From 823877510422f6ce2952de5cc40edd0d62d813e4 Mon Sep 17 00:00:00 2001 From: Aineopintojen-harjoitustyo-Algoritmit-j Date: Wed, 17 Jan 2024 10:51:08 +0200 Subject: Adding BadBot for hinting. --- bots/bot.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'bots/bot.py') 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 -- cgit v1.2.3