Skip to content

Instantly share code, notes, and snippets.

@rickythefox
Forked from forki/gist:1151080
Created September 13, 2017 10:57
Show Gist options
  • Save rickythefox/53a1358812b330f75b79b82f55bb200f to your computer and use it in GitHub Desktop.
Save rickythefox/53a1358812b330f75b79b82f55bb200f to your computer and use it in GitHub Desktop.
A basic model for Poker in F#
type Rank = int
type Suit = | Spades | Hearts | Diamonds | Clubs
type Card = Rank * Suit
let value = fst
let suit = snd
let A,K,Q,J,T = 14,13,12,11,10
let allRanksInSuit suit = [2..A] |> List.map (fun rank -> rank,suit)
let completeDeck =
[Spades; Hearts ; Diamonds; Clubs]
|> List.map allRanksInSuit
|> List.concat
let isPair c1 c2 = value c1 = value c2
let isSuited c1 c2 = suit c1 = suit c2
let isConnected c1 c2 =
let v1,v2 = value c1,value c2
(v1 - v2 |> abs |> (=) 1) ||
(v1 = A && v2 = 2) ||
(v1 = 2 && v2 = A)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment