-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.php
164 lines (128 loc) · 3.92 KB
/
player.php
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
class Player {
const VERSION = "Default PHP folding player 17:33";
const RAINMAN_URL = 'http://rainman.leanpoker.org/rank';
public function betRequest($game_state) {
return 0;
if ($game_state["dealer"] == $game_state["in_action"]) { // devill blöff :)
$smallBlind = $game_state['small_blind'];
$bigBlind = $smallBlind * 2;
$current_buy_in = $game_state['current_buy_in'];
$moneyNeedsToCall = $current_buy_in - $game_state["players"][$game_state["in_action"]]['bet'];
if ($current_buy_in == $bigBlind) {
return $moneyNeedsToCall + 4 * $bigBlind;
}
}
if (count($game_state["community_cards"]) < 3) {
return $this->preFlop($game_state);
} else {
return $this->postFlop($game_state);
}
}
public function betRequest2($game_state) {
if (count($game_state["community_cards"]) < 3) {
return $this->preFlop($game_state);
} else {
return $this->postFlop($game_state);
}
}
public function preFlop($game_state) {
$myCards = $this->myCards($game_state);
$smallBlind = $game_state['small_blind'];
$bigBlind = $smallBlind * 2;
$playersCount = $this->countActivePlayers($game_state);
$moneyNeedsToCall = $game_state['current_buy_in'] - $game_state["players"][$game_state["in_action"]]['bet'];
if ($this->getHandClass($myCards) >= 3 && $playersCount <= 3) {
return 10000000;
}
$isClassTwo = ($this->getHandClass($myCards) === 2);
if ($isClassTwo && $this->getPotOdds($game_state, $moneyNeedsToCall) < (1 / 3)) {
return $moneyNeedsToCall;
}
return 0;
}
public function postFlop($game_state) {
$rank = $this->getRainmanRank($game_state);
if ($rank >= 3) {
return 10000000;
}
$moneyNeedsToCall = $game_state['current_buy_in'] - $game_state["players"][$game_state["in_action"]]['bet'];
if ($rank < 1) {
return 0;
}
return $moneyNeedsToCall + max($game_state["minimum_raise"], $rank * 200);
}
public function showdown($game_state) {
}
public function myCards($gameState) {
return $gameState["players"][$gameState["in_action"]]["hole_cards"];
}
public function countActivePlayers($game_state) {
return count(array_filter($game_state['players'], function($item) {
return $item['status'] === 'active';
}));
}
public function getHandClass($cards) {
$cCards = array_map(function($card){
return $this->convertCard($card['rank']);
}, $cards);
if ($cCards[0] == $cCards[1]) { // magas párok
if ($cCards[0] >= 10)
return 5;
}
if ($cCards[0] >= 10 && $cCards[1] >= 10) { // magas lapok
return 4;
}
if ($cCards[0] == $cCards[1]) { // alacsony párok
if ($cCards[0] < 10)
return 3;
}
$isSuited = $cards[0]['suit'] == $cards[1]['suit'];
$gap = abs($cCards[0] - $cCards[1]);
$isConnected = $gap == 1;
$hasOneGap = $gap == 2;
if ($isConnected || ($isSuited && $hasOneGap)) { // sorhoz
return 2;
}
return 1;
}
public function convertCard($rank) {
switch ($rank) {
case "A":
return 14;
case "K":
return 13;
case "Q":
return 12;
case "J":
return 11;
default:
return (int) $rank;
}
}
public function getRainmanRank($gameState) {
$myCards = $this->myCards($gameState);
$communityCards = $gameState['community_cards'];
$cards = json_encode(array_merge($myCards, $communityCards));
$urlCards = urlencode($cards);
$rankJson = file_get_contents(self::RAINMAN_URL . "?cards=" . $urlCards);
$rank = json_decode($rankJson, true);
if (!in_array($myCards[0], $rank["cards_used"]) and
!in_array($myCards[1], $rank["cards_used"]))
{
return 0;
}
if (1 == $rank['rank']) { // pair
$highest = max(array_map(function($card){
return $this->convertCard($card['rank']);
}, $communityCards));
if ($this->convertCard($rank["value"]) != $highest) { // we are not having the
return 0;
}
}
return $rank['rank'];
}
public function getPotOdds($game_state, $neededToCall) {
return $neededToCall / $game_state['pot'];
}
}