Beispiel #1
0
 def test_create_state_too_little_players(self):
     """
     Purpose: Test creating a state with only 1 player
     """
     with self.assertRaises(ValueError):
         FishGameStateFactory.create_place_penguins_state(
             CreateStateTest.test_board, [(PlayerColor.RED, [])])
Beispiel #2
0
 def test_create_move_state_no_pengs(self):
     """
     Purpose: Test creating a penguin movement state with no penguins throws error
     Signature: Void -> Void
     """
     with self.assertRaises(ValueError):
         FishGameStateFactory.create_move_penguins_state(
             CreateStateTest.test_board, [(PlayerColor.RED, [], 0),
                                          (PlayerColor.BROWN, [], 0)])
Beispiel #3
0
 def test_create_placement_state_bad_penguin_amount(self):
     """
     Purpose: Test creating a penguin placement state with having the older player having penguins placed already
     Signature: Void -> Void
     """
     with self.assertRaises(ValueError):
         FishGameStateFactory.create_place_penguins_state(
             CreateStateTest.test_board, [(PlayerColor.RED, []),
                                          (PlayerColor.BROWN, [(0, 0)])])
Beispiel #4
0
 def test_create_end_state_not_end(self):
     """
     Purpose: Test creating a penguin end state where it is not in an end state
     Signature: Void -> Void
     """
     with self.assertRaises(ValueError):
         FishGameStateFactory.create_end_game_state(
             CreateStateTest.test_board,
             [(PlayerColor.RED, CreateStateTest.test_board_valid_col1, 0),
              (PlayerColor.BROWN, CreateStateTest.test_board_valid_col2, 0)
              ])
Beispiel #5
0
 def test_create_move_state_same_place(self):
     """
     Purpose: Test creating a penguin movement state with trying to put penguins in the same place
     Signature: Void -> Void
     """
     with self.assertRaises(PenguinPlacementError):
         valid_posns = [(0, 0), (0, 2), (1, 1), (1, 3)]
         FishGameStateFactory.create_move_penguins_state(
             CreateStateTest.test_board,
             [(PlayerColor.RED, CreateStateTest.test_board_valid_col1, 0),
              (PlayerColor.BROWN, CreateStateTest.test_board_valid_col1, 0)
              ])
Beispiel #6
0
 def test_create_placement_state_bad_player_amount(self):
     """
     Purpose: Test creating a penguin placement state with too many players
     Signature: Void -> Void
     """
     with self.assertRaises(ValueError):
         FishGameStateFactory.create_place_penguins_state(
             CreateStateTest.test_board, [(PlayerColor.RED, []),
                                          (PlayerColor.BROWN, []),
                                          (PlayerColor.WHITE, []),
                                          (PlayerColor.BLACK, []),
                                          (PlayerColor.RED, [])])
Beispiel #7
0
 def test_create_placement_state_no_penguins(self):
     """
     Purpose: Test creating a penguin placement state with no penguins
     Signature: Void -> Void
     """
     game_state = FishGameStateFactory.create_place_penguins_state(
         CreateStateTest.test_board, [(PlayerColor.RED, []),
                                      (PlayerColor.BROWN, [])])
     self.assertEqual(GamePhase.PLACE_PENGUINS, game_state.get_game_phase())
     self.assertEqual(2, len(game_state.get_player_order()))
Beispiel #8
0
 def test_create_end_state_end(self):
     """
     Purpose: Test creating a penguin end state
     Signature: Void -> Void
     """
     small_board = FishBoardModel.create_with_same_fish_amount(4, 2, 3)
     game_state = FishGameStateFactory.create_end_game_state(
         small_board,
         [(PlayerColor.RED, CreateStateTest.test_board_valid_col1, 0),
          (PlayerColor.BROWN, CreateStateTest.test_board_valid_col2, 5)])
     self.assertEqual(GamePhase.END_GAME, game_state.get_game_phase())
 def test_basic_placement(self):
     """
     Test getting basic placement from this player.
     """
     test_board = FishBoardModel.create_with_same_fish_amount(4, 3, 3)
     test_state = FishGameStateFactory.create_place_penguins_state(test_board,
                                                                   [(PlayerColor.RED, []),
                                                                   (PlayerColor.WHITE, [])])
     player = BasicPlayer()
     placement = player.player_place_penguin(test_state)
     self.assertEqual((0, 0), placement)
