Ejemplo n.º 1
0
    def test_enemy_discard_and_safe_tiles(self):
        client = Client()
        client.table.init_round(0, 0, 0, 0, 0, [0, 0, 0, 0])

        client.table.players[0].in_riichi = True
        client.enemy_discard(1, 10)

        self.assertEqual(len(client.table.players[0].safe_tiles), 1)
Ejemplo n.º 2
0
    def test_call_riichi(self):
        clients = [Client() for _ in range(0, 4)]
        manager = GameManager(clients)
        manager.init_game()
        manager.init_round()

        client = clients[0]
        self.assertEqual(manager.riichi_sticks, 0)
        self.assertEqual(client.player.scores, 25000)
        self.assertEqual(client.player.in_riichi, False)

        manager.call_riichi(client)

        self.assertEqual(manager.riichi_sticks, 1)
        self.assertEqual(client.player.scores, 24000)
        self.assertEqual(client.player.in_riichi, True)

        clients = [Client() for _ in range(0, 4)]
        manager = GameManager(clients)
        manager.init_game()
        manager.init_round()

        manager.call_riichi(clients[0])

        self.assertEqual(clients[0].player.in_riichi, True)
        self.assertEqual(clients[1].player.in_riichi, False)
        self.assertEqual(clients[2].player.in_riichi, False)
        self.assertEqual(clients[3].player.in_riichi, False)

        for client in clients:
            client.player.in_riichi = False

        manager.call_riichi(clients[1])

        self.assertEqual(clients[0].player.in_riichi, False)
        self.assertEqual(clients[1].player.in_riichi, True)
        self.assertEqual(clients[2].player.in_riichi, False)
        self.assertEqual(clients[3].player.in_riichi, False)

        for client in clients:
            client.player.in_riichi = False

        manager.call_riichi(clients[2])

        self.assertEqual(clients[0].player.in_riichi, False)
        self.assertEqual(clients[1].player.in_riichi, False)
        self.assertEqual(clients[2].player.in_riichi, True)
        self.assertEqual(clients[3].player.in_riichi, False)

        for client in clients:
            client.player.in_riichi = False

        manager.call_riichi(clients[3])

        self.assertEqual(clients[0].player.in_riichi, False)
        self.assertEqual(clients[1].player.in_riichi, False)
        self.assertEqual(clients[2].player.in_riichi, False)
        self.assertEqual(clients[3].player.in_riichi, True)
Ejemplo n.º 3
0
    def test_enemy_discard(self):
        client = Client()
        client.table.init_round(0, 0, 0, 0, 0, [0, 0, 0, 0])

        self.assertEqual(client.table.count_of_remaining_tiles, 70)

        client.enemy_discard(1, 10)

        self.assertEqual(len(client.table.get_player(1).discards), 1)
        self.assertEqual(client.table.count_of_remaining_tiles, 69)
Ejemplo n.º 4
0
    def test_enemy_in_riichi(self):
        client = Client()
        client.table.init_round(0, 0, 0, 0, 0, [0, 0, 0, 0])
        player_seat = 1

        self.assertEqual(client.table.get_player(player_seat).in_riichi, False)

        client.enemy_riichi(player_seat)

        self.assertEqual(client.table.get_player(player_seat).in_riichi, True)
Ejemplo n.º 5
0
    def test_discard_tile(self):
        client = Client()
        tiles = [1, 22, 3, 4, 43, 6, 7, 8, 9, 55, 11, 12, 13, 99]
        client.table.init_main_player_hand(tiles)
        self.assertEqual(len(client.table.get_main_player().tiles), 14)

        tile = client.discard_tile()

        self.assertEqual(len(client.table.get_main_player().tiles), 13)
        self.assertEqual(len(client.table.get_main_player().discards), 1)
        self.assertFalse(tile in client.table.get_main_player().tiles)
