Created
October 8, 2013 19:00
-
-
Save misterspeedy/6889751 to your computer and use it in GitHub Desktop.
DU to represent a rank
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// A card rank. | |
type Rank = | |
| Ace | King | Queen | Jack | Value of int | |
static member FromString s = | |
match s with | |
| "A" -> Ace | "K" -> King | "Q" -> Queen | "J" -> Jack | |
| "10" -> Value(10) | |
| _ when s.Length = 1 && s.[0] >= '2' && s.[0] <= '9' -> Value(int(s.[0]) - int('0')) | |
| _ -> raise (ArgumentException(sprintf "Invalid rank string: %s" s)) | |
/// The value of the rank for comparison purposes. | |
member r. SortValue = | |
match r with | |
| Ace -> 14 // Aces high - low-ace cases are handled elsewhere | |
| King -> 13 | |
| Queen -> 12 | |
| Jack -> 11 | |
| Value v -> v |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment