ishikota / PyPokerEngine

Poker engine for poker AI development in Python
https://ishikota.github.io/PyPokerEngine/
MIT License
608 stars 184 forks source link

'restore_game_state' raise Exception when ante is ON #52

Closed ishikota closed 7 years ago

ishikota commented 7 years ago

error_log

  File "/home/ec2-user/pokeraienv/local/lib/python2.7/site-packages/pypokerengine/api/game.py", line 14, in start_poker
    result_message = dealer.start_game(config.max_round)
  File "/home/ec2-user/pokeraienv/local/lib/python2.7/site-packages/pypokerengine/engine/dealer.py", line 39, in start_game
    table = self.play_round(round_count, sb_amount, ante, table)
  File "/home/ec2-user/pokeraienv/local/lib/python2.7/site-packages/pypokerengine/engine/dealer.py", line 48, in play_round
    action, bet_amount = self.__publish_messages(msgs)
  File "/home/ec2-user/pokeraienv/local/lib/python2.7/site-packages/pypokerengine/engine/dealer.py", line 103, in __publish_messages
    return self.message_handler.process_message(*msgs[-1])
  File "/home/ec2-user/pokeraienv/local/lib/python2.7/site-packages/pypokerengine/engine/dealer.py", line 191, in process_message
    return receiver.respond_to_ask(msg["message"])
  File "/home/ec2-user/pokeraienv/local/lib/python2.7/site-packages/pypokerengine/players.py", line 48, in respond_to_ask
    return self.declare_action(valid_actions, hole_card, round_state)
  File "../../../../../pypokerai/player.py", line 16, in declare_action
    game_state = restore_state(hole_card, round_state)
  File "../../../../../pypokerai/player.py", line 49, in restore_state
    game_state = restore_game_state(round_state)
  File "/home/ec2-user/pokeraienv/local/lib/python2.7/site-packages/pypokerengine/utils/game_state_utils.py", line 16, in restore_game_state
    "table": _restore_table(round_state)
  File "/home/ec2-user/pokeraienv/local/lib/python2.7/site-packages/pypokerengine/utils/game_state_utils.py", line 74, in _restore_table
    table.seats = _restore_seats(round_state["seats"], round_state["action_histories"])
  File "/home/ec2-user/pokeraienv/local/lib/python2.7/site-packages/pypokerengine/utils/game_state_utils.py", line 92, in _restore_seats
    _restore_pay_info_on_players(players, players_state, action_histories)
  File "/home/ec2-user/pokeraienv/local/lib/python2.7/site-packages/pypokerengine/utils/game_state_utils.py", line 118, in _restore_pay_info_on_players
    _restore_pay_info_amount_on_players(players, round_action_histories)
  File "/home/ec2-user/pokeraienv/local/lib/python2.7/site-packages/pypokerengine/utils/game_state_utils.py", line 125, in _restore_pay_info_amount_on_players
    player.pay_info.amount += _fetch_pay_amount(action_history)
  File "/home/ec2-user/pokeraienv/local/lib/python2.7/site-packages/pypokerengine/utils/game_state_utils.py", line 137, in _fetch_pay_amount
    raise Exception("Unexpected type of action_history is passed => %s" % action_history)
Exception: Unexpected type of action_history is passed => {'action': 'ANTE', 'amount': 25, 'uuid': 'suormojqznrqohrgkyiiqc'}

Fix Here by handling ANTE type action_history

#game_state_utils.py
130 def _fetch_pay_amount(action_history):$
131     action = action_history["action"]$
132     if action == Player.ACTION_FOLD_STR: return 0$
133     if action == Player.ACTION_CALL_STR: return action_history["paid"]$
134     if action == Player.ACTION_RAISE_STR: return action_history["paid"]$
135     if action == Player.ACTION_SMALL_BLIND: return action_history["amount"]$
136     if action == Player.ACTION_BIG_BLIND: return action_history["amount"]$
137     raise Exception("Unexpected type of action_history is passed => %s" % action_history)