示例#1
0
    def test_is_equal(self):
        board1 = FishBoard(4, 3)
        board1 = board1.create_hole(2, 0)
        board1 = board1.create_hole(3, 0)
        board1 = board1.create_hole(2, 1)
        board1 = board1.create_hole(0, 1)

        board2 = FishBoard(4, 3)
        board2 = board2.create_hole(2, 0)
        board2 = board2.create_hole(3, 0)
        board2 = board2.create_hole(2, 1)
        board2 = board2.create_hole(0, 1)

        factory1 = FishGameState(board=board1,
                                 num_players=3,
                                 players=TestGameState.player_list,
                                 phase=GameStatePhase.INITIAL,
                                 current_player=TestGameState.player_list[0])
        factory1 = factory1.add_penguin(0, 0, "red")
        factory1 = factory1.add_penguin(1, 0, "white")

        factory2 = FishGameState(board=board2,
                                 num_players=3,
                                 players=TestGameState.player_list,
                                 phase=GameStatePhase.INITIAL,
                                 current_player=TestGameState.player_list[0])
        factory2 = factory2.add_penguin(0, 0, "red")
        factory2 = factory2.add_penguin(1, 0, "white")

        state1 = factory1.finalize()
        state2 = factory2.finalize()

        self.assertTrue(state1.is_equal(state2))
示例#2
0
 def test_any_player_can_move_success(self):
     board = FishBoard(4, 3)
     factory = FishGameState(board=board,
                             num_players=3,
                             players=TestGameState.player_list,
                             phase=GameStatePhase.INITIAL,
                             current_player=TestGameState.player_list[0])
     factory = factory.add_penguin(0, 0, "red")
     factory = factory.add_penguin(1, 1, "white")
     game_state = factory.finalize()
     self.assertTrue(game_state.check_any_player_can_move())
示例#3
0
 def test_move_penguin_failure(self):
     board = FishBoard(4, 3)
     factory = FishGameState(board=board,
                             num_players=3,
                             players=TestGameState.player_list,
                             phase=GameStatePhase.INITIAL,
                             current_player=TestGameState.player_list[0])
     factory = factory.add_penguin(row=0, col=0, color="red")
     factory = factory.add_penguin(row=0, col=1, color="white")
     factory = factory.add_penguin(row=0, col=2, color="brown")
     game_state = factory.finalize()
     with self.assertRaises(ValueError):
         game_state.move_penguin("red", 0, 0, 0, 2)
示例#4
0
 def test_any_player_can_move_failure(self):
     board = FishBoard(4, 3)
     board = board.create_hole(2, 0)
     board = board.create_hole(3, 0)
     board = board.create_hole(2, 1)
     board = board.create_hole(0, 1)
     factory = FishGameState(board=board,
                             num_players=3,
                             players=TestGameState.player_list,
                             phase=GameStatePhase.INITIAL,
                             current_player=TestGameState.player_list[0])
     factory = factory.add_penguin(0, 0, "red")
     factory = factory.add_penguin(1, 0, "white")
     game_state = factory.finalize()
     self.assertFalse(game_state.check_any_player_can_move())
示例#5
0
    def test_move_penguin(self):
        board = FishBoard(4, 3)
        factory = FishGameState(board=board,
                                num_players=3,
                                players=TestGameState.player_list,
                                phase=GameStatePhase.INITIAL,
                                current_player=TestGameState.player_list[0])
        factory = factory.add_penguin(row=0, col=1, color="red")
        factory = factory.add_penguin(row=0, col=0, color="white")
        factory = factory.add_penguin(row=3, col=0, color="brown")

        game_state = factory.finalize()
        game_state = game_state.move_penguin("red", 0, 1, 2, 1)
        expected_penguins = [Coordinate(row=2, col=1)]
        self.assertEqual(game_state.players["red"].penguins, expected_penguins)
示例#6
0
    def test_get_player_id_success(self):
        board = FishBoard(4, 3)
        board = board.create_hole(2, 0)
        board = board.create_hole(3, 0)
        board = board.create_hole(2, 1)
        board = board.create_hole(0, 1)
        factory = FishGameState(board=board,
                                num_players=3,
                                players=TestGameState.player_list,
                                phase=GameStatePhase.INITIAL,
                                current_player=TestGameState.player_list[0])
        factory = factory.add_penguin(0, 0, "red")
        factory = factory.add_penguin(1, 0, "white")

        game_state = factory.finalize()
        self.assertEqual(game_state.get_player_color(0, 0), "red")
        self.assertEqual(game_state.get_player_color(3, 2), "")
 def setup():
     test_board = FishBoard(4, 3)
     player_1 = Player("red", 0, 0, [])
     player_2 = Player("white", 0, 0, [])
     test_players = [player_1, player_2]
     factory = FishGameState(board=test_board,
                             players=test_players,
                             phase=GameStatePhase.INITIAL,
                             num_players=len(test_players),
                             current_player=test_players[0])
     factory = factory.add_penguin(0, 0, "red")
     factory = factory.add_penguin(0, 2, "white")
     factory = factory.add_penguin(1, 0, "red")
     factory = factory.add_penguin(1, 2, "white")
     factory = factory.add_penguin(2, 0, "red")
     factory = factory.add_penguin(2, 2, "white")
     factory = factory.add_penguin(3, 0, "red")
     factory = factory.add_penguin(3, 2, "white")
     return factory.finalize(), factory.board, factory.players
示例#8
0
    def setup():
        test_board = FishBoard(4, 3)
        player_1 = Player("red", 0, 0, [])
        player_2 = Player("white", 0, 0, [])
        test_players = [player_1, player_2]
        state = FishGameState(board=test_board,
                              num_players=len(test_players),
                              players=test_players,
                              current_player=player_1,
                              phase=GameStatePhase.INITIAL)
        state = state.add_penguin(0, 0, "red") \
            .add_penguin(0, 2, "white") \
            .add_penguin(0, 1, "red") \
            .add_penguin(1, 2, "white") \
            .add_penguin(2, 0, "red") \
            .add_penguin(2, 2, "white") \
            .add_penguin(3, 0, "red") \
            .add_penguin(3, 2, "white")

        return state.finalize(), state.board, state.players