Beispiel #10
0
 def test_create_initial_state_rows_cols(self):
     """
     Purpose: Test using convenience method to create board state
     Signature: Void -> Void
     """
     game_state = FishGameStateFactory.create_game_state_with_dimensions(
         4, 3, [PlayerColor.RED, PlayerColor.BROWN])
     self.assertEqual([PlayerColor.RED, PlayerColor.BROWN],
                      game_state.get_player_order())
     self.assertEqual(PlayerColor.RED, game_state.get_current_turn())
     self.assertEqual(GamePhase.PLACE_PENGUINS, game_state.get_game_phase())
 def test_remove_invalid_color_from_game(self):
     """
     Purpose: Tests the remove invalid color from game function when an invalid color (not in the game) is removed.
     Signature: Void -> Void
     """
     game_state = FishGameStateFactory.create_place_penguins_state(
         GameStateTest.test_board, [(PlayerColor.BLACK, []),
                                    (PlayerColor.BROWN, [])])
     # check if color is not in game
     with self.assertRaises(ValueError):
         game_state.remove_color_from_game(PlayerColor.RED)
    def test_check_penguin_amount(self):
        """
        Purpose: Test the check penguin's amount function with valid and invalid arguments
        Signature: Void -> Void
        """
        game_state = FishGameStateFactory.create_place_penguins_state(
            GameStateTest.test_board, [(PlayerColor.BLACK, []),
                                       (PlayerColor.BROWN, [])])
        # Situation where not all penguins placed
        with self.assertRaises(ValueError):
            game_state.check_penguin_amount(
                2, {
                    PlayerColor.BLACK:
                    game_state.get_penguins_for_player(PlayerColor.BLACK),
                    PlayerColor.BROWN:
                    game_state.get_penguins_for_player(PlayerColor.BROWN)
                }, True)

        # Situation where not all penguins placed but not needed
        game_state.check_penguin_amount(
            2, {
                PlayerColor.BLACK:
                game_state.get_penguins_for_player(PlayerColor.BLACK),
                PlayerColor.BROWN:
                game_state.get_penguins_for_player(PlayerColor.BROWN)
            }, False)

        # Situation where all penguins placed
        game_state.set_turn(PlayerColor.BROWN)
        game_state.place_penguin(PlayerColor.BROWN, (0, 0),
                                 increase_turn=False)
        game_state.place_penguin(PlayerColor.BROWN, (1, 1),
                                 increase_turn=False)
        game_state.place_penguin(PlayerColor.BROWN, (0, 2),
                                 increase_turn=False)
        game_state.place_penguin(PlayerColor.BROWN, (2, 0),
                                 increase_turn=False)

        game_state.set_turn(PlayerColor.BLACK)
        game_state.place_penguin(PlayerColor.BLACK, (2, 2),
                                 increase_turn=False)
        game_state.place_penguin(PlayerColor.BLACK, (3, 3),
                                 increase_turn=False)
        game_state.place_penguin(PlayerColor.BLACK, (3, 1),
                                 increase_turn=False)
        game_state.place_penguin(PlayerColor.BLACK, (1, 3),
                                 increase_turn=False)
        game_state.check_penguin_amount(
            2, {
                PlayerColor.BLACK:
                game_state.get_penguins_for_player(PlayerColor.BLACK),
                PlayerColor.BROWN:
                game_state.get_penguins_for_player(PlayerColor.BROWN)
            }, True)
Beispiel #13
0
 def test_not_move_state(self):
     """
     Purpose: Test trying to create a tree from a state that is not
              the player movement state
     """
     with self.assertRaises(ValueError):
         small_board = FishBoardModel.create_with_same_fish_amount(4, 3, 3)
         game_state = FishGameStateFactory.create_place_penguins_state(
             small_board, [(PlayerColor.RED, []), (PlayerColor.BLACK, [])]
         )
         FishGameTree(game_state)
    def test_if_players_can_move(self):
        """
        Purpose: Test the state if a player can't move, if 1 player can move, and where more than one player can move.
        Signature: Void -> Void
        """
        test_board = FishBoardModel.create_with_same_fish_amount(4, 3, 3)
        game_state = FishGameStateFactory.create_place_penguins_state(
            test_board, [(PlayerColor.BLACK, []), (PlayerColor.BROWN, [])])
        game_state.place_penguin(PlayerColor.BLACK, (0, 0))
        game_state.place_penguin(PlayerColor.BROWN, (1, 1))
        self.assertEqual(True, game_state.can_any_player_move())

        # Remove tiles
        test_board.remove_tile(2, 2)
        test_board.remove_tile(2, 0)
        test_board.remove_tile(0, 2)
        test_board.remove_tile(1, 3)
        game_state_holes = FishGameStateFactory.create_place_penguins_state(
            test_board, [(PlayerColor.BLACK, [(0, 0)]),
                         (PlayerColor.BROWN, [(1, 1)])])
        self.assertEqual(False, game_state_holes.can_any_player_move())
