module Logic.GameState;
open import Stdlib.Prelude;
open import Logic.Extra;
open import Logic.Board;
type Error :=
| --- no error occurred
noError : Error
| --- a non-fatal error occurred
continue : String → Error
| --- a fatal occurred
terminate : String → Error;
type GameState :=
| state : Board → Symbol → Error → GameState;
--- Textual representation of a ;GameState;
showGameState : GameState → String;
showGameState (state b _ _) := showBoard b;
--- Projects the player
player : GameState → Symbol;
player (state _ p _) := p;
--- initial ;GameState;
beginState : GameState;
beginState :=
state
(board
(map
(map empty)
((1 :: 2 :: 3 :: nil)
:: (4 :: 5 :: 6 :: nil)
:: (7 :: 8 :: 9 :: nil)
:: nil)))
X
noError;
--- ;true; if some player has won the game
won : GameState → Bool;
won (state (board squares) _ _) :=
any full (diagonals squares ++ rows squares ++ columns squares);
--- ;true; if there is a draw
draw : GameState → Bool;
draw (state (board squares) _ _) := null (possibleMoves (flatten squares));
Last modified on 2023-05-08 11:40 UTC