diff options
author | Aineopintojen-harjoitustyo-Algoritmit-j <github-hy-tiralabra@v.hix.fi> | 2024-01-14 14:13:59 +0200 |
---|---|---|
committer | Aineopintojen-harjoitustyo-Algoritmit-j <github-hy-tiralabra@v.hix.fi> | 2024-01-14 14:13:59 +0200 |
commit | 2b98f7c66facfe71bf91aebc0d8cf3978e88303f (patch) | |
tree | 9f43a2aade7c26f6a541af09fdd058d67382d0ee /board | |
parent | e56c2153add98361ea7909789b195d3a702f85bb (diff) |
Making it possible to flag bombs and safe areas directly.
Diffstat (limited to 'board')
-rw-r--r-- | board/board.py | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/board/board.py b/board/board.py index 04d81d1..0b4c3a2 100644 --- a/board/board.py +++ b/board/board.py @@ -121,25 +121,26 @@ class Board(): return self.masked[x][y] - def flag(self, x, y): + def flag(self, x, y, flag=-1): """ aseta lippu peitetylle ruudulle""" if self.invalid_coordinates(x, y): print("Koordinaatit on pelilaudan ulkopuolella", file=stderr) return False - match self.masked[x][y]: - case 0: - print("Ei voi liputtaa avattua ruutua", file=stderr) - return False - case 10 | 11 | 12: - self.masked[x][y]+=1 - return True - case 13: - self.masked[x][y]=10 - return True - - print("Ruudulla odottamaton lippu", file=stderr) - return False + if self.masked[x][y] not in range(10,14): + print("Ruudulla odottamaton lippu tai se on avattu", file=stderr) + return False + + if flag == -1: + self.masked[x][y] += 1 if self.masked[x][y] < 13 else -3 + return True + + if flag not in range(10,14): + print("Lippua jota asetat ei ole olemassa", file=stderr) + return False + + self.masked[x][y]=flag + return True def guess(self, x, y): |