def flood

minebender-game@1.0.0.0 · game.bend:239

import minebender-game@1.0.0.0/game.bend as Game
import Base
import minebender-game@1.0.0.0/types.bend as T
import minebender-game@1.0.0.0/board.bend as B

239# Reveal the cells of `work`, and the neighbours of every zero revealed. n is
240# how many cells are not revealed yet: each reveal uses one up.
241def flood(+n: Nat, work: List<&2, Work>, hd: Bool, +w: Nat, +h: Nat,
242  +layout: T.Grid(Bool), +shown: T.Grid(Bool)) -> T.Grid(Bool):
243  match n:
244    case 0n:
245      shown
246    case 1n+m:
247      match work:
248        case Nil{}:
249          shown
250        case Work{+c, +back} <> +rest:
251          match hd:
252            case False{}:
253              flood(n, rest, head_hidden(w, h, shown, rest), w, h, layout, shown)
254            case True{}:
255              +sh = B.set_at(Bool, shown, c, True{})
256              +wk = push(B.zero(w, h, layout, c), B.neighbours(w, h, c), back, rest)
257              flood(m, wk, head_hidden(w, h, sh, wk), w, h, layout, sh)

Uses (10)

Used by (22)