-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot_player.py
97 lines (78 loc) · 3.38 KB
/
bot_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
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
import random
import cards
from abstract_player import AbstractPlayer
class BotPlayer(AbstractPlayer):
def __init__(self, name):
AbstractPlayer.__init__(self, name)
# ===========================================================================
# #UPDATE:
# ===========================================================================
def update(self, gamestate):
# =======================================================================
# #GAMESTATE ANALYSIS
# =======================================================================
# IDENTIFY STAGE OF THE GAME
stage = gamestate.get_stage()
# IDENTIFY BLINDS:
blinds = gamestate.getRoundBlinds()
# IDENTIFY TOCALL:
tocall = gamestate.get_player_bet_difference(self)
print '%s :' % (self.getName())
folded = False
# fold in case you don't have enough money
if tocall > self.getMoney():
self.fold(gamestate)
folded = True
# =======================================================================
# #POSSIBLE GAMESTAGES:
# =======================================================================
if not folded:
# preflop:
if stage == 'preflop':
if tocall != 0:
self.call(gamestate)
# flop
elif stage == 'flop':
if tocall == 0:
self.bet(gamestate, 2 * blinds)
else:
self.call(gamestate)
# turn
elif stage == 'turn':
if random.random() > 0.6:
if tocall == 0:
if gamestate.get_player_bets(self) == 0:
self.bet(gamestate, 2 * blinds)
else:
self.call(gamestate)
else:
sumofknowncards = cards.listUnion(self.getHand(), gamestate.get_cards_on_table())
if len(cards.find_final_hands(sumofknowncards)) > len(sumofknowncards):
if gamestate.get_player_bets(self) == 0:
self.bet(gamestate, blinds + tocall)
else:
if random.random() < 0.2:
if tocall != 0:
self.fold(gamestate)
else:
self.call(gamestate)
# river
elif stage == 'river':
if random.random() > 0.6:
if tocall == 0:
if gamestate.get_player_bets(self) == 0:
self.bet(gamestate, 2 * blinds)
else:
self.call(gamestate)
else:
sumofknowncards = cards.listUnion(self.getHand(), gamestate.get_cards_on_table())
if len(cards.find_final_hands(sumofknowncards)) > len(sumofknowncards):
if gamestate.get_player_bets(self) == 0:
self.bet(gamestate, 2 * blinds + tocall)
else:
if random.random() < 0.2:
if tocall != 0:
self.fold(gamestate)
else:
self.call(gamestate)
print