1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
hands = Import["e:\\U盘\\p054_poker.txt", "Table"];
type[cards_] :=
Module[{},
values = FromDigits /@ ((StringTake[#, 1] & /@ cards) /. {"A" ->"14", "K" -> "13", "Q" -> "12", "J" -> "11", "T" -> "10"}) //Sort // Reverse;
suites = StringTake[#, -1] & /@ cards;
valuepat = Tally[values][[;; , 2]] // Sort // Reverse;
FirstComVal = First@Commonest@values;
Which[
Length@Union@suites == 1 &&Differences@values == {-1, -1, -1, -1}, {9, values}, (*Royal/Straight Flush*)
valuepat == {4, 1}, {8, Commonest[values, 2]},
valuepat == {3, 2}, {7, Commonest[values, 2]},
Length@Union@suites == 1, {6, values},
Differences@values == {-1, -1, -1, -1}, {5, values},
valuepat == {3, 1, 1}, {4, Prepend[DeleteCases[values, FirstComVal], FirstComVal]},
valuepat == {2, 2, 1}, {3, Append[Commonest[values, 2] // Sort // Reverse, First@Complement[values, Commonest[values, 2]]]},
valuepat == {2, 1, 1, 1}, {2, Prepend[DeleteCases[values, FirstComVal], FirstComVal]},
True, {1, values}
]
]
GetWinner[hand_] := Module[{}, Player1 = type[hand[[;; 5]]]; Player2 = type[hand[[6 ;;]]];
If[Player1[[1]] > Player2[[1]], Return[1],
If[Player1[[1]] < Player2[[1]], Return[2],
For[i = 1, i <= Length@Player1[[2]], i++,
If[Player1[[2, i]] > Player2[[2, i]], Return[1],
If[Player1[[2, i]] < Player2[[2, i]], Return[2]]
]
]
]
]
];
Count[GetWinner /@ hands, 1]
376
|