Beispiel #15
0
 def test_create_placement_state_one_less(self):
     """
     Purpose: Test creating a penguin placement state with second penguin in order having one less penguin
     Signature: Void -> Void
     """
     game_state = FishGameStateFactory.create_place_penguins_state(
         CreateStateTest.test_board, [(PlayerColor.BROWN, [(0, 0)]),
                                      (PlayerColor.RED, [])])
     self.assertEqual(GamePhase.PLACE_PENGUINS, game_state.get_game_phase())
     self.assertEqual(2, len(game_state.get_player_order()))
     self.assertEqual([(0, 0)],
                      game_state.get_penguins_for_player(PlayerColor.BROWN))
 def test_placing_penguin_valid(self):
     """
     Purpose: Test what happens when you place a penguin in a valid tile on the board.
     Signature: Void -> Void
     """
     test_board_hole = FishBoardModel.create_with_same_fish_amount(4, 3, 3)
     test_board_hole.remove_tile(0, 0)
     game_state = FishGameStateFactory.create_place_penguins_state(
         test_board_hole, [(PlayerColor.BLACK, []),
                           (PlayerColor.BROWN, [])])
     game_state.place_penguin(PlayerColor.BLACK, (1, 1))
     game_state.place_penguin(PlayerColor.BROWN, (2, 2))
     game_state.place_penguin(PlayerColor.BLACK, (3, 3))
 def test_get_fish(self):
     """
     Purpose: Test getting a player's fish before and after they move on a board
     Signature: Void -> Void
     """
     small_board = FishBoardModel.create_with_same_fish_amount(4, 5, 3)
     game_state = FishGameStateFactory.create_move_penguins_state(
         small_board,
         [(PlayerColor.BROWN, GameStateTest.test_board_valid_col2, 5),
          (PlayerColor.BLACK, GameStateTest.test_board_valid_col1, 0)])
     self.assertEqual(5, game_state.get_fish_for_player(PlayerColor.BROWN))
     # Valid move from penguin at 3,3 to 4,2
     game_state.move_penguin(PlayerColor.BROWN, (3, 3), (4, 2))
     self.assertEqual(8, game_state.get_fish_for_player(PlayerColor.BROWN))
Beispiel #18
0
 def test_create_move_state_valid(self):
     """
     Purpose: Test creating a penguin movement state with correct amount of penguins
     Signature: Void -> Void
     """
     small_board = FishBoardModel.create_with_same_fish_amount(4, 5, 3)
     game_state = FishGameStateFactory.create_move_penguins_state(
         small_board,
         [(PlayerColor.RED, CreateStateTest.test_board_valid_col1, 0),
          (PlayerColor.BROWN, CreateStateTest.test_board_valid_col2, 5)])
     self.assertEqual(
         4, len(game_state.get_penguins_for_player(PlayerColor.RED)))
     self.assertEqual(
         4, len(game_state.get_penguins_for_player(PlayerColor.BROWN)))
 def test_remove_color_from_game_next_player(self):
     """
     Purpose: Tests removing a color from the game, checks to see if the current turn will shift to be the next player's
     turn once the color is removed
     Signature: Void -> Void
     """
     game_state = FishGameStateFactory.create_place_penguins_state(
         GameStateTest.test_board, [(PlayerColor.BLACK, []),
                                    (PlayerColor.BROWN, [])])
     turn_before = game_state.get_current_turn()
     self.assertEqual(PlayerColor.BLACK, turn_before)
     game_state.remove_color_from_game(PlayerColor.BLACK)
     turn_after = game_state.get_current_turn()
     self.assertEqual(PlayerColor.BROWN, turn_after)
 def create_state(state_json):
     """
     Purpose: Create the state_json based on the passed in JSON object representation
     Signature: State -> FishGameState
     :param state_json: Object of players as specified containing ordering and player information
     :return: Our internal representation of a game state_json
     """
     board = TestHarnessTransformationHelper.parse_board(
         state_json['board'])
     player_info_list = TestHarnessTransformationHelper.create_player_info_list(
         state_json['players'])
     game_state = FishGameStateFactory.create_move_penguins_state(
         board, player_info_list, check_penguin_amount=False)
     return game_state
Beispiel #21
0
 def create_small_tree(rows=4, columns=4):
     """
     Purpose: Create a small tree to be used in tests
     Signature: Int Int -> FishGameTree
     :param rows: Amount of rows for the board
     :param columns: Amount of columns for the board
     """
     small_board = FishBoardModel.create_with_same_fish_amount(rows, columns, 3)
     game_state = FishGameStateFactory.create_move_penguins_state(
         small_board, [(PlayerColor.RED, GameTreeTest.penguins_first_player, 5),
                       (PlayerColor.BLACK, GameTreeTest.penguins_second_player, 0)]
     )
     tree_node = FishGameTree(game_state)
     return tree_node
 def test_remove_color_from_game_order(self):
     """
     Purpose: Tests removing a color from a game, then checks if the state's game order has changed once a player color
     is removed from the game.
     Signature: Void -> Void
     """
     # check if removed from order
     game_state = FishGameStateFactory.create_place_penguins_state(
         GameStateTest.test_board, [(PlayerColor.BLACK, []),
                                    (PlayerColor.BROWN, [])])
     order_before = game_state.get_player_order()
     self.assertEqual([PlayerColor.BLACK, PlayerColor.BROWN], order_before)
     game_state.remove_color_from_game(PlayerColor.BLACK)
     order_after = game_state.get_player_order()
     self.assertEqual([PlayerColor.BROWN], order_after)
 def test_add_fish(self):
     """
     Purpose: Test getting a player's fish before and after adding fish to a player
     Signature: Void -> Void
     """
     small_board = FishBoardModel.create_with_same_fish_amount(4, 5, 3)
     game_state = FishGameStateFactory.create_move_penguins_state(
         small_board,
         [(PlayerColor.BLACK, GameStateTest.test_board_valid_col1, 0),
          (PlayerColor.BROWN, GameStateTest.test_board_valid_col2, 5)])
     self.assertEqual(5, game_state.get_fish_for_player(PlayerColor.BROWN))
     game_state.add_fish_to_player(PlayerColor.BROWN, 6)
     self.assertEqual(11, game_state.get_fish_for_player(PlayerColor.BROWN))
     with self.assertRaises(ValueError):
         game_state.add_fish_to_player(PlayerColor.BROWN, -10)
 def test_remove_color_from_game_player_info(self):
     """
     Purpose: Tests removing a color from the game, checks to see if the Player Color would be removed from the players
     in the state
     Signature: Void -> Void
     """
     game_state = FishGameStateFactory.create_place_penguins_state(
         GameStateTest.test_board, [(PlayerColor.BLACK, []),
                                    (PlayerColor.BROWN, [])])
     # check if removed from player info
     game_state.remove_color_from_game(PlayerColor.BROWN)
     brown_not_in_players = PlayerColor.BROWN in game_state._players.keys()
     black_in_players = PlayerColor.BLACK in game_state._players.keys()
     self.assertFalse(brown_not_in_players)
     self.assertTrue(black_in_players)
