def setUp(self): self.player_0 = Player('Kelly', 0) self.player_1 = Player('Leo', 1) self.player_2 = Player('Ball', 2) self.player_3 = Player('Hao', 3) self.players = [ self.player_0, self.player_1, self.player_2, self.player_3 ]
def setUp(self): self.player_1 = Player('player 1', 0) self.player_2 = Player('player 2', 1) self.player_3 = Player('player 3', 2) self.player_4 = Player('player 4', 3) players = [self.player_1, self.player_2, self.player_3, self.player_4] self.kyoku = Kyoku(players)
def setUp(self): self.player_1 = Player('player 1', 0) self.player_2 = Player('player 2', 1) self.player_3 = Player('player 3', 2) self.player_4 = Player('player 4', 3) self.players = [ self.player_1, self.player_2, self.player_3, self.player_4 ] self.tile_stack = Stack() for player in self.players: for i in range(13): player.hand[self.tile_stack.draw().index] += 1
def main(): round = Round() print(round.state) round.players = [ Player('Eric'), Player('Nana'), Player('Sister'), Player('Brother'), ] round.prepare() print(round.dealer) print([f'{x} ' for x in round.players]) print(round.state)
def test_player_wind(self): table = Table() player = table.player self.assertEqual(player.player_wind, EAST) player = Player(table, 0, 1, False) self.assertEqual(player.player_wind, NORTH) player = Player(table, 0, 2, False) self.assertEqual(player.player_wind, WEST) player = Player(table, 0, 3, False) self.assertEqual(player.player_wind, SOUTH)
def test_player_wind(self): table = Table() player = Player(0, 0, table) self.assertEqual(player.player_wind, EAST) player = Player(0, 1, table) self.assertEqual(player.player_wind, NORTH) player = Player(0, 2, table) self.assertEqual(player.player_wind, WEST) player = Player(0, 3, table) self.assertEqual(player.player_wind, SOUTH)
def setUp(self): self.player_1 = Player('player 1', 0) self.player_2 = Player('player 2', 1) self.player_3 = Player('player 3', 2) self.player_4 = Player('player 4', 3) self.players = [ self.player_1, self.player_2, self.player_3, self.player_4 ] self.tile_stack = Stack() self.logger = KyokuLogger() for player in self.players: for i in range(13): player.hand[self.tile_stack.draw().index] += 1 self.turn = Turn(self.players, self.tile_stack, Jihai.TON, self.logger)
def setUp(self): # tenpai: TON and NAN self.player = Player('test', 1) self.player.hand[Tile(Suit.JIHAI.value, Jihai.TON.value).index] += 2 self.player.hand[Tile(Suit.JIHAI.value, Jihai.NAN.value).index] += 2 naki_tile_1 = Tile(Suit.SOUZU.value, 5) naki_tile_1.owner = 0 naki_tile_2 = Tile(Suit.PINZU.value, 5) naki_tile_2.owner = 3 naki_tile_3 = Tile(Suit.MANZU.value, 8) naki_tile_3.owner = 0 naki_tile_4 = Tile(Suit.MANZU.value, 6) naki_tile_4.owner = 0 self.player.kabe.append( Huro(Naki.PON, naki_tile_1, [Tile(Suit.SOUZU.value, 5) for i in range(3)])) self.player.kabe.append( Huro(Naki.PON, naki_tile_2, [Tile(Suit.PINZU.value, 5) for i in range(3)])) self.player.kabe.append( Huro(Naki.CHII, naki_tile_3, [Tile(Suit.MANZU.value, i) for i in range(7, 10)])) self.player.kabe.append( Huro(Naki.CHII, naki_tile_4, [Tile(Suit.MANZU.value, i) for i in range(6, 9)]))
def test_discard_tile(self): table = Table() player = Player(0, 0, table) tiles = self._string_to_136_array(sou='111345677', pin='15', man='56') tile = self._string_to_136_array(man='9')[0] player.init_hand(tiles) player.draw_tile(tile) discarded_tile = player.discard_tile() self.assertEqual(discarded_tile, 36) player.draw_tile(self._string_to_136_array(pin='4')[0]) discarded_tile = player.discard_tile() self.assertEqual(discarded_tile, 92) player.draw_tile(self._string_to_136_array(pin='3')[0]) discarded_tile = player.discard_tile() self.assertEqual(discarded_tile, 32) player.draw_tile(self._string_to_136_array(man='4')[0]) discarded_tile = player.discard_tile() self.assertEqual(discarded_tile, Shanten.AGARI_STATE)
def _init_players(self,): self.player = Player(self, 0, self.dealer_seat, self.previous_ai) self.players = [self.player] for seat in range(1, self.count_of_players): player = EnemyPlayer(self, seat, self.dealer_seat, self.previous_ai) self.players.append(player)
def setUp(self): self.player = Player('test', 1) self.player.hand[Tile(Suit.JIHAI.value, Jihai.SHAA.value).index] += 2 self.player.hand[Tile(Suit.MANZU.value, 2).index] += 1 self.player.hand[Tile(Suit.MANZU.value, 3).index] += 1 self.player.hand[Tile(Suit.MANZU.value, 4).index] += 1 self.player.hand[Tile(Suit.MANZU.value, 5).index] += 1 self.player.hand[Tile(Suit.MANZU.value, 6).index] += 1
def setUp(self): # tenpai: 3 MANZU 5 SOUZU self.player = Player('test', 1) for i in range(1, 10): self.player.hand[Tile(Suit.PINZU.value, i).index] += 1 self.player.hand[Tile(Suit.MANZU.value, 3).index] += 2 self.player.hand[Tile(Suit.SOUZU.value, 5).index] += 2 self.stack = Stack()
def _init_players(self, use_previous_ai_version=False): self.players = [] for seat in range(0, self.count_of_players): player = Player(seat=seat, dealer_seat=0, table=self, use_previous_ai_version=use_previous_ai_version) self.players.append(player)
def setUp(self): self.player = Player('test player', 0) self.stack = Stack() self.stack.doras = [Tile(Suit.PINZU.value, 3)] self.bakaze = Jihai.TON for i in range(2, 8): self.player.hand[Tile(Suit.PINZU.value, i).index] += 1 self.player.hand[Tile(Suit.MANZU.value, 3).index] += 3 self.player.hand[Tile(Suit.MANZU.value, 9).index] += 2 self.player.hand[Tile(Suit.SOUZU.value, 5).index] += 2 self.player.agari_tile = Tile(Suit.SOUZU.value, 5)
def setUp(self): self.player = Player('test', 0) self.player.hand[Tile(Suit.JIHAI.value, Jihai.HATSU.value).index] += 2 self.player.hand[Tile(Suit.JIHAI.value, Jihai.HAKU.value).index] += 2 self.player.hand[Tile(Suit.JIHAI.value, Jihai.CHUN.value).index] += 1 self.player.hand[Tile(Suit.JIHAI.value, Jihai.NAN.value).index] += 1 self.player.hand[Tile(Suit.PINZU.value, 1).index] += 1 self.player.hand[Tile(Suit.PINZU.value, 9).index] += 1 self.player.hand[Tile(Suit.SOUZU.value, 1).index] += 1 self.player.hand[Tile(Suit.SOUZU.value, 9).index] += 1 self.player.hand[Tile(Suit.SOUZU.value, 3).index] += 1 self.player.hand[Tile(Suit.SOUZU.value, 4).index] += 2
def new_game(self): self.history = [] players = [Player(i) for i in range(self.player_num)] self.dealer = Dealer(self.rand_seed) for player in players: self.dealer.deal_cards(player, 13) self.round = Round(self.dealer, players, self.config) self.player_id = self.dealer.get_banker() self.round.start() snapshot = self.round.get_snapshot() self.history.append(snapshot) return snapshot
def setUp(self): self.player = Player('test', 0) self.player.hand[Tile(Suit.SOUZU.value, 2).index] += 2 self.player.hand[Tile(Suit.SOUZU.value, 3).index] += 1 self.player.hand[Tile(Suit.SOUZU.value, 4).index] += 1 self.player.hand[Tile(Suit.SOUZU.value, 5).index] += 1 self.player.hand[Tile(Suit.MANZU.value, 8).index] += 3 self.player.hand[Tile(Suit.JIHAI.value, Jihai.NAN.value).index] += 3 naki_tile = Tile(Suit.SOUZU.value, 5) naki_tile.owner = 0 self.player.kabe.append( Huro(Naki.PON, naki_tile, [Tile(Suit.SOUZU.value, 5) for i in range(3)]))
def test_outs(self): table = Table() player = Player(0, 0, table) ai = MainAI(table, player) tiles = self._string_to_136_array(sou='111345677', pin='15', man='56') tile = self._string_to_136_array(man='9')[0] player.init_hand(tiles) player.draw_tile(tile) outs, shanten = ai.calculate_outs() self.assertEqual(shanten, 2) self.assertEqual(outs[0]['discard'], 9) self.assertEqual(outs[0]['waiting'], [3, 6, 7, 8, 11, 12, 13, 14, 15, 18, 19, 20, 21, 22, 23, 24, 25]) self.assertEqual(outs[0]['tiles_count'], 57) tiles = self._string_to_136_array(sou='111345677', pin='45', man='56') tile = self._string_to_136_array(man='9')[0] player.init_hand(tiles) player.draw_tile(tile) outs, shanten = ai.calculate_outs() self.assertEqual(shanten, 1) self.assertEqual(outs[0]['discard'], 23) self.assertEqual(outs[0]['waiting'], [3, 6, 11, 14]) self.assertEqual(outs[0]['tiles_count'], 16) tiles = self._string_to_136_array(sou='11145677', pin='345', man='56') tile = self._string_to_136_array(man='9')[0] player.init_hand(tiles) player.draw_tile(tile) outs, shanten = ai.calculate_outs() self.assertEqual(shanten, 0) self.assertEqual(outs[0]['discard'], 8) self.assertEqual(outs[0]['waiting'], [3, 6]) self.assertEqual(outs[0]['tiles_count'], 8) tiles = self._string_to_136_array(sou='11145677', pin='345', man='56') tile = self._string_to_136_array(man='4')[0] player.init_hand(tiles) player.draw_tile(tile) outs, shanten = ai.calculate_outs() self.assertEqual(shanten, Shanten.AGARI_STATE) self.assertEqual(len(outs), 0)
def setUp(self): # tenpai: 3 MANZU 5 SOUZU self.player_1 = Player('test_1', 1) self.player_1.hand[Tile(Suit.PINZU.value, 1).index] += 1 self.player_1.hand[Tile(Suit.PINZU.value, 2).index] += 1 self.player_1.hand[Tile(Suit.PINZU.value, 3).index] += 1 self.player_1.hand[Tile(Suit.PINZU.value, 4).index] += 1 self.player_1.hand[Tile(Suit.PINZU.value, 5).index] += 1 self.player_1.hand[Tile(Suit.PINZU.value, 6).index] += 1 self.player_1.hand[Tile(Suit.PINZU.value, 7).index] += 1 self.player_1.hand[Tile(Suit.PINZU.value, 8).index] += 1 self.player_1.hand[Tile(Suit.PINZU.value, 9).index] += 1 self.player_1.hand[Tile(Suit.MANZU.value, 3).index] += 2 self.player_1.hand[Tile(Suit.SOUZU.value, 5).index] += 2
def test_can_call_riichi_and_tempai(self): table = Table() player = Player(0, 0, table) player.in_tempai = False player.in_riichi = False player.scores = 2000 player.table.count_of_remaining_tiles = 40 self.assertEqual(player.can_call_riichi(), False) player.in_tempai = True self.assertEqual(player.can_call_riichi(), True)
def step_back(self, step: int) -> Snapshot: self.history = self.history[:-step] players = [] snapshot = self.history[-1] snapshot.print() for player_id, player_data in enumerate(snapshot.players): player = Player(player_id) player.load(player_data) players.append(player) self.round.players = players self.round.trace = self.round.trace[:snapshot.step_trace] self.round.player_id = snapshot.player_id self.dealer.jump(snapshot.step_deck) return snapshot
def setUp(self): self.player = Player('test', 1) self.player.hand[Tile(Suit.JIHAI.value, Jihai.SHAA.value).index] += 3 self.player.hand[Tile(Suit.JIHAI.value, Jihai.HATSU.value).index] += 2 self.player.hand[Tile(Suit.JIHAI.value, Jihai.HAKU.value).index] += 1 naki_tile_1 = Tile(Suit.PINZU.value, 5) naki_tile_1.owner = 0 naki_tile_2 = Tile(Suit.MANZU.value, 7) naki_tile_2.owner = 3 self.player.kabe.append( Huro(Naki.PON, naki_tile_1, [Tile(Suit.PINZU.value, 5) for i in range(3)])) self.player.kabe.append( Huro(Naki.PON, naki_tile_2, [Tile(Suit.MANZU.value, 7) for i in range(3)]))
def test_discard_isolated_honor_tiles_first(self): table = Table() player = Player(0, 0, table) tiles = self._string_to_136_array(sou='8', pin='56688', man='11323', honors='36') tile = self._string_to_136_array(man='9')[0] player.init_hand(tiles) player.draw_tile(tile) discarded_tile = player.discard_tile() self.assertEqual(discarded_tile, 128) player.draw_tile(self._string_to_136_array(man='4')[0]) discarded_tile = player.discard_tile() self.assertEqual(discarded_tile, 116)
def setUp(self): # tenpai: 3 MANZU 5 SOUZU self.player = Player('test', 1) self.player.hand[Tile(Suit.PINZU.value, 1).index] += 1 self.player.hand[Tile(Suit.PINZU.value, 2).index] += 1 self.player.hand[Tile(Suit.PINZU.value, 3).index] += 1 self.player.hand[Tile(Suit.PINZU.value, 4).index] += 1 self.player.hand[Tile(Suit.PINZU.value, 5).index] += 1 self.player.hand[Tile(Suit.PINZU.value, 6).index] += 1 self.player.hand[Tile(Suit.PINZU.value, 7).index] += 1 self.player.hand[Tile(Suit.PINZU.value, 8).index] += 1 self.player.hand[Tile(Suit.PINZU.value, 9).index] += 1 self.player.hand[Tile(Suit.MANZU.value, 3).index] += 2 self.player.hand[Tile(Suit.SOUZU.value, 5).index] += 2 self.stack = Stack() self.bakaze = Jihai.TON
def test_set_is_tempai_flag_to_the_player(self): table = Table() player = Player(0, 0, table) tiles = self._string_to_136_array(sou='111345677', pin='45', man='56') tile = self._string_to_136_array(man='9')[0] player.init_hand(tiles) player.draw_tile(tile) player.discard_tile() self.assertEqual(player.in_tempai, False) tiles = self._string_to_136_array(sou='11145677', pin='345', man='56') tile = self._string_to_136_array(man='9')[0] player.init_hand(tiles) player.draw_tile(tile) player.discard_tile() self.assertEqual(player.in_tempai, True)
def load_game(self, uuid, step) -> Snapshot: with open(f'logs/{uuid}_history.pickle', 'rb') as handle: self.history = pickle.load(handle) self.history = self.history[:step] self.dealer = Dealer(self.rand_seed) players = [] snapshot = self.history[-1] for player_id, player_data in enumerate(snapshot.players): player = Player(player_id) player.load(player_data) players.append(player) self.round = Round(self.dealer, players, self.config) with open(f'logs/{uuid}_trace.pickle', 'rb') as handle: self.round.trace = pickle.load(handle)[:snapshot.step_trace] self.round.player_id = snapshot.player_id self.dealer.jump(snapshot.step_deck) return snapshot
def test_no_ankan_after_riichi(self): # tenpai: 7 PINZU self.player = Player('test', 1) self.player.hand[Tile(Suit.MANZU.value, 1).index] += 4 self.player.hand[Tile(Suit.MANZU.value, 2).index] += 2 self.player.hand[Tile(Suit.MANZU.value, 3).index] += 2 self.player.hand[Tile(Suit.MANZU.value, 4).index] += 1 for i in range(4, 7): self.player.hand[Tile(Suit.SOUZU.value, i).index] += 1 self.player.hand[Tile(Suit.PINZU.value, 7).index] += 1 self.player.is_riichi = True ankan_tile = Tile(Suit.SOUZU.value, 1) ankan_tile.owner = 1 pyinput.inputNum = MagicMock(side_effect=[0]) (action, naki), discard_tile = self.player.action_with_new_tile( ankan_tile, False, self.stack, False) self.assertEqual(action, Action.NOACT) self.assertEqual(naki, Naki.NONE) self.assertEqual(discard_tile, ankan_tile)
def setUp(self): self.player = Player('test', 1)
def get_init_players(self, player_names): players = [] for i, name in enumerate(player_names): players.append(Player(name, i)) return players
def setUp(self): self.player = Player('test', 0) self.player.hand[Tile(Suit.PINZU.value, 1).index] += 3 self.player.hand[Tile(Suit.PINZU.value, 2).index] += 1 self.player.hand[Tile(Suit.PINZU.value, 3).index] += 1