summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--__main__.py14
-rw-r--r--app.py18
-rw-r--r--board/board.py42
-rw-r--r--board/static.py4
-rw-r--r--bots/bot.py18
-rw-r--r--bots/dssp.py10
-rw-r--r--bots/simple.py6
-rw-r--r--game/game.py2
-rw-r--r--tests/test_board.py6
-rw-r--r--tui/kbd.py2
-rw-r--r--tui/static.py8
-rw-r--r--tui/tui.py2
12 files changed, 66 insertions, 66 deletions
diff --git a/__main__.py b/__main__.py
index a738449..902d92b 100644
--- a/__main__.py
+++ b/__main__.py
@@ -41,30 +41,34 @@ parser.add_argument(
'-c',
metavar='COUNT',
type=int,
+ dest='count',
help='Suorittaa ohelmaa COUNT kertaa ja tulostaa voitto-osuuden.',
)
parser.add_argument(
'-w',
metavar='WIDTH',
type=int,
+ dest='width',
help='Mukautaa pelilaudan leveydelle WIDTH. (resetoi vaikeustason)',
)
parser.add_argument(
'-H',
metavar='HEIGHT',
type=int,
+ dest='height',
help='Mukautaa pelilaudan korkeudelle HEIGTH. (resetoi vaikeustason)',
)
parser.add_argument(
- '-b',
- metavar='BOMBS',
+ '-m',
+ metavar='MINES',
type=int,
- help='Säätää pelilaulla olevien pommien määrän BOMBS:ksi. (resetoi vaikeustason)',
+ dest='mines',
+ help='Säätää pelilaulla olevien pommien määrän MINES:ksi. (resetoi vaikeustason)',
)
args = parser.parse_args()
-if args.c is None:
+if args.count is None:
app = App(args)
is_win = app.run()
del app
@@ -72,7 +76,7 @@ if args.c is None:
win_count = 0
-run_count = args.c
+run_count = args.count
args.uncertain=True
for i in range(run_count):
print(end=f" \rSuoritus {i+1:>6}/{run_count} ")
diff --git a/app.py b/app.py
index 8394f68..0dfef0a 100644
--- a/app.py
+++ b/app.py
@@ -11,18 +11,14 @@ class App:
board_opts = {'level': Level.BEGINNER}
tui_opts = {'bot': DSSPBot}
if args:
- if args.intermediate:
- board_opts['level'] = Level.INTERMEDIATE
- if args.expert:
- board_opts['level'] = Level.EXPERT
- if args.w:
- board_opts['width'] = args.w
- if args.H:
- board_opts['height'] = args.H
- if args.b:
- board_opts['bombs'] = args.b
+ # pylint: disable = multiple-statements
+ if args.intermediate: board_opts['level'] = Level.INTERMEDIATE
+ if args.expert: board_opts['level'] = Level.EXPERT
+ if args.width: board_opts['width'] = args.width
+ if args.height: board_opts['height'] = args.height
+ if args.mines: board_opts['mines'] = args.mines
- tui_opts['bot'] = SimpleBot if args.simple else DSSPBot
+ if args.simple: tui_opts['bot'] = SimpleBot
tui_opts['autoplay'] = args.auto
tui_opts['interactive'] = not args.uncertain
tui_opts['suppress'] = args.quiet
diff --git a/board/board.py b/board/board.py
index 8fc1f3a..1d31d13 100644
--- a/board/board.py
+++ b/board/board.py
@@ -14,34 +14,34 @@ class Board():
level = Level.BEGINNER,
width = None,
height = None,
- bombs = None):
+ mines = None):
self.__level = level
- self.__width, self.__height, self.__bombs =LevelSpecs[self.__level][:3]
+ self.__width, self.__height, self.__mines =LevelSpecs[self.__level][:3]
if width and width in range(2,51):
self.__width = width
if height and height in range(2,51):
self.__height = width
- if bombs:
- self.__bombs = bombs
+ if mines:
+ self.__mines = mines
- if self.__bombs not in range(1,self.__width*self.__height):
- self.__bombs = self.__width
+ if self.__mines not in range(1,self.__width*self.__height):
+ self.__mines = self.__width
- if ( (self.__width, self.__height, self.__bombs)
+ if ( (self.__width, self.__height, self.__mines)
== LevelSpecs[self.__level][:3] ):
self.__level_name = LevelSpecs[self.__level][3]
else:
self.__level_name = "Mukautettu"
self.__level_name += ( f" ({self.__width}x{self.__height}"
- f", {self.__bombs} miinaa)" )
+ f", {self.__mines} miinaa)" )
self.__tiles = None
self.__masked = None
self.__initialize_tiles()
- self.__randomize_bombs()
+ self.__randomize_mines()
self.__calculate_neighbours()
@@ -52,14 +52,14 @@ class Board():
self.__masked = [[Tile.UNOPENED for _ in range(h)] for _ in range(w)]
- def __randomize_bombs(self):
+ def __randomize_mines(self):
""" arpoo pelilaudalle pommit """
- for _ in range(self.__bombs):
+ for _ in range(self.__mines):
while True:
x, y = randrange(0,self.__width), randrange(0,self.__height)
if self.__tiles[x][y] != Tile.BLANK:
continue
- self.__tiles[x][y] = Tile.BOMB
+ self.__tiles[x][y] = Tile.MINE
break
@@ -67,13 +67,13 @@ class Board():
""" laskee naapurissa olevien pommien määrät valmiiksi laudalle """
for y in range(self.__height):
for x in range(self.__width):
- if self.__tiles[x][y] == Tile.BOMB:
+ if self.__tiles[x][y] == Tile.MINE:
continue
- neighbouring_bombs = 0
+ neighbouring_mines = 0
for nx, ny in self.get_neighbours_coords(x,y):
- if self.__tiles[nx][ny] == Tile.BOMB:
- neighbouring_bombs += 1
- self.__tiles[x][y] = neighbouring_bombs
+ if self.__tiles[nx][ny] == Tile.MINE:
+ neighbouring_mines += 1
+ self.__tiles[x][y] = neighbouring_mines
def invalid_coordinates(self, x, y):
@@ -113,7 +113,7 @@ class Board():
""" tarkistaa onko peli voitettu """
for y in range(self.__height):
for x in range(self.__width):
- if self.__tiles[x][y] == Tile.BOMB:
+ if self.__tiles[x][y] == Tile.MINE:
if not self.__masked[x][y]:
return False
else:
@@ -175,7 +175,7 @@ class Board():
self.__masked[x][y] = 0
- if self.__tiles[x][y] == Tile.BOMB:
+ if self.__tiles[x][y] == Tile.MINE:
return False
if self.__tiles[x][y] == Tile.BLANK:
@@ -198,9 +198,9 @@ class Board():
""" palauttaa laudan korkeuden """
return self.__height
- def get_bombs(self):
+ def get_mines(self):
""" palauttaa pommien määrän """
- return self.__bombs
+ return self.__mines
def get_level_name(self):
""" palauttaa vaikesutason nimen"""
diff --git a/board/static.py b/board/static.py
index 5d4b4ba..4804ded 100644
--- a/board/static.py
+++ b/board/static.py
@@ -20,8 +20,8 @@ class Tile(IntEnum):
SIX = 6
SEVEN = 7
EIGHT = 8
- BOMB = 9
- FLAG_BOMB = 10
+ MINE = 9
+ FLAG_MINE = 10
FLAG_FREE = 11
UNOPENED = 12
FLAG_UNKNOWN = 13
diff --git a/bots/bot.py b/bots/bot.py
index f32b466..cc09936 100644
--- a/bots/bot.py
+++ b/bots/bot.py
@@ -7,7 +7,7 @@ class Bot():
def __init__(self, **opts):
self.uncertain = opts['uncertain'] if 'uncertain' in opts else False
self.safe_tiles = set()
- self.bomb_tiles = set()
+ self.mine_tiles = set()
self.matrix = []
self.w = 0
self.h = 0
@@ -25,14 +25,14 @@ class Bot():
if self.safe_tiles:
x, y = self.safe_tiles.pop()
return Action.SAFE, x, y
- if self.bomb_tiles:
- x, y = self.bomb_tiles.pop()
- return Action.BOMB, x, y
+ if self.mine_tiles:
+ x, y = self.mine_tiles.pop()
+ return Action.MINE, x, y
return Action.NOOP, 0, 0
def saved_hints(self):
""" onko muuveja varastossa """
- return self.safe_tiles or self.bomb_tiles
+ return self.safe_tiles or self.mine_tiles
def hint(self, matrix, cursor_x, cursor_y):
""" antaa vinkin. tässä tapauksessa ei mitään """
@@ -73,14 +73,14 @@ class Bot():
def remove_number_tiles(self, tiles):
""" poistaa vapaat ja vapaaksi merkityt alueet ja numerolaatat """
for tile in list(tiles):
- if self.matrix[tile[0]][tile[1]] < Tile.FLAG_BOMB:
+ if self.matrix[tile[0]][tile[1]] < Tile.FLAG_MINE:
tiles.remove(tile)
- def remove_bomb_tiles(self, tiles):
+ def remove_mine_tiles(self, tiles):
""" poistaa pommit ja pommiksi merkityt """
count=0
for tile in list(tiles):
- if self.matrix[tile[0]][tile[1]] in (Tile.BOMB, Tile.FLAG_BOMB):
+ if self.matrix[tile[0]][tile[1]] in (Tile.MINE, Tile.FLAG_MINE):
tiles.remove(tile)
count+=1
return count
@@ -91,7 +91,7 @@ class Bot():
def number_tile(self, tile):
""" tutkii onko numerolaatta """
- return 0 < self.matrix[tile[0]][tile[1]] < Tile.BOMB
+ return 0 < self.matrix[tile[0]][tile[1]] < Tile.MINE
def count_unknowns(self, tiles):
""" laskee tunnistamattomat laatat """
diff --git a/bots/dssp.py b/bots/dssp.py
index 78dec8e..1e559a2 100644
--- a/bots/dssp.py
+++ b/bots/dssp.py
@@ -25,8 +25,8 @@ class DSSPBot(SimpleBot):
n2 = self.get_neighbours(tile2)
self.remove_number_tiles(n1)
self.remove_number_tiles(n2)
- c1 -= self.remove_bomb_tiles(n1)
- c2 -= self.remove_bomb_tiles(n2)
+ c1 -= self.remove_mine_tiles(n1)
+ c2 -= self.remove_mine_tiles(n2)
# otetaan vain alue1:n laatat pois vähennetään se pommeista
# näin tiedetään montako pommia on jäätävä yhteiselle alueelle
@@ -48,8 +48,8 @@ class DSSPBot(SimpleBot):
for safe in n2:
self.safe_tiles.add(safe)
if cc == len(nc) and c2 == len(n2):
- for bomb in n2:
- self.bomb_tiles.add(bomb)
+ for mine in n2:
+ self.mine_tiles.add(mine)
return self.saved_hints()
@@ -58,7 +58,7 @@ class DSSPBot(SimpleBot):
tiles = self.get_border_tiles()
for tile in tiles:
n = self.get_neighbours(tile)
- c = self.get_value(tile) - self.remove_bomb_tiles(n)
+ c = self.get_value(tile) - self.remove_mine_tiles(n)
self.remove_number_tiles(n)
for ntile in n:
heatmap[ntile] += c/len(n)
diff --git a/bots/simple.py b/bots/simple.py
index cb3d25c..54e2d05 100644
--- a/bots/simple.py
+++ b/bots/simple.py
@@ -12,13 +12,13 @@ class SimpleBot(Bot):
c = self.get_value(tile)
n = self.get_neighbours(tile)
self.remove_number_tiles(n)
- c -= self.remove_bomb_tiles(n)
+ c -= self.remove_mine_tiles(n)
if c == 0:
for safe in n:
self.safe_tiles.add(safe)
if c == len(n):
- for bomb in n:
- self.bomb_tiles.add(bomb)
+ for mine in n:
+ self.mine_tiles.add(mine)
return self.saved_hints()
def lucky_guess(self):
diff --git a/game/game.py b/game/game.py
index 2a4efad..fefcf8f 100644
--- a/game/game.py
+++ b/game/game.py
@@ -34,7 +34,7 @@ class Game:
return False
case Action.FLAG:
self.board.flag(self.x, self.y)
- case Action.BOMB:
+ case Action.MINE:
self.board.flag(self.x, self.y, 10)
case Action.SAFE:
self.board.flag(self.x, self.y, 11)
diff --git a/tests/test_board.py b/tests/test_board.py
index 7b0d1fd..750e75f 100644
--- a/tests/test_board.py
+++ b/tests/test_board.py
@@ -16,14 +16,14 @@ class TestBoardClass(unittest.TestCase):
b = Board(level=Level.EXPERT)
self.assertEqual(b.get_width(), LevelSpecs[Level.EXPERT][0])
self.assertEqual(b.get_height(), LevelSpecs[Level.EXPERT][1])
- self.assertEqual(b.get_bombs(), LevelSpecs[Level.EXPERT][2])
+ self.assertEqual(b.get_mines(), LevelSpecs[Level.EXPERT][2])
def test_init_with_incorect_dimensions(self):
""" luominen ei saa onnitua mahdottomilla mitoilla """
b = Board(width=1, height=999)
self.assertEqual(b.get_width(), LevelSpecs[Level.BEGINNER][0])
self.assertEqual(b.get_height(), LevelSpecs[Level.BEGINNER][1])
- self.assertEqual(b.get_bombs(), LevelSpecs[Level.BEGINNER][2])
+ self.assertEqual(b.get_mines(), LevelSpecs[Level.BEGINNER][2])
def test_get_view_and_guess(self):
""" laudan näkymä on oikein senkin jälkeen kun on arvattu"""
@@ -109,5 +109,5 @@ class TestBoardClass(unittest.TestCase):
""" Testataan että nykyinen vaikeustaso palautuu oikein """
b = Board(level=Level.INTERMEDIATE)
self.assertIn(LevelSpecs[Level.INTERMEDIATE][3], b.get_level_name())
- b = Board(level=Level.INTERMEDIATE, width=25, bombs=2)
+ b = Board(level=Level.INTERMEDIATE, width=25, mines=2)
self.assertIn("Mukautettu", b.get_level_name())
diff --git a/tui/kbd.py b/tui/kbd.py
index b6d2363..81840ae 100644
--- a/tui/kbd.py
+++ b/tui/kbd.py
@@ -57,7 +57,7 @@ class Kbd():
match action:
case Action.QUIT | Action.HINT:
return (action, x, y)
- case Action.OPEN | Action.FLAG | Action.BOMB | Action.SAFE:
+ case Action.OPEN | Action.FLAG | Action.MINE | Action.SAFE:
return (action, x, y)
case Action.UP:
y = y-1 if y > 0 else 0
diff --git a/tui/static.py b/tui/static.py
index 2b3693a..fba5525 100644
--- a/tui/static.py
+++ b/tui/static.py
@@ -19,7 +19,7 @@ class Action(Enum):
BEGIN = 11
END = 12
NOOP = 13 # ei mitään - tarvitaan, ettei mätsää ansikoodeja esciin
- BOMB = 14 # merkkaa pommi
+ MINE = 14 # merkkaa pommi
SAFE = 15 # merkkaa turvallinen
# ActionKeys - Ohjelma vertaa syötteen alkua näihin ja palauttaa ekan
@@ -31,7 +31,7 @@ ActionKeys = {
"w": Action.UP, "a": Action.LEFT, "s": Action.DOWN,
"d": Action.RIGHT, " ": Action.OPEN, "\n": Action.OPEN,
"f": Action.FLAG, "m": Action.FLAG, "q": Action.QUIT,
- "p": Action.BOMB, "x": Action.BOMB, "o": Action.SAFE,
+ "p": Action.MINE, "x": Action.MINE, "o": Action.SAFE,
"l": Action.QUIT, "?": Action.HINT, "b": Action.HINT
}
@@ -67,8 +67,8 @@ TileTypes = {
Tile.SIX: TileType( "[6]", [(0x9,0), (0x9,0), (0x9,0)] ),
Tile.SEVEN: TileType( "[7]", [(0x9,0), (0x9,0), (0x9,0)] ),
Tile.EIGHT: TileType( "[8]", [(0x9,0), (0x9,0), (0x9,0)] ),
- Tile.BOMB: TileType( "[@]", [(0xF,1), (0xF,1), (0xF,1)] ),
- Tile.FLAG_BOMB: TileType( "[×]", [(0x8,7), (0x1,7), (0x8,7)] ),
+ Tile.MINE: TileType( "[@]", [(0xF,1), (0xF,1), (0xF,1)] ),
+ Tile.FLAG_MINE: TileType( "[×]", [(0x8,7), (0x1,7), (0x8,7)] ),
Tile.FLAG_FREE: TileType( "[•]", [(0x8,7), (0x2,7), (0x8,7)] ),
Tile.UNOPENED: TileType( "[#]", [(0x8,7), (0x8,7), (0x8,7)] ),
Tile.FLAG_UNKNOWN: TileType( "[?]", [(0x8,7), (0x0,7), (0x8,7)] )
diff --git a/tui/tui.py b/tui/tui.py
index 4409134..d32af71 100644
--- a/tui/tui.py
+++ b/tui/tui.py
@@ -66,7 +66,7 @@ class Tui():
match action:
case Action.QUIT:
return (action, x, y)
- case Action.OPEN | Action.FLAG | Action.BOMB | Action.SAFE:
+ case Action.OPEN | Action.FLAG | Action.MINE | Action.SAFE:
if matrix[x][y] >= 10:
return (action, x, y)
case Action.HINT: