From 899d0997a6badae6535e9f69e0f6d70f3a272578 Mon Sep 17 00:00:00 2001 From: Aineopintojen-harjoitustyo-Algoritmit-j Date: Sun, 14 Jan 2024 16:02:12 +0200 Subject: Adding the idiot bot for giving idiot hints. --- app.py | 4 +++- bots/bot.py | 14 ++++++++++++++ bots/idiot.py | 17 +++++++++++++++++ tui/tui.py | 2 +- 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 bots/bot.py create mode 100644 bots/idiot.py diff --git a/app.py b/app.py index 977e6c3..d8ca622 100644 --- a/app.py +++ b/app.py @@ -2,13 +2,15 @@ from board.board import Board from tui.tui import Tui from game.game import Game +from bots.idiot import IdiotBot # pylint: disable = too-few-public-methods class App: """ App - Luokka pääohjelmalle""" def __init__(self): self.board = Board() - self.ui = Tui("just testing bot here") + self.bot = IdiotBot() + self.ui = Tui(self.bot) self.game = Game(self.board,self.ui) def run(self): diff --git a/bots/bot.py b/bots/bot.py new file mode 100644 index 0000000..1b7fedd --- /dev/null +++ b/bots/bot.py @@ -0,0 +1,14 @@ +""" bots/bot.py - bottien kantaisä """ +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): + """ antaa vinkin. tässä tapauksessa ei mitään """ + # pylint: disable = unused-argument + self.hints += 1 + return Action.NOOP, x, y diff --git a/bots/idiot.py b/bots/idiot.py new file mode 100644 index 0000000..4f1f9f4 --- /dev/null +++ b/bots/idiot.py @@ -0,0 +1,17 @@ +""" bots/idiot.py - se ensimmäinen botti joka tekee kaiken väärin """ +from bots.bot import Bot +from tui.static import Action +class IdiotBot(Bot): + """ IdiotBot - merkistsee kaikki turvallisiksi avata """ + # pylint: disable = too-few-public-methods + + def hint(self, matrix, x, y): + """ merkitsee jonkin ruudun """ + super().hint(matrix, x, y) + # pylint: disable = consider-using-enumerate + for ty in range(len(matrix[0])): + for tx in range(len(matrix)): + if matrix[tx][ty]==10: + return(Action.SAFE, tx, ty) + return (Action.NOOP, x, y) + \ No newline at end of file diff --git a/tui/tui.py b/tui/tui.py index d884766..8521227 100644 --- a/tui/tui.py +++ b/tui/tui.py @@ -98,7 +98,7 @@ class Tui(): x = len(matrix)-1 case Action.HINT: if self.bot is not None: - return (Action.BOMB, 0, 0) + return self.bot.hint(matrix, x, y) self.draw_matrix(matrix, x, y) -- cgit v1.2.3