Skip to content

Commit

Permalink
Merge pull request wenkesj#3 from kiwi-chang/una/rule
Browse files Browse the repository at this point in the history
fix env.
  • Loading branch information
KiwiChang authored and GitHub Enterprise committed Jul 19, 2018
2 parents 1c90d08 + 4d1d881 commit 839ede6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
2 changes: 1 addition & 1 deletion holdem/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ def _get_current_state(self):
int(player.playing_hand),
int(player.handrank),
int(player.playedthisround),
int(player.betting),
int(player.currentbet),
int(player.isallin),
int(player.lastsidepot),
0,
Expand Down
44 changes: 27 additions & 17 deletions holdem/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def __init__(self, player_id, stack=1000, emptyplayer=False, playername="", relo

# flags for table management
self.emptyplayer = emptyplayer
self.betting = 0
self.isallin = False
self.playing_hand = False
self.playedthisround = False
Expand All @@ -69,27 +68,29 @@ def set_seat(self, value):
def reset_hand(self):
self.hand = []
self.playedthisround = False
self.betting = 0
self.isallin = False
self.currentbet = 0
self.lastsidepot = 0
self.playing_hand = (self.stack != 0)

def bet(self, bet_size):
# not for bigblind, smallblind
# bet_size = min(player.stack, player_bet) + player.currentbet
self.playedthisround = True
if not bet_size:
if not bet_size: # for check
return
self.stack -= (bet_size - self.currentbet)
self.betting += (bet_size - self.currentbet)
self.currentbet = bet_size
if self.stack == 0:
actualbet = bet_size - self.currentbet
if self.stack <= actualbet:
actualbet = self.stack
self.isallin = True
self.stack -= actualbet
self.currentbet += actualbet

def refund(self, ammount):
self.stack += ammount

def player_state(self):
return (self.get_seat(), self.stack, self.playing_hand, self.betting, self.player_id)
return (self.get_seat(), self.stack, self.playing_hand, self.currentbet, self.player_id)

def reset_stack(self):
self.stack = self._init_stack
Expand All @@ -113,30 +114,39 @@ def player_move(self, table_state, action):
assert action_idx in [Player.CHECK, Player.RAISE]
if action_idx == Player.RAISE:
if self._roundRaiseCount > self._roundRaiseLimit:
raise error.Error('raise times ({}) in this round had exceed limitation ({})'.format(self._roundRaiseCount, self._roundRaiseLimit))
# raise error.Error('raise times ({}) in this round had exceed limitation ({})'.format(self._roundRaiseCount, self._roundRaiseLimit))
return ('check', 0)
if raise_amount < minraise:
raise error.Error('raise must be greater than minraise {}'.format(minraise))
# raise error.Error('raise must be greater than minraise {}'.format(minraise))
return ('check', 0)
if raise_amount > self.stack:
raise error.Error('raise must be less than maxraise {}'.format(self.stack))
# raise error.Error('raise must be less than maxraise {}'.format(self.stack))
return ('raise', self.stack)
move_tuple = ('raise', raise_amount)
self._roundRaiseCount += 1
elif action_idx == Player.CHECK:
move_tuple = ('check', 0)
else:
raise error.Error('invalid action ({}) must be check (0) or raise (2)'.format(action_idx))
# raise error.Error('invalid action ({}) must be check (0) or raise (2)'.format(action_idx))
move_tuple = ('check', 0)
else:
if action_idx not in [Player.RAISE, Player.CALL, Player.FOLD]:
raise error.Error('invalid action ({}) must be raise (2), call (1), or fold (3)'.format(action_idx))
if action_idx == Player.RAISE:
if self._roundRaiseCount > self._roundRaiseLimit:
# raise error.Error('raise times ({}) in this round had exceed limitation ({})'.format(self._roundRaiseCount, self._roundRaiseLimit))
return ('call', tocall)
if raise_amount < minraise:
raise error.Error('raise must be greater than minraise {} but {}'.format(minraise, raise_amount))
# raise error.Error('raise must be greater than minraise {} but {}'.format(minraise, raise_amount))
return ('call', tocall)
if raise_amount > self.stack:
raise error.Error('raise must be less than maxraise {}'.format(self.stack))
# raise error.Error('raise must be less than maxraise {}'.format(self.stack))
return ('raise', tocall)
move_tuple = ('raise', raise_amount)
self._roundRaiseCount += 1
elif action_idx == Player.CALL:
move_tuple = ('call', tocall)
elif action_idx == Player.FOLD:
move_tuple = ('fold', -1)
else:
raise error.Error('invalid action ({}) must be raise (2), call (1), or fold (3)'.format(action_idx))
# raise error.Error('invalid action ({}) must be raise (2), call (1), or fold (3)'.format(action_idx))
return ('call', tocall)
return move_tuple

0 comments on commit 839ede6

Please sign in to comment.