Ejemplo n.º 6
0
    def test_draw_tile(self):
        client = Client()
        tiles = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
        client.table.init_round(0, 0, 0, 0, 0, [0, 0, 0, 0])
        client.table.init_main_player_hand(tiles)
        self.assertEqual(len(client.table.get_main_player().tiles), 13)
        self.assertEqual(client.table.count_of_remaining_tiles, 70)

        client.draw_tile(14)

        self.assertEqual(len(client.table.get_main_player().tiles), 14)
        self.assertEqual(client.table.count_of_remaining_tiles, 69)
Ejemplo n.º 7
0
    def test_call_meld(self):
        client = Client()

        client.table.init_round(0, 0, 0, 0, 0, [0, 0, 0, 0])
        self.assertEqual(client.table.count_of_remaining_tiles, 70)

        meld = Meld()
        meld.who = 3

        client.call_meld(meld)

        self.assertEqual(len(client.table.get_player(3).melds), 1)
        self.assertEqual(client.table.count_of_remaining_tiles, 71)
Ejemplo n.º 8
0
    def test_init_dealer(self):
        clients = [Client() for _ in range(0, 4)]
        manager = GameManager(clients)
        manager.set_dealer(0)
        manager.init_round()

        self.assertTrue(manager.clients[0].player.is_dealer)
        self.assertFalse(manager.clients[1].player.is_dealer)
        self.assertFalse(manager.clients[2].player.is_dealer)
        self.assertFalse(manager.clients[3].player.is_dealer)

        manager.set_dealer(1)
        manager.init_round()

        self.assertTrue(manager.clients[1].player.is_dealer)
        self.assertFalse(manager.clients[0].player.is_dealer)
        self.assertFalse(manager.clients[2].player.is_dealer)
        self.assertFalse(manager.clients[3].player.is_dealer)

        manager.set_dealer(2)
        manager.init_round()

        self.assertTrue(manager.clients[2].player.is_dealer)
        self.assertFalse(manager.clients[0].player.is_dealer)
        self.assertFalse(manager.clients[1].player.is_dealer)
        self.assertFalse(manager.clients[3].player.is_dealer)

        manager.set_dealer(3)
        manager.init_round()

        self.assertTrue(manager.clients[3].player.is_dealer)
        self.assertFalse(manager.clients[0].player.is_dealer)
        self.assertFalse(manager.clients[1].player.is_dealer)
        self.assertFalse(manager.clients[2].player.is_dealer)
Ejemplo n.º 9
0
    def test_scores_calculations_after_retake(self):
        clients = [Client() for _ in range(0, 4)]
        manager = GameManager(clients)
        manager.init_game()
        manager.init_round()

        manager.process_the_end_of_the_round(None, None, None, None, False)

        self.assertEqual(clients[0].player.scores, 25000)
        self.assertEqual(clients[1].player.scores, 25000)
        self.assertEqual(clients[2].player.scores, 25000)
        self.assertEqual(clients[3].player.scores, 25000)

        clients[0].player.in_tempai = True
        manager.process_the_end_of_the_round(None, None, None, None, False)

        self.assertEqual(clients[0].player.scores, 28000)
        self.assertEqual(clients[1].player.scores, 24000)
        self.assertEqual(clients[2].player.scores, 24000)
        self.assertEqual(clients[3].player.scores, 24000)

        for client in clients:
            client.player.scores = 25000

        clients[0].player.in_tempai = True
        clients[1].player.in_tempai = True
        manager.process_the_end_of_the_round(None, None, None, None, False)

        self.assertEqual(clients[0].player.scores, 26500)
        self.assertEqual(clients[1].player.scores, 26500)
        self.assertEqual(clients[2].player.scores, 23500)
        self.assertEqual(clients[3].player.scores, 23500)

        for client in clients:
            client.player.scores = 25000

        clients[0].player.in_tempai = True
        clients[1].player.in_tempai = True
        clients[2].player.in_tempai = True
        manager.process_the_end_of_the_round(None, None, None, None, False)

        self.assertEqual(clients[0].player.scores, 26000)
        self.assertEqual(clients[1].player.scores, 26000)
        self.assertEqual(clients[2].player.scores, 26000)
        self.assertEqual(clients[3].player.scores, 22000)

        for client in clients:
            client.player.scores = 25000

        clients[0].player.in_tempai = True
        clients[1].player.in_tempai = True
        clients[2].player.in_tempai = True
        clients[3].player.in_tempai = True
        manager.process_the_end_of_the_round(None, None, None, None, False)

        self.assertEqual(clients[0].player.scores, 25000)
        self.assertEqual(clients[1].player.scores, 25000)
        self.assertEqual(clients[2].player.scores, 25000)
        self.assertEqual(clients[3].player.scores, 25000)
