コード例 #1
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)])
コード例 #2
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)
              ])
コード例 #3
0
 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
コード例 #4
0
 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))
コード例 #5
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)))
コード例 #6
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
コード例 #7
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())
コード例 #8
0
 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)
コード例 #9
0
 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))
コード例 #10
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
コード例 #11
0
    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)
コード例 #12
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))
コード例 #13
0
    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))
コード例 #14
0
 def test_moving_penguin_from_invalid_or_nonexisting(self):
     """
     Purpose: Test what happens when you attempt to move a penguin from an invalid spot
     (No existing penguin, no tile, not on board, or another player's penguin)
     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, 5),
          (PlayerColor.BROWN, GameStateTest.test_board_valid_col2, 0)])
     # No penguin
     with self.assertRaises(PenguinMovementError):
         game_state.move_penguin(PlayerColor.BLACK, (1, 4), (2, 3))
     # Not on board
     with self.assertRaises(PenguinMovementError):
         game_state.move_penguin(PlayerColor.BLACK, (10, 10), (11, 9))
     # Other player's penguin
     with self.assertRaises(PenguinMovementError):
         game_state.move_penguin(PlayerColor.BLACK, (3, 3), (4, 2))