Skip to content

Commit

Permalink
update the limit version
Browse files Browse the repository at this point in the history
  • Loading branch information
changhongyan123 committed Feb 6, 2019
1 parent 0abeee0 commit f08fada
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 26 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class RaisedPlayer(BasePokerPlayer):
def declare_action(self, valid_actions, hole_card, round_state):
#Implement your stragy code
return action, amount #Note: modify the action and amount is not allowed here.
return action
def receive_game_start_message(self, game_info):
pass
Expand All @@ -64,14 +64,14 @@ class RaisedPlayer(BasePokerPlayer):

```
[
{ "action" : "fold" , "amount" : int },
{ "action" : "call" , "amount" : int },
{ "action" : "raise", "amount" : int }
{ "action" : "fold" },
{ "action" : "call" },
{ "action" : "raise" }
]
OR
[
{"action": "fold", "amount": int},
{"action": "call", "amount": int}
{"action": "fold"},
{"action": "call"}
]
```

Expand Down
14 changes: 7 additions & 7 deletions pypokerengine/engine/action_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ def agree_amount(self, players):

@classmethod
def legal_actions(self, players, player_pos, sb_amount,street):
raise_amount,raise_limit = self.__round_raise_amount(sb_amount,street)
raise_amount,raise_limit = self.round_raise_amount(sb_amount,street)
current_amount = self.agree_amount(players)
player_raised_number = self.__player_raise_number(players,player_pos,street)
if current_amount < raise_limit and player_raised_number < 4:
return [
{ "action" : "fold" , "amount" : 0 },
{ "action" : "call" , "amount" : current_amount },
{ "action" : "raise", "amount" : raise_amount+current_amount }
{ "action" : "fold" },
{ "action" : "call" },
{ "action" : "raise"}
]
else:
return [
{"action": "fold", "amount": 0},
{"action": "call", "amount": current_amount}
{"action": "fold"},
{"action": "call"}
]

@classmethod
Expand Down Expand Up @@ -92,7 +92,7 @@ def __fetch_last_raise(self, players):
return max(raise_histories, key=lambda h: h["amount"]) # maxby

@classmethod
def __round_raise_amount(self, sb_amount,street):
def round_raise_amount(self, sb_amount,street):
if street == 0 or street == 1:
return sb_amount * 2, sb_amount * 2 * 4
else:
Expand Down
4 changes: 2 additions & 2 deletions pypokerengine/engine/dealer.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def play_round(self, round_count, blind_amount, ante, table):
#TODO:update the play_round
self.__message_check(msgs, state["street"])
if state["street"] != Const.Street.FINISHED: # continue the round
action, bet_amount = self.__publish_messages(msgs)
state, msgs = RoundManager.apply_action(state, action, bet_amount)
action = self.__publish_messages(msgs)
state, msgs = RoundManager.apply_action(state, action)
else: # finish the round after publish round result
self.__publish_messages(msgs)
break
Expand Down
21 changes: 16 additions & 5 deletions pypokerengine/engine/round_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def start_new_round(self, round_count, small_blind_amount, ante_amount, table):
return state, start_msg + street_msgs

@classmethod
def apply_action(self, original_state, action, bet_amount):
def apply_action(self, original_state, action):
state = self.__deep_copy_state(original_state)
state = self.__update_state_by_action(state, action, bet_amount)
state,bet_amount = self.__update_state_by_action(state, action)
update_msg = self.__update_message(state, action, bet_amount)
if self.__is_everyone_agreed(state):
[player.save_street_action_histories(state["street"]) for player in state["table"].seats.players]
Expand All @@ -41,6 +41,9 @@ def apply_action(self, original_state, action, bet_amount):
ask_message = (next_player.uuid, MessageBuilder.build_ask_message(next_player_pos, state))
return state, [update_msg, ask_message]




@classmethod
def __correct_ante(self, ante_amount, players):
if ante_amount == 0: return
Expand Down Expand Up @@ -144,14 +147,22 @@ def __forward_street(self, state):
return state, street_start_msg + ask_message

@classmethod
def __update_state_by_action(self, state, action, bet_amount):
def __update_state_by_action(self, state, action):
table = state["table"]
current_amount = ActionChecker.agree_amount(state["table"].seats.players)
bet = ActionChecker.round_raise_amount(state["small_blind_amount"],state["street"])
if action == "raise":
amount = current_amount + bet[0]
elif action == "call":
amount = current_amount
elif action == "fold":
amount = 0
action, bet_amount = ActionChecker.correct_action(\
table.seats.players, state["next_player"], state["small_blind_amount"], action, bet_amount)
table.seats.players, state["next_player"], state["small_blind_amount"], action, amount)
next_player = table.seats.players[state["next_player"]]
if ActionChecker.is_allin(next_player, action, bet_amount):
next_player.pay_info.update_to_allin()
return self.__accept_action(state, action, bet_amount)
return self.__accept_action(state, action, bet_amount),amount

@classmethod
def __accept_action(self, state, action, bet_amount):
Expand Down
8 changes: 4 additions & 4 deletions raise_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ class RaisedPlayer(BasePokerPlayer):
def declare_action(self, valid_actions, hole_card, round_state):
for i in valid_actions:
if i["action"] == "raise":
action, amount = i["action"], i["amount"]
return action, amount # action returned here is sent to the poker engine
action, amount = valid_actions[1]["action"], valid_actions[1]["amount"]
return action, amount # action returned here is sent to the poker engine
action = i["action"]
return action # action returned here is sent to the poker engine
action = valid_actions[1]["action"]
return action # action returned here is sent to the poker engine

def receive_game_start_message(self, game_info):
pass
Expand Down
4 changes: 2 additions & 2 deletions randomplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def declare_action(self, valid_actions, hole_card, round_state):
call_action_info = valid_actions[2]
else:
call_action_info = valid_actions[0]
action, amount = call_action_info["action"], call_action_info["amount"]
return action, amount # action returned here is sent to the poker engine
action = call_action_info["action"]
return action # action returned here is sent to the poker engine

def receive_game_start_message(self, game_info):
pass
Expand Down

0 comments on commit f08fada

Please sign in to comment.