Beispiel #25
0
 def test_stuck_state(self):
     """
     Purpose: Show generation of children when the current player cannot move
     """
     player_row1 = [(0, 0), (0, 2), (1, 1)]
     player_row2 = [(2, 0), (3, 1), (2, 2)]
     small_board = FishBoardModel.create_with_same_fish_amount(3, 3, 3)
     game_state = FishGameStateFactory.create_move_penguins_state(
         small_board, [(PlayerColor.RED, player_row1, 0),
                       (PlayerColor.BLACK, player_row2, 0)],
         check_penguin_amount=False
     )
     stuck_tree = FishGameTree(game_state)
     self.assertEqual(1, len(list(stuck_tree.generate_direct_children())))
     self.assertEqual(PlayerColor.BLACK, list(stuck_tree.generate_direct_children())[0].get_turn_color())
 def test_moving_penguin_to_invalid_or_existing(self):
     """
     Purpose: Test what happens when you attempt to move a penguin to an invalid spot.
     Signature: Void -> Void
     """
     small_board = FishBoardModel.create_with_same_fish_amount(4, 5, 3)
     game_state = FishGameStateFactory.create_move_penguins_state(
         small_board,
         [(PlayerColor.RED, GameStateTest.test_board_valid_col1, 0),
          (PlayerColor.BROWN, GameStateTest.test_board_valid_col2, 5)])
     # Moving to a valid spot with another penguin on it
     with self.assertRaises(ValueError):
         game_state.move_penguin(PlayerColor.BROWN, (2, 2), (3, 1))
     # Moving to an invalid spot
     with self.assertRaises(ValueError):
         game_state.move_penguin(PlayerColor.BROWN, (2, 2), (4, 0))
 def test_moving_valid_penguin(self):
     """
     Purpose: Test what happens when you attempt to move a penguin to a valid spot.
     Signature: Void -> Void
     """
     small_board = FishBoardModel.create_with_same_fish_amount(4, 5, 3)
     game_state = FishGameStateFactory.create_move_penguins_state(
         small_board,
         [(PlayerColor.RED, GameStateTest.test_board_valid_col1, 0),
          (PlayerColor.BROWN, GameStateTest.test_board_valid_col2, 5)],
         turn=PlayerColor.BROWN)
     # Valid move from penguin at 3,3 to 4,2
     game_state.move_penguin(PlayerColor.BROWN, (3, 3), (4, 2))
     # Tile should be removed now, try going back
     with self.assertRaises(PenguinMovementError):
         game_state.set_turn(PlayerColor.BROWN)
         game_state.move_penguin(PlayerColor.BROWN, (4, 2), (3, 3))
    def test_basic_move(self):
        """
        Test getting a basic move from this player
        """
        board_json = [[1, 1, 1], [2, 3, 4], [1, 1, 1]]
        board = THHelper.parse_board(board_json)
        test_board_valid_row1 = [(0, 0), (2, 0), (4, 0)]
        test_board_valid_row2 = [(1, 1), (3, 1), (5, 1)]
        test_state = FishGameStateFactory.create_move_penguins_state(board,
                                                                     [(PlayerColor.RED, test_board_valid_row1, 0),
                                                                      (PlayerColor.BLACK, test_board_valid_row2, 0)],
                                                                     check_penguin_amount=False,
                                                                     turn=PlayerColor.BLACK)

        player = BasicPlayer()
        placement = player.player_move_penguin(test_state)
        self.assertEqual(((5, 1), (4, 2)), placement)
Beispiel #29
0
 def create_multiple_players(rows=5, columns=5):
     """
     Purpose: Create a larger board with multiple players to be used for testing
     Signature: Int Int -> FishGameTree
     :param rows: Amount of rows for the board
     :param columns: Amount of columns for the board
     """
     small_board = FishBoardModel.create_with_same_fish_amount(rows, columns, 3)
     game_state = FishGameStateFactory.create_move_penguins_state(
         small_board, [(PlayerColor.RED, GameTreeTest.penguins_four_player[1], 0),
                       (PlayerColor.BLACK, GameTreeTest.penguins_four_player[0], 0),
                       (PlayerColor.BROWN, GameTreeTest.penguins_four_player[2], 0),
                       (PlayerColor.WHITE, GameTreeTest.penguins_four_player[3], 0),
                       ]
     )
     tree_node = FishGameTree(game_state)
     return tree_node
    def test_moving_valid_penguin_turns(self):
        """
        Purpose: Test what happens when you move penguins in turn order
        Signature: Void -> Void
        """
        small_board = FishBoardModel.create_with_same_fish_amount(4, 5, 3)
        game_state = FishGameStateFactory.create_move_penguins_state(
            small_board,
            [(PlayerColor.RED, GameStateTest.test_board_valid_col1, 0),
             (PlayerColor.BROWN, GameStateTest.test_board_valid_col3, 5)],
            turn=PlayerColor.BROWN)
        # Valid move from penguin at 3,3 to 4,2
        game_state.move_penguin(PlayerColor.BROWN, (4, 2), (3, 1))
        # Valid move for next turn
        game_state.move_penguin(PlayerColor.RED, (1, 1), (2, 0))

        # attempt to move out of order
        with self.assertRaises(ValueError):
            game_state.move_penguin(PlayerColor.RED, (2, 0), (2, 2))