Ejemplo n.º 10
0
    def test_enemy_discard(self):
        client = Client()
        client.table.init_round(0, 0, 0, 0, 0, [0, 0, 0, 0])

        self.assertEqual(client.table.count_of_remaining_tiles, 70)

        client.table.add_discarded_tile(1, 10, False)

        self.assertEqual(client.table.count_of_remaining_tiles, 69)
Ejemplo n.º 11
0
    def test_is_game_end_by_negative_scores(self):
        clients = [Client() for _ in range(0, 4)]
        manager = GameManager(clients)
        manager.set_dealer(0)
        manager.init_round()

        winner = clients[0]
        loser = clients[1]
        loser.player.scores = 500

        result = manager.process_the_end_of_the_round(list(range(0, 14)), 0,
                                                      winner, loser, False)
        self.assertEqual(loser.player.scores, -500)
        self.assertEqual(result['is_game_end'], True)
Ejemplo n.º 12
0
    def test_win_by_tsumo_and_scores_calculation(self):
        clients = [Client() for _ in range(0, 4)]
        manager = GameManager(clients)
        manager.init_game()
        manager.init_round()
        manager.riichi_sticks = 1

        winner = clients[0]
        manager.process_the_end_of_the_round(list(range(0, 14)), 0, winner,
                                             None, True)

        self.assertEqual(winner.player.scores, 26900)
        self.assertEqual(clients[1].player.scores, 24700)
        self.assertEqual(clients[2].player.scores, 24700)
        self.assertEqual(clients[3].player.scores, 24700)
Ejemplo n.º 13
0
    def test_play_round_with_retake(self):
        game.game_manager.shuffle_seed = lambda: 0.01

        clients = [Client() for _ in range(0, 4)]
        manager = GameManager(clients)
        manager.init_game()
        manager.set_dealer(3)
        manager.init_round()

        result = manager.play_round()

        self.assertEqual(manager.round_number, 1)
        self.assertEqual(result['is_tsumo'], False)
        self.assertEqual(result['is_game_end'], False)
        self.assertEqual(result['winner'], None)
        self.assertEqual(result['loser'], None)
Ejemplo n.º 14
0
    def test_discard_tile(self):
        client = Client()

        client.table.init_round(0, 0, 0, 0, 0, [0, 0, 0, 0])
        tiles = [1, 22, 3, 4, 43, 6, 7, 8, 9, 55, 11, 12, 13, 99]
        client.table.player.init_hand(tiles)

        self.assertEqual(len(client.table.player.tiles), 14)
        self.assertEqual(client.table.count_of_remaining_tiles, 70)

        tile = client.player.discard_tile()

        self.assertEqual(len(client.table.player.tiles), 13)
        self.assertEqual(len(client.table.player.discards), 1)
        self.assertFalse(tile in client.table.player.tiles)
        self.assertEqual(client.table.count_of_remaining_tiles, 69)
Ejemplo n.º 15
0
    def test_init_round(self):
        clients = [Client() for _ in range(0, 4)]
        manager = GameManager(clients)
        manager.init_game()
        manager.init_round()

        self.assertEqual(len(manager.dead_wall), 14)
        self.assertEqual(len(manager.dora_indicators), 1)
        self.assertIsNotNone(manager.current_client)
        self.assertEqual(manager.round_number, 0)
        self.assertEqual(manager.honba_sticks, 0)
        self.assertEqual(manager.riichi_sticks, 0)
        self.assertEqual([i.player.scores for i in manager.clients],
                         [25000, 25000, 25000, 25000])

        for client in clients:
            self.assertEqual(len(client.player.tiles), 13)

        self.assertEqual(len(manager.tiles), 70)
Ejemplo n.º 16
0
    def test_call_meld(self):
        client = Client()

        client.table.init_round(0, 0, 0, 0, 0, [0, 0, 0, 0])
        self.assertEqual(client.table.count_of_remaining_tiles, 70)

        meld = Meld()
        client.table.add_called_meld(0, meld)

        self.assertEqual(len(client.player.melds), 1)
        self.assertEqual(client.table.count_of_remaining_tiles, 71)

        client.player.tiles = [0]
        meld = Meld()
        meld.type = Meld.KAN
        meld.called_tile = 0
        client.table.add_called_meld(0, meld)

        self.assertEqual(len(client.player.melds), 2)
        # +1 for called meld
        # -1 for called kan
        self.assertEqual(client.table.count_of_remaining_tiles, 71)
Ejemplo n.º 17
0
    def test_win_by_ron_and_scores_calculation(self):
        clients = [Client() for _ in range(0, 4)]
        manager = GameManager(clients)
        manager.init_game()
        manager.init_round()

        winner = clients[0]
        loser = clients[1]

        # only 1000 hand
        manager.process_the_end_of_the_round(list(range(0, 14)), 0, winner,
                                             loser, False)
        self.assertEqual(winner.player.scores, 26000)
        self.assertEqual(loser.player.scores, 24000)

        winner.player.scores = 25000
        winner.player.dealer_seat = 1
        loser.player.scores = 25000
        manager.riichi_sticks = 2
        manager.honba_sticks = 2

        manager.process_the_end_of_the_round(list(range(0, 14)), 0, winner,
                                             loser, False)
        self.assertEqual(winner.player.scores, 28600)
        self.assertEqual(loser.player.scores, 23400)
        self.assertEqual(manager.riichi_sticks, 0)
        self.assertEqual(manager.honba_sticks, 0)

        winner.player.scores = 25000
        winner.player.dealer_seat = 0
        loser.player.scores = 25000
        manager.honba_sticks = 2

        # if dealer won we need to increment honba sticks
        manager.process_the_end_of_the_round(list(range(0, 14)), 0, winner,
                                             loser, False)
        self.assertEqual(winner.player.scores, 26600)
        self.assertEqual(loser.player.scores, 23400)
        self.assertEqual(manager.honba_sticks, 3)
Ejemplo n.º 18
0
    def test_is_game_end_by_eight_winds(self):
        clients = [Client() for _ in range(0, 4)]

        current_dealer = 0
        manager = GameManager(clients)
        manager.init_game()
        manager.set_dealer(current_dealer)
        manager.init_round()
        manager._unique_dealers = 1

        for x in range(0, 7):
            # to avoid honba
            client = current_dealer == 0 and 1 or 0

            result = manager.process_the_end_of_the_round(
                list(range(0, 14)), 0, clients[client], None, True)
            self.assertEqual(result['is_game_end'], False)
            self.assertNotEqual(manager.dealer, current_dealer)
            current_dealer = manager.dealer

        result = manager.process_the_end_of_the_round(list(range(0, 14)), 0,
                                                      clients[0], None, True)
        self.assertEqual(result['is_game_end'], True)
