コード例 #1
0
    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)
コード例 #2
0
 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)])
     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_naki = MagicMock(
         self.player_1.kabe.append(kan_4))
     self.turn.draw_flow = MagicMock(return_value=(0, Tile(0, 1), 0,
                                                   Action.NAKI))
     state, discard_tile, discard_pos, act = self.turn.naki_flow(
         self.player_1, Naki.DAMINKAN)
     self.assertEqual(state, 0)
     self.assertEqual(discard_tile, Tile(0, 1))
     self.assertEqual(discard_pos, 0)
     self.assertEqual(len(self.tile_stack.doras), 5)
コード例 #3
0
    def test_tenpai_6(self):
        self.player.hand[Tile(Suit.JIHAI.value, Jihai.TON.value).index] += 1
        naki_tile_1 = Tile(Suit.JIHAI.value, Jihai.SHAA.value)
        naki_tile_1.owner = 3
        naki_tile_2 = Tile(Suit.SOUZU.value, 5)
        naki_tile_2.owner = 3
        naki_tile_3 = Tile(Suit.PINZU.value, 5)
        naki_tile_3.owner = 2
        naki_tile_4 = Tile(Suit.MANZU.value, 9)
        naki_tile_4.owner = 0
        self.player.kabe.append(
            Huro(Naki.PON, naki_tile_1,
                 [Tile(Suit.JIHAI.value, Jihai.SHAA.value) for i in range(3)]))
        self.player.kabe.append(
            Huro(Naki.PON, naki_tile_2,
                 [Tile(Suit.SOUZU.value, 5) for i in range(3)]))
        self.player.kabe.append(
            Huro(Naki.PON, naki_tile_3,
                 [Tile(Suit.PINZU.value, 5) for i in range(3)]))
        self.player.kabe.append(
            Huro(Naki.CHII, naki_tile_4,
                 [Tile(Suit.MANZU.value, i) for i in range(7, 10)]))
        tenpai = [Tile(Suit.JIHAI.value, Jihai.TON.value)]

        self.assert_tenpai(self.player, tenpai)
コード例 #4
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)]))
コード例 #5
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)]))
コード例 #6
0
 def setUp(self):
     chii_tile = Tile(Suit.MANZU.value, 7)
     chii_tile.owner = 0
     self.huro_chii = Huro(Naki.CHII, chii_tile, [
         Tile(Suit.MANZU.value, 7),
         Tile(Suit.MANZU.value, 8),
         Tile(Suit.MANZU.value, 9)
     ])
     pon_tile = Tile(Suit.MANZU.value, 2)
     pon_tile.owner = 0
     self.huro_pon = Huro(Naki.PON, pon_tile,
                          [Tile(Suit.MANZU.value, 2) for i in range(3)])
     kan_tile = Tile(Suit.MANZU.value, 5)
     kan_tile.owner = 0
     self.huro_kan = Huro(Naki.DAMINKAN, kan_tile,
                          [Tile(Suit.MANZU.value, 5) for i in range(4)])
コード例 #7
0
    def test_pon(self):
        self.current_kyoku.deal()

        # change tile in hand to test pon
        pon_tile = Tile(Suit.JIHAI.value, Jihai.CHUN.value)
        pon_tile.owner = self.players[0].seating_position
        to_discard_tile = Tile(Suit.JIHAI.value, Jihai.HAKU.value)

        self.current_kyoku.players[0].hand = defaultdict(int)
        self.current_kyoku.players[0].hand[pon_tile.index] = 1
        self.current_kyoku.players[0].hand[Tile(2, 1).index] += 1
        self.current_kyoku.players[0].hand[Tile(2, 2).index] += 1
        self.current_kyoku.players[0].hand[Tile(2, 3).index] += 1
        self.current_kyoku.players[1].hand = defaultdict(int)
        self.current_kyoku.players[1].hand[pon_tile.index] = 2
        self.current_kyoku.players[1].hand[to_discard_tile.index] = 1
        self.current_kyoku.players[1].hand[Tile(2, 2).index] += 1
        self.current_kyoku.players[1].hand[Tile(2, 3).index] += 1
        self.current_kyoku.players[1].hand[Tile(2, 4).index] += 1
        self.current_kyoku.players[2].hand = defaultdict(int)
        self.current_kyoku.players[2].hand[Tile(2, 5).index] += 1
        self.current_kyoku.players[2].hand[Tile(2, 6).index] += 1
        self.current_kyoku.players[2].hand[Tile(2, 7).index] += 1
        self.current_kyoku.players[3].hand = defaultdict(int)
        self.current_kyoku.players[3].hand[Tile(2, 7).index] += 1
        self.current_kyoku.players[3].hand[Tile(2, 8).index] += 1
        self.current_kyoku.players[3].hand[Tile(2, 9).index] += 1

        pyinput.inputNum = MagicMock(side_effect=[1, 0, 0])
        pyinput.inputChoice = MagicMock(return_value=2)

        turn = Turn(
            self.current_kyoku.players,
            self.current_kyoku.tile_stack,
            Jihai.TON,
            self.logger,
        )

        mock_draw_flow = MagicMock(
            return_value=(0, pon_tile, self.players[0].seating_position))
        state, discard_tile, discard_pos = mock_draw_flow(
            self.current_kyoku.oya_player)

        state, discard_tile, discard_pos, act = turn.discard_flow(
            discard_tile, discard_pos)

        pon_in_kabe = Huro(Naki.PON, pon_tile, [pon_tile, pon_tile, pon_tile])

        # Raw input: 1, 2, 0, 0

        self.assertEqual(state, 0)
        self.assertEqual(discard_tile, to_discard_tile)
        self.assertEqual(discard_pos, self.players[1].seating_position)
        self.assertEqual(pon_in_kabe.naki_type,
                         self.players[1].kabe[0].naki_type)
        self.assertEqual(pon_in_kabe.naki_tile,
                         self.players[1].kabe[0].naki_tile)
        # test remove_huro_tiles()
        self.assertEqual(self.players[1].hand[pon_tile.index], 0)
        self.assertEqual(pon_in_kabe.tiles, self.players[1].kabe[0].tiles)
