diff options
author | Aineopintojen-harjoitustyo-Algoritmit-j <github-hy-tiralabra@v.hix.fi> | 2024-01-17 10:51:08 +0200 |
---|---|---|
committer | Aineopintojen-harjoitustyo-Algoritmit-j <github-hy-tiralabra@v.hix.fi> | 2024-01-17 10:51:08 +0200 |
commit | 823877510422f6ce2952de5cc40edd0d62d813e4 (patch) | |
tree | 1e68d682a3f59dea0a87aa83c9bb1c73aeb2badb /bots/bad.py | |
parent | 899d0997a6badae6535e9f69e0f6d70f3a272578 (diff) |
Adding BadBot for hinting.
Diffstat (limited to 'bots/bad.py')
-rw-r--r-- | bots/bad.py | 58 |
1 files changed, 58 insertions, 0 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) |