unison/sheepshead.u

46 lines
887 B
Plaintext
Raw Normal View History

2019-05-24 16:20:59 +03:00
type Suit = ♣ | ♠ | ♥ | ♦
type Card = Card Rank Suit
type Rank = A | K | Q | J | 10_ | 9_ | 8_ | 7_
type NonEmpty a = NonEmpty a [a]
use Rank A K Q J 10_ 9_ 8_ 7_
use Suit Club Spade Heart Diamond
use NonEmpty NonEmpty
use UInt64 (==)
namespace Suit where
club = ♣
spade = ♠
heart = ♥
diamond = ♦
all = [♣, ♠, ♥, ♦]
namespace Rank where
all = [A, 10_, K, Q, J, 9_, 8_, 7_]
points r = case r of
A -> 11
10_ -> 10
K -> 4
Q -> 3
J -> 2
_ -> 0
toText r = case r of
A -> "A"
K -> "K"
Q -> "Q"
J -> "J"
10_ -> "10"
9_ -> "9"
8_ -> "8"
7_ -> "7"
namespace NonEmpty where
toList n = case n of
NonEmpty h t -> Sequence.cons h t
fromList : [a] -> Optional (NonEmpty a)
fromList l =
if Sequence.size l == 0 then None
else Some (NonEmpty (Sequence.at 0 l) (Sequence.drop 1 l))
()