summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAineopintojen-harjoitustyo-Algoritmit-j <github-hy-tiralabra@v.hix.fi>2024-02-18 17:24:14 +0200
committerAineopintojen-harjoitustyo-Algoritmit-j <github-hy-tiralabra@v.hix.fi>2024-02-18 17:24:14 +0200
commitf8452c313ca78e5f04714331c4a222e8aed53805 (patch)
tree2bd492d332e5867b6875d560ce97072a27e3523f
parent5e69623d022ecd747e20ca29e891d221c9ccbbab (diff)
Bot doesn't need to know cursor coordinates.
-rw-r--r--pyproject.toml2
-rw-r--r--src/miinaharava/bots/bot.py4
-rw-r--r--src/miinaharava/tests/test_bot.py2
-rw-r--r--src/miinaharava/tui/tui.py11
4 files changed, 11 insertions, 8 deletions
diff --git a/pyproject.toml b/pyproject.toml
index ca26e7d..8cfad68 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
[tool.poetry]
name = "miinaharava"
-version = "0.1"
+version = "0.2-alpha"
description = "Miinaharava ratkaisijalla"
authors = ["Aineopintojen-harjoitustyo-Algoritmit-j <github-hy-tiralabra@v.hix.fi>"]
readme = "README.md"
diff --git a/src/miinaharava/bots/bot.py b/src/miinaharava/bots/bot.py
index b00f9a6..15dbb8e 100644
--- a/src/miinaharava/bots/bot.py
+++ b/src/miinaharava/bots/bot.py
@@ -40,7 +40,7 @@ class Bot():
tiles.remove(tile)
return self.safe_tiles or self.mine_tiles
- def hint(self, matrix, cursor_x, cursor_y):
+ def hint(self, matrix):
""" Kysyy tekoälyltä vihjettä. Joko palauttaa vihjeen, arvauksen tai
vain nykyisen paikan ilman toimintoa. """
self.matrix = matrix
@@ -50,7 +50,7 @@ class Bot():
for step in (self.saved_hints, self.search, ok_to_guess ):
if step():
return self.get_hint_from_list()
- return Action.NOOP, cursor_x, cursor_y
+ return Action.NOOP, 0, 0
def get_dimensions(self):
""" Apufunktio joka palauttaa pelilaudan mitat. """
diff --git a/src/miinaharava/tests/test_bot.py b/src/miinaharava/tests/test_bot.py
index 4dab148..435151f 100644
--- a/src/miinaharava/tests/test_bot.py
+++ b/src/miinaharava/tests/test_bot.py
@@ -26,7 +26,7 @@ class TestBotClass(unittest.TestCase):
tested = set()
while True:
- action, x, y = bot.hint(brd.get_view(), 0, 0)
+ action, x, y = bot.hint(brd.get_view())
if (x,y) in tested:
break
tested.add((x,y))
diff --git a/src/miinaharava/tui/tui.py b/src/miinaharava/tui/tui.py
index d7f7fb3..378b222 100644
--- a/src/miinaharava/tui/tui.py
+++ b/src/miinaharava/tui/tui.py
@@ -55,12 +55,12 @@ class Tui():
# automaattipeli avaa botin vinkit heti
if self.autoplay:
- action, x, y = self.bot.hint(matrix, x, y)
+ action, bx, by = self.bot.hint(matrix)
if action != Action.NOOP:
if self.delay:
- self.draw.matrix(matrix, x, y)
+ self.draw.matrix(matrix, bx, by)
time.sleep(self.delay/100)
- return Action.OPEN if action==Action.SAFE else action, x, y
+ return Action.OPEN if action==Action.SAFE else action, bx, by
# ilman näppiskäsittelijää voidaan lopettaa
@@ -79,7 +79,10 @@ class Tui():
return (action, x, y)
case Action.HINT:
if self.bot is not None:
- return self.bot.hint(matrix, x, y)
+ action, bx, by = self.bot.hint(matrix)
+ if action != Action.NOOP:
+ return (action, bx, by)
+ return (Action.NOOP, x, y)
def game_over(self, matrix, x, y):
""" tehtävät kun kuolee """