def test_distance_for_dimension_6(self): """Check the 4 distances on an 6-dimensional chess board""" queen = Queen(4, 4) right, left, above, below = queen.get_distance_for_dimension( dimension=6) self.assertEqual(right, 2) self.assertEqual(left, 3) self.assertEqual(above, 2) self.assertEqual(below, 3)
def test_count_valid_squares_in_1x1(self): """Test for count valid squares in 1x1 chess board""" game = ChessBoardGame(dimension=1) queen = Queen(1, 1) obstacles = [] self.assertEquals( game.count_valid_squares(queen=queen, obstacles=obstacles), 0)
def test_count_valid_squares_in_5x5_with_3_obstacles(self): """Test for count valid squares in 5x5 chess board, with obstacles""" game = ChessBoardGame(dimension=5) queen = Queen(4, 3) obstacles = [Obstacle(5, 5), Obstacle(4, 2), Obstacle(2, 3)] self.assertEquals( game.count_valid_squares(queen=queen, obstacles=obstacles), 10)
def test_count_valid_squares_in_4x4(self): """Test for count valid squares in 4x4 chess board""" game = ChessBoardGame(dimension=4) queen = Queen(4, 4) obstacles = [] self.assertEquals( game.count_valid_squares(queen=queen, obstacles=obstacles), 9)
def test_count_valid_squares_in_8x8_with_1_obstacle(self): """Test for count valid squares in 8x8 chess board, with obstacles""" game = ChessBoardGame(dimension=8) queen = Queen(4, 4) obstacles = [Obstacle(3, 5)] self.assertEquals( game.count_valid_squares(queen=queen, obstacles=obstacles), 24)
def queensAttack(n, k, r_q, c_q, obstacles): """ Determine how many squares the queen can attack Args: n : The number of rows and columns in the board k : The number of obstacles on the board r_q : The row number of the queen's position c_q : The column number of the queen's position obstacles : A list where each element is an array of 2 integers, the row and column of an obstacle Returns: The numbers os squares that the queen can attack from position (r_q, c_q) Raises: ValueError: Validation. """ if n <= 0 or n > 10**5: raise ValueError('Board dimensions are not valid') if k < 0 or k > 10 ^ 5: raise ValueError('The number of obstacles is not valid') if [r_q, c_q] in obstacles: raise ValueError( 'There can be no obstacle in the position where the queen is') queen = Queen(row=r_q, column=c_q) game = ChessBoardGame(dimension=n) obs = [Obstacle(row=obs[0], column=obs[1]) for obs in obstacles] return game.count_valid_squares(queen=queen, obstacles=obs)
def test_diff_with_queen(self): """Check the method to get the distance between the queen and an obstacle""" queen = Queen(1, 4) obstacle_1 = Obstacle(4, 1) obstacle_2 = Obstacle(4, 4) row, column = obstacle_1.get_diff_with_queen(queen=queen) self.assertEqual(row, 3) self.assertEqual(column, -3) row, column = obstacle_2.get_diff_with_queen(queen=queen) self.assertEqual(row, 0) self.assertEqual(column, -3)