diff options
author | Aineopintojen-harjoitustyo-Algoritmit-j <github-hy-tiralabra@v.hix.fi> | 2024-01-27 12:36:02 +0200 |
---|---|---|
committer | Aineopintojen-harjoitustyo-Algoritmit-j <github-hy-tiralabra@v.hix.fi> | 2024-01-27 12:36:02 +0200 |
commit | d68d1a33f52ad9ddeb97c6e45f1e66cdf27c67f5 (patch) | |
tree | 5ed95a7e5b9a427fc4c4791e21a92fb88fbf7ce7 | |
parent | c0a0bb30e03be9c47b99d5da848e29a747e9af66 (diff) |
Implementing uncertain moves as bot option.
-rw-r--r-- | README.md | 7 | ||||
-rw-r--r-- | __main__.py | 3 | ||||
-rw-r--r-- | app.py | 8 | ||||
-rw-r--r-- | bots/bad.py | 14 | ||||
-rw-r--r-- | bots/bot.py | 3 |
5 files changed, 28 insertions, 7 deletions
@@ -7,8 +7,15 @@ Miinaharava ratkaisijalla - [määrittelydokumentti](doc/m%C3%A4%C3%A4rittelydokumentti.pdf) ## Ohjeet: + +### Asenna `git clone https://github.com/Aineopintojen-harjoitustyo-Algoritmit-j/miinaharava` +### Aja `python3 miinaharava` +### Käyttöohjeet `python3 miinaharava -h` + +### Automaattipelin suoritusesimerkki +`python3 miinaharava -i -a -u` diff --git a/__main__.py b/__main__.py index 697ceb4..edf3888 100644 --- a/__main__.py +++ b/__main__.py @@ -32,9 +32,6 @@ parser.add_argument( action='store_true' ) - - - args = parser.parse_args() app = App(args) @@ -8,16 +8,18 @@ from bots import BadBot class App: """ App - Luokka pääohjelmalle""" def __init__(self, args=None): - level=Level.BEGINNER - ui_class=Tui + level = Level.BEGINNER + ui_class = Tui + uncertain = False if args: level = Level.EXPERT if args.expert else level level = Level.INTERMEDIATE if args.intermediate else level level = Level.BEGINNER if args.beginner else level ui_class = AutoTui if args.auto else ui_class + uncertain = args.uncertain self.board = Board(level=level) - self.bot = BadBot() + self.bot = BadBot(uncertain=uncertain) self.ui = ui_class(self.bot) self.game = Game(self.board,self.ui) 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) diff --git a/bots/bot.py b/bots/bot.py index a097a8d..5ad0bd2 100644 --- a/bots/bot.py +++ b/bots/bot.py @@ -3,7 +3,8 @@ from tui import Action class Bot(): """ Bot - perusluokka perittäväksi """ - def __init__(self): + def __init__(self, **opts): + self.uncertain = opts['uncertain'] if 'uncertain' in opts else False self.hints = 0 def neighbours(self,dx,dy,x,y): |