/roomai/games/texasholdem/TexasHoldemStatePublic.py

https://github.com/roomai/RoomAI
Python | 177 lines | 119 code | 43 blank | 15 comment | 34 complexity | 444fe3fa2d8bd38d779361eb9abe4118 MD5 | raw file
  1. #!/bin/python
  2. #coding:utf-8
  3. import roomai.games.common
  4. class TexasHoldemStatePublic(roomai.games.common.AbstractStatePublic):
  5. '''
  6. The public state of TexasHoldem
  7. '''
  8. def __init__(self):
  9. super(TexasHoldemStatePublic, self).__init__()
  10. self.__stage__ = None
  11. self.__public_cards__ = None
  12. #state of players
  13. self.__is_fold__ = None
  14. self.__num_fold__ = None
  15. self.__is_allin__ = None
  16. self.__num_allin__ = None
  17. self.__is_needed_to_action__ = None
  18. self.__num_needed_to_action__ = None
  19. self.__param_dealer_id__ = -1
  20. self.__param_big_blind_bet__ = -1
  21. self.__param_init_chips__ = None
  22. #chips is array which contains the chips of all players
  23. self.__chips__ = None
  24. #bets is array which contains the bets from all players
  25. self.__bets__ = None
  26. #max_bet = max(self.bets)
  27. self.__max_bet_sofar__ = None
  28. #the raise acount
  29. self.__raise_account__ = None
  30. def __get_max_bet_sofar__(self): return self.__max_bet_sofar__
  31. max_bet_sofar = property(__get_max_bet_sofar__, doc="The max bet used by one player so far")
  32. def __get_raise_account__(self): return self.__raise_account__
  33. raise_account = property(__get_raise_account__, doc="The raise account. If a player want to raise, the price must be max_bet_sofar + raise_account * N. The raise account will increases as the game goes forward")
  34. def __get_chips__(self):
  35. if self.__chips__ is None:
  36. return None
  37. else:
  38. return tuple(self.__chips__)
  39. chips = property(__get_chips__, doc = "chips is an array of the chips of all players. For example, chips=[50,50,50]")
  40. def __get_bets__(self):
  41. if self.__bets__ is None:
  42. return None
  43. else:
  44. return tuple(self.__bets__)
  45. bets = property(__get_bets__, doc = "bets is an array which contains the bets from all players. For example, bets=[50,25,25]")
  46. def __get_is_fold__(self):
  47. if self.__is_fold__ is None: return None
  48. else: return tuple(self.__is_fold__)
  49. is_fold = property(__get_is_fold__, doc="is_fold is an array of which player has take the fold action. For example, is_fold = [true,true,false] denotes the player0 and player1 have taken the fold action")
  50. def __get_num_fold__(self):
  51. return self.__num_fold__
  52. num_fold = property(__get_num_fold__, doc = "The number of players who has taken the fold action")
  53. def __get_is_allin__(self):
  54. if self.__is_allin__ is None: return None
  55. else: return tuple(self.__is_allin__)
  56. is_allin = property(__get_is_allin__, doc="is_allin is an array of which player has take the allin action. For example, is_allin = [true,true,false] denotes the player0 and player1 have taken the allin action")
  57. def __get_num_allin__(self):
  58. return self.__num_allin__
  59. num_allin = property(__get_num_allin__, doc = "The number of players who has taken the allin action")
  60. def __get_is_needed_to_action__(self):
  61. if self.__is_needed_to_action__ is None: return None
  62. else: return tuple(self.__is_needed_to_action__)
  63. is_needed_to_action = property(__get_is_needed_to_action__, doc="is_needed_to_action is an array of which player has take the needed_to_action action. For example, is_needed_to_action = [true,true,false] denotes the player0 and player1 are need to take action")
  64. def __get_num_needed_to_action__(self):
  65. return self.__num_needed_to_action__
  66. num_needed_to_action = property(__get_num_needed_to_action__, doc = "The number of players who has taken the needed_to_action action")
  67. def __get_public_cards__(self):
  68. if self.__public_cards__ is None:
  69. return None
  70. else:
  71. return tuple(self.__public_cards__)
  72. public_cards = property(__get_public_cards__, doc="The public cards of this game. For example, public_cards = [roomai.common.PokerCards.lookup(\"A_Spade\"), roomai.common.PokerCards.lookup(\"A_Heart\")]")
  73. def __get_stage__(self):
  74. return self.__stage__
  75. stage = property(__get_stage__, doc="The stage of the TexasHoldem game. The stage must be one of 1,2,3 or 4.")
  76. ######################### initialization param ##################
  77. __param_dealer_id__ = 0
  78. def __get_param_dealer_id__(self): return self.__param_dealer_id__
  79. param_dealer_id = property(__get_param_dealer_id__, doc="The player id of the dealer. The next player after the dealer is the small blind. The next player after the small blind is the big blind.For example, param_dealer_id = 2")
  80. __param_init_chips__ = None
  81. def __get_param_init_chips__(self): return self.__param_init_chips__
  82. param_init_chips = property(__get_param_init_chips__, doc="The initialization chips of this game. For example, param_initialization_chips = [10,5,6]")
  83. __param_big_blind_bet__ = 10
  84. def __get_param_big_blind_bet__(self): return self.__param_big_blind_bet__
  85. param_big_blind_bet = property(__get_param_big_blind_bet__, doc="The big blind bet")
  86. def __deepcopy__(self, memodict={}, newinstance = None):
  87. if newinstance is None:
  88. newinstance = TexasHoldemStatePublic()
  89. newinstance = super(TexasHoldemStatePublic, self).__deepcopy__(newinstance=newinstance)
  90. newinstance.__param_dealer_id__ = self.param_dealer_id
  91. newinstance.__param_big_blind_bet__ = self.param_big_blind_bet
  92. newinstance.__param_init_chips__ = self.__param_init_chips__
  93. newinstance.__stage__ = self.stage
  94. if self.public_cards is None:
  95. newinstance.__public_cards__ = None
  96. else:
  97. newinstance.__public_cards__ = [self.public_cards[i].__deepcopy__() for i in range(len(self.public_cards))]
  98. ######## quit, allin , needed_to_action
  99. newinstance.__num_fold__ = self.__num_fold__
  100. if self.is_fold is None:
  101. newinstance.__is_fold__ = None
  102. else:
  103. newinstance.__is_fold__ = [self.is_fold[i] for i in range(len(self.is_fold))]
  104. newinstance.__num_allin__ = self.__num_allin__
  105. if self.is_allin is None:
  106. newinstance.__is_allin__ = None
  107. else:
  108. newinstance.__is_allin__ = [self.is_allin[i] for i in range(len(self.is_allin))]
  109. newinstance.__num_needed_to_action__ = self.__num_needed_to_action__
  110. if self.is_needed_to_action is None:
  111. newinstance.__is_needed_to_action__ = None
  112. else:
  113. newinstance.__is_needed_to_action__ = [self.is_needed_to_action[i] for i in
  114. range(len(self.is_needed_to_action))]
  115. # chips is array which contains the chips of all players
  116. if self.chips is None:
  117. newinstance.__chips__ = None
  118. else:
  119. newinstance.__chips__ = [self.chips[i] for i in range(len(self.chips))]
  120. # bets is array which contains the bets from all players
  121. if self.bets is None:
  122. newinstance.__bets__ = None
  123. else:
  124. newinstance.__bets__ = [self.bets[i] for i in range(len(self.bets))]
  125. newinstance.__max_bet_sofar__ = self.max_bet_sofar
  126. newinstance.__raise_account__ = self.raise_account
  127. newinstance.__turn__ = self.turn
  128. ### isterminal, scores
  129. newinstance.__is_terminal__ = self.is_terminal
  130. if self.scores is None:
  131. newinstance.__scores__ = None
  132. else:
  133. newinstance.__scores__ = [self.scores[i] for i in range(len(self.scores))]
  134. return newinstance