cell.bend checks
raw source on the hub · import 0x3b876eed3a748ea7fba8a7834d3c610b/cell.bend as Cell
Cell: one square of the board, and the two moves that act on it. ================================================================
A cell carries three facts: whether it hides a mine, how many mines
touch it, and what the player has done to it. near is fixed when
the board is laid out. mine is fixed for the whole game. Only
mark moves, and it moves through a small state machine:
Hidden --flag--> Flagged --flag--> Hidden Hidden --open--> Shown
A flag blocks an open, and a shown cell is final. LAWS.bend states these as claims, and PROOF.bend proves them.
1 import
import Base
Types
type Mark source · line 17 · raw
Data
HiddenMark
FlaggedMark
ShownMark
type Cell source · line 22 · raw
Data
Cell@mine:Bool -> @near:U32 -> @mark:Mark -> Cell
Definitions
def Mark.is_flagged source · line 34 · raw
@k:Mark -> Bool
def Mark.is_shown source · line 43 · raw
@k:Mark -> Bool
def Mark.expose source · line 54 · raw
@k:Mark -> Mark
A flag on a mine stays a flag, so a won board keeps its flags. Anything else on a mine comes up when the game is lost.
def Cell.is_mine source · line 63 · raw
@c:Cell -> Bool
def Cell.near source · line 68 · raw
@c:Cell -> U32
def Cell.mark source · line 73 · raw
@c:Cell -> Mark
def Cell.is_shown source · line 83 · raw
@c:Cell -> Bool
def Cell.is_flagged source · line 88 · raw
@c:Cell -> Bool
def Cell.flag source · line 94 · raw
@c:Cell -> Cell
Right-click. It turns a flag on or off and leaves a shown cell alone.
def Cell.open source · line 106 · raw
@c:Cell -> Cell
Left-click. A flagged cell does not open; a shown cell does not change.
def Cell.expose source · line 118 · raw
@c:Cell -> Cell
The end of a lost game: every mine that is not flagged comes up.
def Cell.is_open_blank source · line 128 · raw
@c:Cell -> Bool
A shown cell with no mine next to it. The flood spreads out of these.
def Cell.one_shown source · line 134 · raw
@c:Cell -> U32
Counters. Grid.sum adds these up over the whole board in parallel.
def Cell.one_flag source · line 137 · raw
@c:Cell -> U32
def Cell.one_mine source · line 140 · raw
@c:Cell -> U32
def Cell.one_boom source · line 144 · raw
@c:Cell -> U32
A shown mine. One of these means the game is lost.