def init_game(self): ''' Initialilze the game of Mahjong This version supports two-player Mahjong Returns: (tuple): Tuple containing: (dict): The first state of the game (int): Current player's id ''' # Initialize a dealer that can deal cards self.dealer = Dealer() # Initialize four players to play the game self.players = [Player(i) for i in range(self.num_players)] self.judger = Judger() self.round = Round(self.judger, self.dealer, self.num_players) # Deal 13 cards to each player to prepare for the game for player in self.players: self.dealer.deal_cards(player, 13) # Save the hisory for stepping back to the last state. self.history = [] self.dealer.deal_cards(self.players[self.round.current_player], 1) state = self.get_state(self.round.current_player) self.cur_state = state return state, self.round.current_player
] else: test_case = [ values[index - 1], values[index], values[index + 1] ] if self.check_consecutive(test_case): set_count += 1 for each in test_case: values.pop(values.index(each)) c = _type + "-" + str(each) sets.append(c) if c in tmp_cards: tmp_cards.pop(tmp_cards.index(c)) return set_count, sets if __name__ == "__main__": judger = MahjongJudger() player = Player(0) card_info = Card.info #print(card_info) player.pile.append([Card(card_info['type'][0], card_info['trait'][0])] * 3) #player.hand.extend([Card(card_info['type'][0], card_info['trait'][0])]*2) player.hand.extend([Card(card_info['type'][1], card_info['trait'][1])] * 4) player.hand.extend([Card(card_info['type'][2], card_info['trait'][1])] * 3) player.hand.extend([Card(card_info['type'][0], card_info['trait'][2])] * 3) player.hand.extend([Card(card_info['type'][3], card_info['trait'][9])] * 2) #player.hand.extend([Card(card_info['type'][2], card_info['trait'][4])]*1) print([card.get_str() for card in player.hand]) print(judger.judge_hu(player))
def test_player_get_player_id(self): player = Player(0, np.random.RandomState()) self.assertEqual(0, player.get_player_id())
def test_player_get_player_id(self): player = Player(0) self.assertEqual(0, player.get_player_id())