コード例 #8
0
class TestHuro(unittest.TestCase):
    def setUp(self):
        chii_tile = Tile(Suit.MANZU.value, 7)
        chii_tile.owner = 0
        self.huro_chii = Huro(Naki.CHII, chii_tile, [
            Tile(Suit.MANZU.value, 7),
            Tile(Suit.MANZU.value, 8),
            Tile(Suit.MANZU.value, 9)
        ])
        pon_tile = Tile(Suit.MANZU.value, 2)
        pon_tile.owner = 0
        self.huro_pon = Huro(Naki.PON, pon_tile,
                             [Tile(Suit.MANZU.value, 2) for i in range(3)])
        kan_tile = Tile(Suit.MANZU.value, 5)
        kan_tile.owner = 0
        self.huro_kan = Huro(Naki.DAMINKAN, kan_tile,
                             [Tile(Suit.MANZU.value, 5) for i in range(4)])

    def test_naki_type(self):
        self.assertEqual(self.huro_kan.naki_type, Naki.DAMINKAN)

    def test_tiles_getter(self):
        tiles_in_huro = [
            Tile(Suit.MANZU.value, 7),
            Tile(Suit.MANZU.value, 8),
            Tile(Suit.MANZU.value, 9)
        ]
        self.assertEqual(self.huro_chii.tiles, tiles_in_huro)

    def test_tiles_setter(self):
        new_tiles_in_huro = [
            Tile(Suit.MANZU.value, 5),
            Tile(Suit.MANZU.value, 6),
            Tile(Suit.MANZU.value, 7)
        ]
        self.huro_chii.tiles = new_tiles_in_huro
        self.assertEqual(self.huro_chii.tiles, new_tiles_in_huro)

    def test_add_kan(self):
        self.huro_pon.add_kan(Tile(Suit.MANZU.value, 2))
        self.assertEqual(self.huro_pon.naki_type, Naki.CHAKAN)

    def test_add_kan_error(self):
        with self.assertRaises(ValueError):
            self.huro_chii.add_kan(Tile(Suit.MANZU.value, 7))
コード例 #9
0
 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)
コード例 #10
0
 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)
コード例 #11
0
    def test_no_riichi_kabe(self):
        self.player.hand[Tile(Suit.PINZU.value, 1).index] -= 1
        self.player.hand[Tile(Suit.SOUZU.value, 5).index] -= 2
        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)]))
        self.player.menzenchin = False

        machi = check_tenpai(self.player.hand, self.player.kabe)
        riichi = check_riichi(self.player, machi, self.stack)
        self.assertEqual(riichi, False)
コード例 #12
0
 def test_tenpai_7(self):
     self.player.hand[Tile(Suit.MANZU.value, 1).index] += 4
     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] += 4
     naki_tile = Tile(Suit.JIHAI.value, Jihai.SHAA.value)
     naki_tile.owner = 0
     self.player.kabe.append(
         Huro(Naki.PON, naki_tile,
              [Tile(Suit.JIHAI.value, Jihai.SHAA.value) for i in range(3)]))
     tenpai = [Tile(Suit.MANZU.value, 1), Tile(Suit.MANZU.value, 4)]
     # tenpai: 1 MANZU 4 MANZU 空聴(カラテン)
     self.assert_tenpai(self.player, tenpai)
