Skip to content

Commit

Permalink
Merge branch 'alpha' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
edwinans committed May 11, 2024
2 parents bbae25a + 2e55370 commit ae22410
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,19 @@ let rec calculate_expansion ({grid; state; size; _} as model) (i, j) =
grid.(i).(j) <- Empty nb_camels
end

let check_win {grid; state; camels; flagged_camels; generated; _} =
match generated && camels = flagged_camels with
| false -> false
| true ->
Array.mapi (fun i ->
Array.mapi (fun j -> function
| Camel -> state.(i).(j) = Flagged
| Empty _ -> state.(i).(j) <> Flagged
)
)
grid
|> Array.for_all (Array.for_all Fun.id)

let update ({camels; size; grid; state; generated; _} as model) = function
| Click (i, j) ->
Utils.log_cell "click" (i, j);
Expand Down Expand Up @@ -151,7 +164,7 @@ let update ({camels; size; grid; state; generated; _} as model) = function
Vdom.return {model with state}
| Check_win ->
let c =
match model.camels = model.flagged_camels with
match check_win model with
| true -> Some [Vdom.Cmd.echo Won]
| false -> None
in
Expand Down

0 comments on commit ae22410

Please sign in to comment.