@@ 10,12 10,14 @@ import numpy as np
"""Represents game state at any point in time.
Note that this does not track flags, as they have no impact on the gameplay
logic and should be handled by the UI exclusively.
size: size of the square board
near[x, y]: how many bombs are near `(x, y)`
bomb[x, y]: 1 if `(x, y)` is a bomb
revealed[x, y]: 1 if `(x, y)` has been revealed
flagged[x, y]: 1 if `(x, y)` has been flagged
won: `True` if user has won, `None` if the game has not finished
clicks: tracks the number of total clicks done by the user
@@ 38,7 40,6 @@ class State:
self.size = size
self.bomb = np.zeros((self.size, self.size), dtype=int)
self.revealed = np.copy(self.bomb)
self.flagged = np.copy(self.bomb)
self.near = np.copy(self.bomb)
self.won: Optional[bool] = None
self.clicks = 0
@@ 143,7 144,3 @@ class State:
if not (new_x == x and new_y == y):
def flag(self, x: int, y: int):
"""Mark `(x, y)` as flagged."""
self.flagged[x, y] = 1