From f08fadad2ad6a0a388782b096e49e96283dc9301 Mon Sep 17 00:00:00 2001 From: changhongyan <745030092@qq.com> Date: Wed, 6 Feb 2019 19:13:21 +0800 Subject: [PATCH] update the limit version --- README.md | 12 ++++++------ pypokerengine/engine/action_checker.py | 14 +++++++------- pypokerengine/engine/dealer.py | 4 ++-- pypokerengine/engine/round_manager.py | 21 ++++++++++++++++----- raise_player.py | 8 ++++---- randomplayer.py | 4 ++-- 6 files changed, 37 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 2951623..df775ae 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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"} ] ``` diff --git a/pypokerengine/engine/action_checker.py b/pypokerengine/engine/action_checker.py index 526951b..230c074 100644 --- a/pypokerengine/engine/action_checker.py +++ b/pypokerengine/engine/action_checker.py @@ -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 @@ -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: diff --git a/pypokerengine/engine/dealer.py b/pypokerengine/engine/dealer.py index 12845bc..7783f38 100644 --- a/pypokerengine/engine/dealer.py +++ b/pypokerengine/engine/dealer.py @@ -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 diff --git a/pypokerengine/engine/round_manager.py b/pypokerengine/engine/round_manager.py index 5c2cdf3..b84fe5b 100644 --- a/pypokerengine/engine/round_manager.py +++ b/pypokerengine/engine/round_manager.py @@ -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] @@ -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 @@ -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): diff --git a/raise_player.py b/raise_player.py index f233172..441432f 100644 --- a/raise_player.py +++ b/raise_player.py @@ -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 diff --git a/randomplayer.py b/randomplayer.py index b6afa1f..3066960 100644 --- a/randomplayer.py +++ b/randomplayer.py @@ -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