~piotr-machura/sweep-ai

6c4d8943ea1445fa80274a071dbd01c820ea92ec — Piotr Machura 10 months ago b2cf2b6
Remove flags from core game logic
1 files changed, 3 insertions(+), 6 deletions(-)

M sweep_ai/logic.py
M sweep_ai/logic.py => sweep_ai/logic.py +3 -6
@@ 10,12 10,14 @@ import numpy as np
class State:
    """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.

    Properties:
        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):
                        neighbors.append((new_x, new_y))
        return neighbors

    def flag(self, x: int, y: int):
        """Mark `(x, y)` as flagged."""
        self.flagged[x, y] = 1