-
Notifications
You must be signed in to change notification settings - Fork 4
/
monte_carlo_player.py
41 lines (30 loc) · 1.22 KB
/
monte_carlo_player.py
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
from pypokerengine.players import BasePokerPlayer
from pypokerengine.utils.card_utils import estimate_hole_card_win_rate, gen_cards
NB_SIMULATION = 1000
class MonteCarloPlayer(BasePokerPlayer):
def declare_action(self, valid_actions, hole_card, round_state):
# valid_actions format => [raise_action_pp = pprint.PrettyPrinter(indent=2)
community_card = round_state['community_card']
win_rate = estimate_hole_card_win_rate(
nb_simulation=NB_SIMULATION,
nb_player=self.num_players,
hole_card=gen_cards(hole_card),
community_card=gen_cards(community_card)
)
if win_rate >= 1.0 / self.num_players:
action = valid_actions[1] # fetch CALL action info
else:
action = valid_actions[0] # fetch FOLD action info
return action["action"]
def receive_game_start_message(self, game_info):
self.num_players = game_info['player_num']
def receive_round_start_message(self, round_count, hole_card, seats):
pass
def receive_street_start_message(self, street, round_state):
pass
def receive_game_update_message(self, action, round_state):
pass
def receive_round_result_message(self, winners, hand_info, round_state):
pass
def setup_ai():
return MonteCarloPlayer()