Beispiel #1
0
 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)]))
Beispiel #2
0
 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()
Beispiel #3
0
 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
     ]
Beispiel #4
0
    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)
Beispiel #5
0
 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
Beispiel #6
0
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)
Beispiel #7
0
    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)
Beispiel #8
0
 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 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)
Beispiel #10
0
    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)
Beispiel #11
0
    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)
Beispiel #12
0
    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)
Beispiel #13
0
    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
Beispiel #14
0
 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
Beispiel #15
0
    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)
Beispiel #17
0
 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
Beispiel #18
0
    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
Beispiel #19
0
 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
Beispiel #20
0
class TestFuriten(unittest.TestCase):
    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_furiten(self):
        self.player.add_kawa(Tile(Suit.JIHAI.value, Jihai.TON.value))
        self.assertEqual(check_furiten(self.player), True)

    def test_no_furiten(self):
        self.assertEqual(check_furiten(self.player), False)

    def test_own_discard_furiten(self):
        self.player.add_kawa(Tile(Suit.JIHAI.value, Jihai.TON.value))
        self.assertEqual(check_own_discard_furiten(self.player), True)

    def test_no_own_discard_furiten(self):
        self.assertEqual(check_own_discard_furiten(self.player), False)
Beispiel #21
0
    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)
Beispiel #22
0
 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)]))
Beispiel #23
0
class TestRon(unittest.TestCase):
    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_ron(self):
        discard_1 = Tile(Suit.MANZU.value, 3)
        discard_2 = Tile(Suit.SOUZU.value, 5)

        ron_1 = check_ron(self.player, discard_1, self.stack, self.bakaze)
        ron_2 = check_ron(self.player, discard_2, self.stack, self.bakaze)
        self.assertEqual(ron_1, True)
        self.assertEqual(ron_2, True)

    def test_no_ron(self):
        discard_1 = Tile(Suit.MANZU.value, 4)
        ron_1 = check_ron(self.player, discard_1, self.stack, self.bakaze)
        self.assertEqual(ron_1, False)

        # 振聴
        discard_2 = Tile(Suit.MANZU.value, 3)
        self.player.add_kawa(Tile(Suit.MANZU.value, 3))

        ron_2 = check_ron(self.player, discard_2, self.stack, self.bakaze)
        self.assertEqual(ron_2, False)
Beispiel #24
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
Beispiel #25
0
 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)]))
Beispiel #26
0
    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)
Beispiel #27
0
    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)
