-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathplayer.py
More file actions
76 lines (61 loc) · 1.87 KB
/
player.py
File metadata and controls
76 lines (61 loc) · 1.87 KB
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
'''
Created on Jan 26, 2017
@author: tommi
'''
from enum import Enum
from handeval import pcg_brand
class Action(Enum):
CHECKFOLD = 1
CHECKCALL = 2
BETRAISE = 3
class Street(Enum):
PREFLOP = 0
FLOP = 3
TURN = 4
RIVER = 5
SHOWDOWN = 6
class PlayerState:
STACK_SIZE = 10000
MONEY_BEHIND = 990000
def __init__(self):
self.stack = self.STACK_SIZE
self.moneyLeft = self.MONEY_BEHIND
self.reset()
def bet(self, amount):
diff = amount - self.betSize
if diff >= self.stack:
self.betSize += self.stack
self.stack = 0
self.isAllIn = True
else:
self.betSize += diff
self.stack -= diff
def add_money(self, amount):
if amount > 0:
self.stack += amount
def reset(self):
self.betSize = 0
self.isAllIn = False
self.hasActed = False
self.hasFolded = False
self.cards = []
self.boardCards = []
return self.reload_stack()
def reload_stack(self):
if self.stack == 0:
if self.moneyLeft <= 0:
return False
else:
self.stack += min(self.STACK_SIZE, self.moneyLeft)
self.moneyLeft -= self.stack
return True
return True
class Agent: # Base class for all AI and human players. Plays random moves. Agent never modifies PlayerStates.
def __init__(self):
self.state = PlayerState()
def set_enemy_state(self, state):
self.enemyState = state
def get_action(self): # AI implementation
return Action(pcg_brand(3) + 1), pcg_brand(10000)
def update(self, street, pot):
pass