Last active
August 21, 2016 22:00
-
-
Save atoko/8c76a8c8af899e740d1811dd6f2c940f to your computer and use it in GitHub Desktop.
This file contains 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
#indent "off" | |
type Suit = | |
|Oro |Basto |Copa |Espada | |
type Face = | |
|I |II |III |IV |V |VI |VII |X |XI |XII | |
type Card = Suit * Face | |
type BriscaCard = {card:Card; isLife:bool;} | |
let BriscaValue (c : BriscaCard) = | |
match c.card with | |
| (_, I) -> 11 | |
| (_, III) -> 10 | |
| (_, X) -> 1 | |
| (_, XI) -> 2 | |
| (_, XII) -> 3 | |
| (_, _) -> 0 | |
let WinPriority (c : BriscaCard) = | |
match c.card with | |
| (_, I) -> 8 | |
| (_, II) -> 0 | |
| (_, III) -> 9 | |
| (_, IV) -> 1 | |
| (_, V) -> 2 | |
| (_, VI) -> 3 | |
| (_, VII) -> 4 | |
| (_, X) -> 5 | |
| (_, XI) -> 6 | |
| (_, XII) -> 7 | |
let SuitsMatch (a, b) = ((not a.isLife) && b.isLife) || (fst a.card = fst b.card) | |
let PointWinner (a, b) = | |
match BriscaValue b = BriscaValue a with | |
| true -> (match WinPriority b > WinPriority a with | |
| true -> b | |
| false -> a) | |
| false -> (match BriscaValue b > BriscaValue a with | |
| true -> b | |
| false -> a) | |
let BriscaWinner a b = | |
if SuitsMatch (a, b) then | |
if (a.isLife) && not b.isLife then | |
a | |
else | |
match b.isLife with | |
| true -> b | |
| false -> PointWinner (a, b) | |
else | |
a | |
//Example usage | |
//let oro2 = { | |
// card = (Oro, III); | |
// isLife = true | |
//} | |
//let espada5 = { | |
// card = (Espada, XII); | |
// isLife = false | |
//} | |
// | |
//let cardA = espada5 | |
//let cardB = oro2 | |
//let result = BriscaWinner cardA cardB | |
//let points = BriscaValue cardA + BriscaValue cardB |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment