summaryrefslogtreecommitdiff
path: root/bots/bad.py
diff options
context:
space:
mode:
authorAineopintojen-harjoitustyo-Algoritmit-j <github-hy-tiralabra@v.hix.fi>2024-01-27 12:36:02 +0200
committerAineopintojen-harjoitustyo-Algoritmit-j <github-hy-tiralabra@v.hix.fi>2024-01-27 12:36:02 +0200
commitd68d1a33f52ad9ddeb97c6e45f1e66cdf27c67f5 (patch)
tree5ed95a7e5b9a427fc4c4791e21a92fb88fbf7ce7 /bots/bad.py
parentc0a0bb30e03be9c47b99d5da848e29a747e9af66 (diff)
Implementing uncertain moves as bot option.
Diffstat (limited to 'bots/bad.py')
-rw-r--r--bots/bad.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/bots/bad.py b/bots/bad.py
index fb853f1..5197dc9 100644
--- a/bots/bad.py
+++ b/bots/bad.py
@@ -1,4 +1,5 @@
""" bots/bad.py - botti joka ehkä osaa merkata jonkun asian """
+from random import sample
from tui import Action
from .bot import Bot
@@ -37,6 +38,16 @@ class BadBot(Bot):
tiles.append( (x,y) )
return tiles
+ def get_unopened_tiles(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:
+ tiles.append( (x,y) )
+ return tiles
def hint(self, matrix, cursor_x, cursor_y):
""" merkitsee jonkin ruudun """
@@ -56,4 +67,7 @@ class BadBot(Bot):
if matrix[x][y]-bombs==unopened:
bomb = ncoords[ntiles.index(12)]
return(Action.BOMB, bomb[0], bomb[1])
+ if self.uncertain:
+ x, y = sample(self.get_unopened_tiles(matrix),1)[0]
+ return (Action.OPEN, x, y)
return (Action.NOOP, cursor_x, cursor_y)