unison/unison-src/tests/tictactoe0.u
2020-09-27 20:39:26 -04:00

34 lines
593 B
Plaintext

-- board piece
type P = X | O | E
type Board = Board P P P P P P P P P
use Board Board
use P O X E
use Optional Some None
orElse a b =
match a with
None -> b
a -> a
b = (Board X O X
O X X
O E X)
isWin board =
same : P -> P -> P -> Optional P
same a b c = if (a == b) && (a == c) && not (a == E)
then Some a
else None
match board with
-- vertical top/center/bottom
-- horizontal left/center/right
-- diagonal rising/falling
Board a b c
d e f
g h i -> (same a b c)
> isWin b
-- Some 3