コード例 #13
0
    def test_tenpai_5(self):
        self.player.hand[Tile(Suit.PINZU.value, 9).index] += 2
        self.player.hand[Tile(Suit.MANZU.value, 1).index] += 1
        self.player.hand[Tile(Suit.MANZU.value, 3).index] += 1
        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
        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)]))
        tenpai = [Tile(Suit.MANZU.value, 2)]

        self.assert_tenpai(self.player, tenpai)
コード例 #14
0
ファイル: test_helpers.py プロジェクト: rasca0027/Mahjong4RL
 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)]))
コード例 #15
0
ファイル: test_kyoku.py プロジェクト: rasca0027/Mahjong4RL
 def test_no_nagashi_mangan_2(self):
     self.player_1.furiten_tiles_idx.add(Tile(Suit.MANZU.value, 1).index)
     self.player_1.furiten_tiles_idx.add(Tile(Suit.MANZU.value, 9).index)
     naki_tile = Tile(Suit.JIHAI.value, Jihai.HAKU.value)
     naki_tile.owner = self.player_1.seating_position
     huro = Huro(Naki.CHII, naki_tile, [])
     self.player_2.kabe = [huro]
     self.player_2.furiten_tiles_idx.add(Tile(Suit.MANZU.value, 5).index)
     self.player_3.furiten_tiles_idx.add(Tile(Suit.MANZU.value, 5).index)
     self.player_3.furiten_tiles_idx.add(Tile(Suit.MANZU.value, 5).index)
     self.player_4.furiten_tiles_idx.add(Tile(Suit.MANZU.value, 5).index)
     winner = self.kyoku.check_nagashi_mangan()
     self.assertEqual(winner, None)
コード例 #16
0
    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)
コード例 #17
0
 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)
コード例 #18
0
    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)
コード例 #19
0
    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)
コード例 #20
0
    def test_tenpai_4(self):
        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] += 2
        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)]))
        tenpai = [
            Tile(Suit.JIHAI.value, Jihai.NAN.value),
            Tile(Suit.SOUZU.value, 2)
        ]

        self.assert_tenpai(self.player, tenpai)
コード例 #21
0
    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)
コード例 #22
0
ファイル: test_logger.py プロジェクト: rasca0027/Mahjong4RL
 def test_log_naki(self):
     naki_tile = Tile(Suit.SOUZU.value, 5)
     kan = Huro(Naki.ANKAN, naki_tile,
                [Tile(Suit.SOUZU.value, 5) for i in range(4)])
     logger = KyokuLogger()
     logger.log(
         p_pos=self.player_1.seating_position,
         action=Action.NAKI,
         action_tile=naki_tile,
         naki_type=Naki.ANKAN,
         huro=kan,
     )
     log = logger.logs[0]
     self.assertEqual(log.p_pos, 0)
     self.assertEqual(log.action, Action.NAKI)
     self.assertEqual(log.action_tile, naki_tile)
     self.assertEqual(log.naki_type, Naki.ANKAN)
     self.assertEqual(
         str(log),
         "Player 0 NAKI ANKAN with 5 SOUZU forms "
         "5 SOUZU|5 SOUZU|5 SOUZU|5 SOUZU",
     )
コード例 #23
0
    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)
コード例 #24
0
    def test_chii(self):
        self.current_kyoku.deal()

        # change tile in hand to test chii
        chii_tile = Tile(Suit.MANZU.value, 5)
        chii_tile.owner = self.players[0].seating_position
        to_discard_tile = Tile(Suit.PINZU.value, 9)

        self.current_kyoku.players[0].hand = defaultdict(int)
        self.current_kyoku.players[0].hand[chii_tile.index] = 1
        self.current_kyoku.players[0].hand[Tile(2, 1).index] += 1
        self.current_kyoku.players[0].hand[Tile(2, 2).index] += 1
        self.current_kyoku.players[0].hand[Tile(2, 3).index] += 1
        self.current_kyoku.players[1].hand = defaultdict(int)
        self.current_kyoku.players[1].hand[chii_tile.index - 1] = 1
        self.current_kyoku.players[1].hand[chii_tile.index + 1] = 1
        self.current_kyoku.players[1].hand[to_discard_tile.index] = 1
        self.current_kyoku.players[1].hand[Tile(2, 2).index] += 2
        self.current_kyoku.players[1].hand[Tile(2, 3).index] += 1
        self.current_kyoku.players[1].hand[Tile(2, 4).index] += 1
        self.current_kyoku.players[2].hand = defaultdict(int)
        self.current_kyoku.players[2].hand[Tile(2, 5).index] += 2
        self.current_kyoku.players[2].hand[Tile(2, 6).index] += 1
        self.current_kyoku.players[2].hand[Tile(2, 7).index] += 1
        self.current_kyoku.players[3].hand = defaultdict(int)
        self.current_kyoku.players[3].hand[Tile(3, 7).index] += 2
        self.current_kyoku.players[3].hand[Tile(3, 8).index] += 1
        self.current_kyoku.players[3].hand[Tile(3, 9).index] += 1

        pyinput.inputNum = MagicMock(side_effect=[1, 0, 4])
        pyinput.inputChoice = MagicMock(return_value=1)

        turn = Turn(
            self.current_kyoku.players,
            self.current_kyoku.tile_stack,
            Jihai.TON,
            self.logger,
        )

        mock_draw_flow = MagicMock(
            return_value=(0, chii_tile, self.players[0].seating_position))
        state, discard_tile, discard_pos = mock_draw_flow(
            self.current_kyoku.oya_player)

        state, discard_tile, discard_pos, act = turn.discard_flow(
            discard_tile, discard_pos)

        chii_in_kabe = Huro(
            Naki.CHII, chii_tile,
            [chii_tile.prev_tile(), chii_tile,
             chii_tile.next_tile()])

        self.assertEqual(state, 0)
        self.assertEqual(discard_tile, to_discard_tile)
        self.assertEqual(discard_pos, self.players[1].seating_position)
        self.assertEqual(chii_in_kabe.naki_type,
                         self.players[1].kabe[0].naki_type)
        self.assertEqual(chii_in_kabe.naki_tile,
                         self.players[1].kabe[0].naki_tile)
        # test remove_huro_tiles()
        self.assertEqual(self.players[1].hand[chii_tile.index - 1], 0)
        self.assertEqual(self.players[1].hand[chii_tile.index + 1], 0)
        self.assertEqual(chii_in_kabe.tiles, self.players[1].kabe[0].tiles)
