Card datatypes and views
Use these for defining card-specifc game logic or for displaying specific cards.
A playing card suit type.
Useful for pattern matching behavior of different games that are based on the suit of the card.
A playing card face type.
Like the suit type above, this is useful for matching on different card faces, and does not induce an implicit order.
A playing card type.
Can either hold a card of suit and face, or a blank card.
Face numbers are designated from 1 to 13 for A-K. Games which treat the ace differently can specify their behavior through the game logic.
The blank variant is useful for displaying cards that have not been flipped over, for instance.
aceOfSpades =
Card Spades Ace
blankCard =
Back
new : String -> Basics.Int -> Maybe Card
Construct a new card.
The first argument must be one of "spades", "diamonds", "clubs", or "hearts" (any case) for the card suit.
The second argument must be an integer from 1 to 13 for A-K.
Use Cards.defaultNew if you want a Card
instead of a Maybe Card
.
new "spades" 1 == Just (Card Spades Ace)
new "SPADES" 1 == Just (Card Spades Ace)
new "horses" 1 == Nothing
new "spades" 0 == Nothing
defaultNew : Card -> String -> Basics.Int -> Card
Construct a new card with a default argument.
The first input is the default card to use if construction fails.
The remaining two inputs correspond to the two inputs for Cards.new.
defaultNew Back "spades" 1 == Card Spades Ace
defaultNew Back "SPADES" 1 == Card Spades Ace
defaultNew Back "horses" 1 == Back
defaultNew Back "spades" 0 == Back
viewCard : Card -> ( String, String )
Return the color and unicode string for a Card
.
Use this function to write Html views for cards or decks.
viewCard (defaultNew Back "spades" 1) == ( "black", "🂡" )
viewCard (defaultNew Back "hearts" 7) == ( "red", "🃗" )
defaultFace : Face -> Basics.Int
Default resoltuion of Faces to integers, in A-K order.
defaultFace Ace == 1
defaultFace King == 13