Beispiel #28
0
class TestTurnDrawFlow(unittest.TestCase):
    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 test_riichi(self):
        self.player_1.action_with_new_tile = MagicMock(
            return_value=((Action.RIICHI, Naki.NONE), None))
        self.assertEqual(self.turn.draw_flow(self.player_1),
                         (0, None, 0, Action.RIICHI))

    def test_tsumo(self):
        self.player_1.action_with_new_tile = MagicMock(
            return_value=((Action.TSUMO, Naki.NONE), None))
        self.assertEqual(self.turn.draw_flow(self.player_1),
                         (1, None, None, Action.TSUMO))

    def test_ankan(self):
        naki_tile = Tile(Suit.SOUZU.value, 5)
        naki_tile.owner = self.player_1.seating_position
        kan = Huro(Naki.ANKAN, naki_tile,
                   [Tile(Suit.SOUZU.value, 5) for i in range(4)])

        self.player_1.tmp_huro = kan

        self.player_1.action_with_new_tile = MagicMock()
        self.player_1.action_with_new_tile.side_effect = [
            ((Action.NAKI, Naki.CHAKAN), None),
            ((Action.NOACT, Naki.NONE), Tile(0, 1))
        ]
        self.turn.kan_flow = MagicMock(return_value=0)

        state, discard_tile, discard_pos, act = self.turn.draw_flow(
            self.player_1)
        self.assertEqual(state, 0)
        self.assertEqual(discard_tile, Tile(0, 1))
        self.assertEqual(discard_pos, 0)
        self.assertEqual(self.player_1.kawa[0], Tile(0, 1))
        self.assertEqual(len(self.tile_stack.doras), 2)

    def test_chakan(self):
        # change type from PON to KAN, what's tmp_huro in this case?
        naki_tile = Tile(Suit.SOUZU.value, 5)
        naki_tile.owner = self.player_1.seating_position
        kan = Huro(Naki.ANKAN, naki_tile,
                   [Tile(Suit.SOUZU.value, 5) for i in range(4)])

        self.player_1.tmp_huro = kan

        self.player_1.action_with_new_tile = MagicMock()
        self.player_1.action_with_new_tile.side_effect = [
            ((Action.NAKI, Naki.CHAKAN), None),
            ((Action.NOACT, Naki.NONE), Tile(0, 1))
        ]
        self.turn.kan_flow = MagicMock(return_value=0)
        state, discard_tile, discard_pos, act = self.turn.draw_flow(
            self.player_1)
        self.assertEqual(state, 0)
        self.assertEqual(discard_tile, Tile(0, 1))
        self.assertEqual(discard_pos, 0)
        self.assertEqual(self.player_1.kawa[0], Tile(0, 1))
        self.assertEqual(len(self.tile_stack.doras), 2)

    def test_chakan_chankan(self):
        naki_tile = Tile(Suit.SOUZU.value, 5)
        naki_tile.owner = self.player_1.seating_position
        kan = Huro(Naki.ANKAN, naki_tile,
                   [Tile(Suit.SOUZU.value, 5) for i in range(4)])

        self.player_1.tmp_huro = kan

        self.player_1.action_with_new_tile = MagicMock()
        self.player_1.action_with_new_tile.side_effect = [
            ((Action.NAKI, Naki.CHAKAN), None),
            ((Action.NOACT, Naki.NONE), Tile(0, 1))
        ]
        self.turn.kan_flow = MagicMock(return_value=1)
        state, discard_tile, discard_pos = self.turn.draw_flow(self.player_1)
        self.assertEqual(state, 1)
        self.assertEqual(discard_tile, None)
        self.assertEqual(discard_pos, None)

    def test_ankan_twice(self):
        naki_tile_1 = Tile(Suit.SOUZU.value, 5)
        naki_tile_1.owner = self.player_1.seating_position
        naki_tile_2 = Tile(Suit.SOUZU.value, 6)
        naki_tile_2.owner = self.player_1.seating_position
        kan_1 = Huro(Naki.ANKAN, naki_tile_1,
                     [Tile(Suit.SOUZU.value, 5) for i in range(4)])
        kan_2 = Huro(Naki.ANKAN, naki_tile_2,
                     [Tile(Suit.SOUZU.value, 6) for i in range(4)])

        self.player_1 = Mock()
        self.player_1.seating_position = 0
        self.player_1.get_shimocha = lambda: 1 % 4
        self.player_1.hand = defaultdict(int)
        self.player_1.kawa = []
        self.player_1.add_kawa = lambda tile: self.player_1.kawa.append(tile)
        p = PropertyMock(side_effect=[kan_1, kan_2])
        type(self.player_1).tmp_huro = p

        self.player_1.action_with_new_tile = MagicMock()
        self.player_1.action_with_new_tile.side_effect = [
            ((Action.NAKI, Naki.ANKAN), None),
            ((Action.NAKI, Naki.ANKAN), None),
            ((Action.NOACT, Naki.NONE), Tile(0, 1))
        ]
        state, discard_tile, discard_pos, act = self.turn.draw_flow(
            self.player_1)
        self.assertEqual(state, 0)
        self.assertEqual(discard_tile, Tile(0, 1))
        self.assertEqual(discard_pos, 0)
        self.assertEqual(self.player_1.kawa[0], Tile(0, 1))
        self.assertEqual(len(self.tile_stack.doras), 3)

    def test_draw_flow_suukaikan(self):
        # is declared when four quads are formed by different players.
        for _ in range(3):
            self.tile_stack.add_dora_indicator()
        naki_tile = Tile(Suit.SOUZU.value, 5)
        naki_tile.owner = self.player_1.seating_position

        kan = Huro(Naki.ANKAN, naki_tile,
                   [Tile(Suit.SOUZU.value, 5) for i in range(4)])
        self.player_1.action_with_new_tile = MagicMock()
        self.player_1.action_with_new_tile.side_effect = [
            ((Action.NAKI, Naki.ANKAN), None),
            ((Action.NOACT, Naki.NONE), Tile(0, 1))
        ]
        self.player_1.action_with_naki = MagicMock(
            self.player_1.kabe.append(kan))
        state, discard_tile, discard_pos, _ = self.turn.draw_flow(
            self.player_1)
        self.assertEqual(state, 0)
        self.assertEqual(discard_tile, Tile(0, 1))
        self.assertEqual(discard_pos, self.player_1.seating_position)
        self.assertEqual(len(self.tile_stack.doras), 5)
        self.assertEqual(self.turn.suukaikan, True)

    def test_draw_flow_suukantsu(self):
        for _ in range(3):
            self.tile_stack.add_dora_indicator()
        naki_tile_1 = Tile(Suit.SOUZU.value, 5)
        naki_tile_1.owner = self.player_1.seating_position
        naki_tile_2 = Tile(Suit.SOUZU.value, 6)
        naki_tile_2.owner = self.player_1.seating_position
        naki_tile_3 = Tile(Suit.SOUZU.value, 7)
        naki_tile_3.owner = self.player_1.seating_position
        naki_tile_4 = Tile(Suit.SOUZU.value, 8)
        naki_tile_4.owner = self.player_1.seating_position
        kan_1 = Huro(Naki.ANKAN, naki_tile_1,
                     [Tile(Suit.SOUZU.value, 5) for i in range(4)])
        kan_2 = Huro(Naki.ANKAN, naki_tile_2,
                     [Tile(Suit.SOUZU.value, 6) for i in range(4)])
        kan_3 = Huro(Naki.ANKAN, naki_tile_3,
                     [Tile(Suit.SOUZU.value, 7) for i in range(4)])
        kan_4 = Huro(Naki.ANKAN, naki_tile_4,
                     [Tile(Suit.SOUZU.value, 8) for i in range(4)])
        self.player_1.kabe.append(kan_1)
        self.player_1.kabe.append(kan_2)
        self.player_1.kabe.append(kan_3)
        self.player_1.action_with_new_tile = MagicMock()
        self.player_1.action_with_new_tile.side_effect = [
            ((Action.NAKI, Naki.ANKAN), None),
            ((Action.NOACT, Naki.NONE), Tile(0, 1))
        ]
        self.player_1.action_with_naki = MagicMock()

        def m(_):
            self.player_1.kabe.append(kan_4)

        self.player_1.action_with_naki.side_effect = m
        state, discard_tile, discard_pos, act = self.turn.draw_flow(
            self.player_1)
        self.assertEqual(state, 0)
        self.assertEqual(discard_tile, Tile(0, 1))
        self.assertEqual(discard_pos, 0)
        self.assertEqual(len(self.tile_stack.doras), 5)

    def test_suukantsu_other_player(self):
        for _ in range(3):
            self.tile_stack.add_dora_indicator()
        naki_tile = Tile(Suit.SOUZU.value, 5)
        naki_tile.owner = self.player_1.seating_position
        kan = Huro(Naki.DAMINKAN, naki_tile,
                   [Tile(Suit.SOUZU.value, 5) for i in range(4)])
        kabe = [kan]
        self.turn.check_suukaikan(kabe)
        self.assertEqual(len(self.tile_stack.doras), 5)
        self.assertEqual(self.turn.suukaikan, True)

    def test_suukaikan(self):
        for _ in range(3):
            self.tile_stack.add_dora_indicator()
        naki_tile = Tile(Suit.SOUZU.value, 5)
        naki_tile.owner = self.player_1.seating_position
        kan = Huro(Naki.DAMINKAN, naki_tile,
                   [Tile(Suit.SOUZU.value, 5) for i in range(4)])
        kabe = [kan]
        self.turn.check_suukaikan(kabe)
        self.assertEqual(len(self.tile_stack.doras), 5)
        self.assertEqual(self.turn.suukaikan, True)

    def test_suukantsu(self):
        for _ in range(3):
            self.tile_stack.add_dora_indicator()
        naki_tile_1 = Tile(Suit.SOUZU.value, 5)
        naki_tile_1.owner = self.player_1.seating_position
        naki_tile_2 = Tile(Suit.SOUZU.value, 6)
        naki_tile_2.owner = self.player_1.seating_position
        naki_tile_3 = Tile(Suit.SOUZU.value, 7)
        naki_tile_3.owner = self.player_1.seating_position
        naki_tile_4 = Tile(Suit.SOUZU.value, 8)
        naki_tile_4.owner = self.player_1.seating_position
        kan_1 = Huro(Naki.ANKAN, naki_tile_1,
                     [Tile(Suit.SOUZU.value, 5) for i in range(4)])
        kan_2 = Huro(Naki.ANKAN, naki_tile_2,
                     [Tile(Suit.SOUZU.value, 6) for i in range(4)])
        kan_3 = Huro(Naki.ANKAN, naki_tile_3,
                     [Tile(Suit.SOUZU.value, 7) for i in range(4)])
        kan_4 = Huro(Naki.ANKAN, naki_tile_4,
                     [Tile(Suit.SOUZU.value, 8) for i in range(4)])
        kabe = [kan_1, kan_2, kan_3, kan_4]
        self.turn.check_suukaikan(kabe)
        self.assertEqual(len(self.tile_stack.doras), 5)
        self.assertEqual(self.turn.suukaikan, False)

    def test_no_suukaikan(self):
        self.tile_stack.add_dora_indicator()
        naki_tile = Tile(Suit.SOUZU.value, 5)
        naki_tile.owner = self.player_1.seating_position
        kan = Huro(Naki.ANKAN, naki_tile,
                   [Tile(Suit.SOUZU.value, 5) for i in range(4)])
        kabe = [kan]
        self.turn.check_suukaikan(kabe)
        self.assertEqual(self.turn.suukaikan, False)

    def test_rinshan_kaihou(self):
        naki_tile = Tile(Suit.SOUZU.value, 5)
        naki_tile.owner = self.player_1.seating_position
        kan = Huro(Naki.ANKAN, naki_tile,
                   [Tile(Suit.SOUZU.value, 5) for i in range(4)])

        self.player_1.tmp_huro = kan
        self.player_1.action_with_new_tile = MagicMock()
        self.player_1.action_with_new_tile.side_effect = [
            ((Action.NAKI, Naki.ANKAN), None),
            ((Action.TSUMO, Naki.NONE), None)
        ]
        state, discard_tile, discard_pos, act = self.turn.draw_flow(
            self.player_1)
        self.assertEqual(state, 1)
        self.assertEqual(discard_tile, None)
        self.assertEqual(discard_pos, None)

    def test_suufon_renda(self):
        tile_ton = Tile(Suit.JIHAI.value, Jihai.TON.value)
        self.player_1.add_kawa(tile_ton)
        self.player_2.add_kawa(tile_ton)
        self.player_3.add_kawa(tile_ton)
        self.player_4.add_kawa(tile_ton)

        self.assertEqual(self.turn.check_suufon_renda(), True)

    def test_suufon_renda_counter_example(self):
        tile_ton = Tile(Suit.JIHAI.value, Jihai.TON.value)
        tile_nan = Tile(Suit.JIHAI.value, Jihai.NAN.value)
        self.player_1.add_kawa(tile_nan)
        self.player_2.add_kawa(tile_ton)
        self.player_3.add_kawa(tile_ton)
        self.player_4.add_kawa(tile_ton)

        self.assertEqual(self.turn.check_suufon_renda(), False)
Beispiel #29
0
    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)
Beispiel #30
0
 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