forked from CS3243-AY1819S2-G50/POK-AI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bluff_player.py
51 lines (39 loc) · 1.61 KB
/
bluff_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
42
43
44
45
46
47
48
49
50
51
from pypokerengine.players import BasePokerPlayer
from pypokerengine.utils.card_utils import gen_cards, estimate_hole_card_win_rate
import pprint
NB_SIMULATION = 1000
class BluffPlayer(BasePokerPlayer):
def declare_action(self, valid_actions, hole_card, round_state):
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)
)
can_call = len([item for item in valid_actions if item['action'] == 'call']) > 0
can_raise = len([item for item in valid_actions if item['action'] == 'raise']) > 0
# print("HonestP hole card: "+ str(hole_card))
# print("Winrate: "+ str(win_rate))
if win_rate >= 0.35:
if win_rate > 0.7:
action = valid_actions[2]['action'] if can_raise else valid_actions[1]['action']
else:
action = valid_actions[1]['action']
else:
action = "call"
return action # action returned here is sent to the poker engine
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):
# print("My ID (round result - random) : "+self.uuid)
# pprint.pprint(round_state)
pass
def setup_ai():
return HonestPlayer()