mirror of
https://github.com/unisonweb/unison.git
synced 2024-10-04 13:47:26 +03:00
34 lines
615 B
Plaintext
34 lines
615 B
Plaintext
-- board piece
|
|
structural type P = X | O | E
|
|
|
|
structural 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
|