Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
782 B
4
Indexable
let max_cards cards = 
let order card = match card.v with
| Three -> 9
| Two -> 8
| Ace -> 7
| King -> 6
| Knight -> 5
| Jack -> 4
| Seven -> 3
| Six -> 2
| Five -> 1
| Four -> 0
in
let rec find_max_of c maxC color = match c with
    | Null -> maxC
    | Carta carta when (order carta >= order maxC) && carta.c=color -> find_max_of carta.tl carta color
    | Carta carta when (order carta < order maxC) || carta.c<>color -> find_max_of carta.tl maxC color
    | Carta carta -> find_max_of carta.tl maxC color
in
match cards with
| Null -> None
| Carta carta -> match carta.c with
    | Spade -> find_max_of cards carta.tl carta.c
    | Coppa -> find_max_of cards carta.tl carta.c
    | Bastoni -> find_max_of cards carta.tl carta.c
    | Denari -> find_max_of cards carta.tl carta.c