summaryrefslogtreecommitdiff
path: root/bots
diff options
context:
space:
mode:
Diffstat (limited to 'bots')
-rw-r--r--bots/bad.py58
-rw-r--r--bots/bot.py23
-rw-r--r--bots/idiot.py8
3 files changed, 82 insertions, 7 deletions
diff --git a/bots/bad.py b/bots/bad.py
new file mode 100644
index 0000000..1419fc0
--- /dev/null
+++ b/bots/bad.py
@@ -0,0 +1,58 @@
+""" bots/bad.py - botti joka ehkä osaa merkata jonkun asian """
+from bots.bot import Bot
+from tui.static import Action
+class BadBot(Bot):
+ """ IdiotBot - merkistsee kaikki turvallisiksi avata """
+ # pylint: disable = too-few-public-methods
+ def missing_bombs(self, matrix, x, y):
+ """ test how many boms are not found at the coordinate """
+ dx = len(matrix)
+ dy = len(matrix[0])
+ bcount = 0
+ for nx, ny in self.neighbours(dx, dy, x, y):
+ if matrix[nx][ny] in (9,11):
+ bcount+=1
+ return matrix[x][y]-bcount
+
+ def get_tiles_at_border(self, matrix):
+ """ get interesting tiles on the border of cleared and masked area """
+ tiles = []
+ w = len(matrix)
+ h = len(matrix[0])
+ for y in range(h):
+ for x in range(w):
+ if matrix[x][y] < 12:
+ open_tiles=1
+ masked_tiles=0
+ else:
+ open_tiles=0
+ masked_tiles=1
+ for nx, ny in self.neighbours(w, h, x, y):
+ if matrix[nx][ny] < 12:
+ open_tiles+=1
+ else:
+ masked_tiles+=1
+ if open_tiles and masked_tiles:
+ tiles.append( (x,y) )
+ return tiles
+
+
+ def hint(self, matrix, cursor_x, cursor_y):
+ """ merkitsee jonkin ruudun """
+ super().hint(matrix, cursor_x, cursor_y)
+ w = len(matrix)
+ h = len(matrix[0])
+ # pylint: disable = consider-using-enumerate
+ for x, y in self.get_tiles_at_border(matrix):
+ ncoords=self.neighbours(w,h,x,y)
+ ntiles=self.coordinates_to_tiles(matrix,ncoords)
+ unopened=ntiles.count(12)
+ bombs=ntiles.count(10)
+ if unopened:
+ if matrix[x][y]<9 and matrix[x][y]==bombs:
+ safe = ncoords[ntiles.index(12)]
+ return(Action.SAFE, safe[0], safe[1])
+ if matrix[x][y]-bombs==unopened:
+ bomb = ncoords[ntiles.index(12)]
+ return(Action.BOMB, bomb[0], bomb[1])
+ return (Action.NOOP, cursor_x, cursor_y)
diff --git a/bots/bot.py b/bots/bot.py
index 1b7fedd..8466c51 100644
--- a/bots/bot.py
+++ b/bots/bot.py
@@ -3,12 +3,29 @@ from tui.static import Action
class Bot():
""" Bot - perusluokka perittäväksi """
- # pylint: disable = too-few-public-methods
def __init__(self):
self.hints = 0
- def hint(self, matrix, x, y):
+ def neighbours(self,dx,dy,x,y):
+ """ palauttaa listana viereiset koordinaatit """
+ offsets = (
+ (-1, -1), ( 0, -1), ( 1, -1),
+ (-1, 0), ( 1, 0),
+ (-1, 1), ( 0, 1), ( 1, 1),
+ )
+ coords=[]
+ for ox, oy in offsets:
+ if ox+x in range(dx):
+ if oy+y in range(dy):
+ coords.append((ox+x, oy+y))
+ return coords
+
+ def coordinates_to_tiles(self, matrix, coords):
+ """ lukee koordinaateissa olevien ruutujen arvot listaksi """
+ return [matrix[x][y] for x,y in coords]
+
+ def hint(self, matrix, cursor_x, cursor_y):
""" antaa vinkin. tässä tapauksessa ei mitään """
# pylint: disable = unused-argument
self.hints += 1
- return Action.NOOP, x, y
+ return Action.NOOP, cursor_x, cursor_y
diff --git a/bots/idiot.py b/bots/idiot.py
index 4f1f9f4..200d690 100644
--- a/bots/idiot.py
+++ b/bots/idiot.py
@@ -5,13 +5,13 @@ class IdiotBot(Bot):
""" IdiotBot - merkistsee kaikki turvallisiksi avata """
# pylint: disable = too-few-public-methods
- def hint(self, matrix, x, y):
+ def hint(self, matrix, cursor_x, cursor_y):
""" merkitsee jonkin ruudun """
- super().hint(matrix, x, y)
+ super().hint(matrix, cursor_x, cursor_y)
# pylint: disable = consider-using-enumerate
for ty in range(len(matrix[0])):
for tx in range(len(matrix)):
- if matrix[tx][ty]==10:
+ if matrix[tx][ty]==12:
return(Action.SAFE, tx, ty)
- return (Action.NOOP, x, y)
+ return (Action.NOOP, cursor_x, cursor_y)
\ No newline at end of file