Ejemplo n.º 19
0
    def test_init_scores_and_recalculate_position(self):
        clients = [Client() for _ in range(0, 4)]
        manager = GameManager(clients)
        manager.init_game()
        manager.set_dealer(3)

        clients[0].player.scores = 24000
        clients[1].player.scores = 23000
        clients[2].player.scores = 22000
        clients[3].player.scores = 21000

        manager.recalculate_players_position()

        self.assertEqual(clients[0].player.scores, 24000)
        self.assertEqual(clients[0].player.position, 1)
        self.assertEqual(clients[1].player.scores, 23000)
        self.assertEqual(clients[1].player.position, 2)
        self.assertEqual(clients[2].player.scores, 22000)
        self.assertEqual(clients[2].player.position, 3)
        self.assertEqual(clients[3].player.scores, 21000)
        self.assertEqual(clients[3].player.position, 4)

        clients[0].player.scores = 24000
        clients[1].player.scores = 24000
        clients[2].player.scores = 22000
        clients[3].player.scores = 22000

        manager.recalculate_players_position()

        self.assertEqual(clients[0].player.scores, 24000)
        self.assertEqual(clients[0].player.position, 1)
        self.assertEqual(clients[1].player.scores, 24000)
        self.assertEqual(clients[1].player.position, 2)
        self.assertEqual(clients[2].player.scores, 22000)
        self.assertEqual(clients[2].player.position, 3)
        self.assertEqual(clients[3].player.scores, 22000)
        self.assertEqual(clients[3].player.position, 4)
Ejemplo n.º 20
0
    def test_retake_and_honba_increment(self):
        clients = [Client() for _ in range(0, 4)]
        manager = GameManager(clients)
        manager.init_game()
        manager.init_round()

        # no one in tempai, so honba stick should be added
        manager.process_the_end_of_the_round(None, None, None, None, False)
        self.assertEqual(manager.honba_sticks, 1)

        manager.honba_sticks = 0
        manager.set_dealer(0)
        clients[0].player.in_tempai = False
        clients[1].player.in_tempai = True

        # dealer NOT in tempai, no honba
        manager.process_the_end_of_the_round(None, None, None, None, False)
        self.assertEqual(manager.honba_sticks, 0)

        clients[0].player.in_tempai = True

        # dealer in tempai, so honba stick should be added
        manager.process_the_end_of_the_round(None, None, None, None, False)
        self.assertEqual(manager.honba_sticks, 1)
Ejemplo n.º 21
0
    def test_change_dealer_after_end_of_the_round(self):
        clients = [Client() for _ in range(0, 4)]
        manager = GameManager(clients)
        manager.set_dealer(0)
        manager.init_round()

        # retake. dealer is NOT in tempai, let's move a dealer position
        manager.process_the_end_of_the_round(list(range(0, 14)), None, None,
                                             None, False)
        self.assertEqual(manager.dealer, 1)

        # retake. dealer is in tempai, don't move a dealer position
        clients[1].player.in_tempai = True
        manager.process_the_end_of_the_round(list(range(0, 14)), 0, None, None,
                                             False)
        self.assertEqual(manager.dealer, 1)

        # dealer win by ron, don't move a dealer position
        manager.process_the_end_of_the_round(list(range(0, 14)), 0, None, None,
                                             False)
        self.assertEqual(manager.dealer, 1)

        # dealer win by tsumo, don't move a dealer position
        manager.process_the_end_of_the_round(list(range(0, 14)), 0, None, None,
                                             False)
        self.assertEqual(manager.dealer, 1)

        # NOT dealer win by ron, let's move a dealer position
        manager.process_the_end_of_the_round(list(range(0, 14)), 0, clients[3],
                                             clients[2], False)
        self.assertEqual(manager.dealer, 2)

        # NOT dealer win by tsumo, let's move a dealer position
        manager.process_the_end_of_the_round(list(range(0, 14)), 0, clients[1],
                                             None, True)
        self.assertEqual(manager.dealer, 3)
Ejemplo n.º 22
0
    def test_init_game(self):
        clients = [Client() for _ in range(0, 4)]
        manager = GameManager(clients)
        manager.init_game()

        self.assertTrue(manager.dealer in [0, 1, 2, 3])