From e785dbd4f726c5716f21071ed25dc35ac87c0c74 Mon Sep 17 00:00:00 2001 From: Aineopintojen-harjoitustyo-Algoritmit-j Date: Sat, 17 Feb 2024 09:41:48 +0200 Subject: Dev tools and directory structure rework. --- src/miinaharava/bots/simple.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/miinaharava/bots/simple.py (limited to 'src/miinaharava/bots/simple.py') diff --git a/src/miinaharava/bots/simple.py b/src/miinaharava/bots/simple.py new file mode 100644 index 0000000..46b9506 --- /dev/null +++ b/src/miinaharava/bots/simple.py @@ -0,0 +1,30 @@ +""" bots/simple.py - yksinkertainen botti joka etsii vain yhdeltä laatalta """ +from random import sample + +from .bot import Bot + +class SimpleBot(Bot): + """ SimpleBot - perustyhmä botti """ + + def search(self): + """ simple_search - jos viereisten avaamattomien määrä tästmää """ + tiles = self.get_interesting_tiles() + for tile in tiles: + c = self.get_value(tile) + n = self.get_neighbours(tile) + self.remove_number_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 mine in n: + self.mine_tiles.add(mine) + return self.saved_hints() + + def lucky_guess(self): + tiles = self.get_unknown_tiles() + if tiles: + self.safe_tiles.add(sample(sorted(tiles),1)[0]) + return True + return False -- cgit v1.2.3