def init(self, params = dict()): ''' Initialize the SevenKing game environment with the initialization params.\n The initialization is a dict with some options\n 1) backward_enable: whether to record all history states. if you need call the backward function, please set it to True. default False\n 2) num_normal_players: how many players are in the game \n An example of the initialization param is {"num_normal_players":2,"backward_enable":True}\n :param params: the initialization params :return: infos, public_state, person_states, private_state ''' if "num_normal_players" in params: self.__params__["num_normal_players"] = params["num_normal_players"] else: self.__params__["num_normal_players"] = 3 if "backward_enable" in params: self.__params__["backward_enable"] = params["backward_enable"] else: self.__params__["backward_enable"] = False self.public_state = SevenKingPublicState() self.private_state = SevenKingPrivateState() self.person_states = [SevenKingPersonState() for i in range(self.__params__["num_normal_players"] + 1)] self.public_state_history = [] self.private_state_history = [] self.person_states_history = [] ## private_state allcards = [c.__deepcopy__() for c in AllSevenKingPokerCards.values()] random.shuffle(allcards) self.private_state.__keep_cards__ = allcards for i in range(self.__params__["num_normal_players"]): tmp = [] for j in range(5): c = self.private_state.__keep_cards__.pop() tmp.append(c) self.person_states[i].__add_cards__(tmp) ## public_state self.public_state.__turn__,_ = self.__choose_player_with_lowest_card__() self.public_state.__is_terminal__ = False self.public_state.__scores__ = [] self.public_state.__license_action__ = SevenKingAction.lookup("") self.public_state.__stage__ = 0 self.public_state.__num_normal_players__ = self.__params__["num_normal_players"] self.public_state.__num_keep_cards__ = len(self.private_state.keep_cards) self.public_state.__num_hand_cards__ = [len(person_state.hand_cards) for person_state in self.person_states] self.public_state.__is_fold__ = [False for i in range(self.public_state.num_normal_players)] self.public_state.__num_fold__ = 0 ## person_state for i in range(self.__params__["num_normal_players"]+1): self.person_states[i].__id__ = i if i == self.public_state.turn: self.person_states[i].__available_actions__ = SevenKingEnv.available_actions(self.public_state, self.person_states[i]) self.__gen_history__() infos = self.__gen_infos__() return infos, self.public_state, self.person_states, self.private_state
def init(self, params=dict()): """ Args: params: Returns: """ if "num_players" in params: self.num_players = params["num_players"] else: self.num_players = 3 if "allcards" in params: allcards = [c.__deepcopy__() for c in params["allcards"]] else: allcards = [ c.__deepcopy__() for c in AllSevenKingPokerCards.values() ] random.shuffle(allcards) if "record_history" in params: self.record_history = params["record_history"] else: self.record_history = False self.public_state = SevenKingPublicState() self.private_state = SevenKingPrivateState() self.person_states = [ SevenKingPersonState() for i in range(self.num_players) ] self.public_state_history = [] self.private_state_history = [] self.person_states_history = [] ## private_state self.private_state._SevenKingPrivateState__keep_cards = allcards for i in range(self.num_players): tmp = [] for j in range(5): c = self.private_state._SevenKingPrivateState__keep_cards.pop() tmp.append(c) self.person_states[i]._SevenKingPersonState__add_cards(tmp) ## public_state self.public_state.turn, _ = self.choose_player_with_lowest_card() self.public_state.is_terminal = False self.public_state.scores = [] self.public_state.previous_id = None self.public_state.previous_action = None self.public_state._SevenKingPublicState__license_action = SevenKingAction.lookup( "") self.public_state._SevenKingPublicState__stage = 0 self.public_state._SevenKingPublicState__num_players = self.num_players self.public_state._SevenKingPublicState__num_keep_cards = len( self.private_state.keep_cards) self.public_state._SevenKingPublicState__num_hand_cards = [ len(person_state.hand_cards) for person_state in self.person_states ] self.public_state._SevenKingPublicState__is_fold = [ False for i in range(self.public_state.num_players) ] self.public_state._SevenKingPublicState__num_fold = 0 ## person_state for i in range(self.num_players): self.person_states[i].id = i if i == self.public_state.turn: self.person_states[ i].available_actions = SevenKingEnv.available_actions( self.public_state, self.person_states[i]) self.__gen_history__() infos = self.__gen_infos__() return infos, self.public_state, self.person_states, self.private_state