コード例 #25
0
    def test_ankan(self):
        self.current_kyoku.deal()

        kan_tile = Tile(Suit.JIHAI.value, Jihai.CHUN.value)
        to_discard_tile = Tile(Suit.JIHAI.value, Jihai.HAKU.value)

        self.current_kyoku.players[0].hand = defaultdict(int)
        self.current_kyoku.players[0].hand[Tile(2, 1).index] += 2
        self.current_kyoku.players[0].hand[Tile(2, 2).index] += 1
        self.current_kyoku.players[0].hand[Tile(2, 3).index] += 1
        self.current_kyoku.players[1].hand = defaultdict(int)
        self.current_kyoku.players[1].hand[kan_tile.index] = 3
        self.current_kyoku.players[1].hand[to_discard_tile.index] = 1
        self.current_kyoku.players[1].hand[Tile(2, 2).index] += 2
        self.current_kyoku.players[1].hand[Tile(2, 3).index] += 1
        self.current_kyoku.players[1].hand[Tile(2, 4).index] += 1
        self.current_kyoku.players[2].hand = defaultdict(int)
        self.current_kyoku.players[2].hand[Tile(2, 5).index] += 2
        self.current_kyoku.players[2].hand[Tile(2, 6).index] += 1
        self.current_kyoku.players[2].hand[Tile(2, 7).index] += 1
        self.current_kyoku.players[3].hand = defaultdict(int)
        self.current_kyoku.players[3].hand[Tile(2, 7).index] += 2
        self.current_kyoku.players[3].hand[Tile(2, 8).index] += 1
        self.current_kyoku.players[3].hand[Tile(2, 9).index] += 1

        pyinput.inputNum = MagicMock(side_effect=[1, 0, 0])
        pyinput.inputChoice = MagicMock(return_value=5)

        turn = Turn(
            self.current_kyoku.players,
            self.current_kyoku.tile_stack,
            Jihai.TON,
            self.logger,
        )

        mock_draw_flow = MagicMock(
            return_value=(0, Tile(Suit.JIHAI.value, Jihai.TON.value),
                          self.players[0].seating_position))
        state, discard_tile, discard_pos = mock_draw_flow(
            self.current_kyoku.oya_player)

        ankan_tile = kan_tile
        with patch('mahjong.components.Stack.draw') as mock_func:

            def f(from_rinshan):
                if from_rinshan:
                    return Tile(Suit.SOUZU.value, 9)
                else:
                    return ankan_tile

            mock_func.side_effect = f
            state, discard_tile, discard_pos, act = turn.discard_flow(
                discard_tile, discard_pos)

        kan_in_kabe = Huro(Naki.ANKAN, ankan_tile,
                           [kan_tile, kan_tile, kan_tile, kan_tile])

        self.assertEqual(state, 0)
        self.assertEqual(discard_tile, to_discard_tile)
        self.assertEqual(discard_pos, self.players[1].seating_position)
        self.assertEqual(kan_in_kabe.naki_type,
                         self.players[1].kabe[0].naki_type)
        self.assertEqual(kan_in_kabe.naki_tile,
                         self.players[1].kabe[0].naki_tile)
        self.assertEqual(self.players[1].hand[ankan_tile.index], 0)
        self.assertEqual(kan_in_kabe.tiles, self.players[1].kabe[0].tiles)