예제 #1
0
 def test_validate_input_invalid_player_id_upperbound(self):
     board = FishBoard(4, 3)
     game_state = FishGameState(board,
                                3,
                                TestGameState.player_list,
                                current_player=TestGameState.player_list[0],
                                phase=GameStatePhase.FINAL)
     is_valid, error_msg = game_state.validate_input("", 0, 0)
     self.assertFalse(is_valid)
     self.assertEqual(error_msg, "Player color does not exist")
예제 #2
0
 def test_validate_input_true(self):
     board = FishBoard(4, 3)
     game_state = FishGameState(board,
                                3,
                                TestGameState.player_list,
                                current_player=TestGameState.player_list[0],
                                phase=GameStatePhase.FINAL)
     is_valid, error_msg = game_state.validate_input("red", 0, 0)
     self.assertTrue(is_valid)
     self.assertEqual(error_msg, "")
예제 #3
0
 def test_validate_input_invalid_row_and_col_out_of_bounds(self):
     board = FishBoard(4, 3)
     game_state = FishGameState(board,
                                3,
                                TestGameState.player_list,
                                current_player=TestGameState.player_list[0],
                                phase=GameStatePhase.FINAL)
     is_valid, error_msg = game_state.validate_input("red", 6, 6)
     self.assertFalse(is_valid)
     self.assertEqual(error_msg,
                      "Row and column do not exist in this board")
예제 #4
0
 def test_validate_input_invalid_row_and_col_has_penguin(self):
     board = FishBoard(4, 3)
     factory = FishGameState(board=board,
                             num_players=2,
                             players=TestGameState.player_list,
                             phase=GameStatePhase.INITIAL,
                             current_player=TestGameState.player_list[0])
     factory = factory.add_penguin(2, 2, "red")
     is_valid, error_msg = factory.validate_input("white", 2, 2)
     self.assertFalse(is_valid)
     self.assertEqual(error_msg, "This tile already has a penguin")
예제 #5
0
 def test_validate_input_invalid_row_and_col_has_hole(self):
     board = FishBoard(4, 3)
     board = board.create_hole(1, 1)
     game_state = FishGameState(board,
                                3,
                                TestGameState.player_list,
                                current_player=TestGameState.player_list[0],
                                phase=GameStatePhase.FINAL)
     is_valid, error_msg = game_state.validate_input("red", 1, 1)
     self.assertFalse(is_valid)
     self.assertEqual(error_msg, "Row and column is a hole")
예제 #6
0
    def place_penguin(state: FishGameState) -> Coordinate:
        """
        Place a penguin in the next available place in the given state's board according to a zig-zag pattern that begins
        in the top left corner.
        :param state: The state that will have penguins added to it.
        :return: The updated state after adding the penguin in the correct place.
        """
        for r, row in enumerate(state.board.board):
            for c, col in enumerate(row):
                if state.validate_input(state.current_player.color, r, c)[0]:
                    return Coordinate(r, c)

        raise ValueError("No available tiles for penguin placement.")