示例#1
0
    def test_get_possible_squares_rook(self):
        """ Test for get_possible_squares("r") """
        game = Game()
        game.board.clear_board()
        game.move_count += 1
        game.board.place_piece("k", "E8")
        game.board.place_piece("K", "C8")
        game.board.place_piece("r", "D1")
        legal_moves = game.get_possible_squares("r", "D1")
        # Rook on empty board on d1
        self.assertEqual(
            legal_moves,
            [[1, 3], [2, 3], [3, 3], [4, 3], [5, 3], [6, 3], [7, 3], [0, 4],
             [0, 5], [0, 6], [0, 7], [0, 2], [0, 1], [0, 0]])
        game.board.set_up_pieces()
        # Black Rook on d1 on starting board
        self.assertEqual(game.get_possible_squares("r", "D1"),
                         [[1, 3], [0, 4], [0, 2]])
        # White Rook on d1 on starting board
        game.move_count += 1
        self.assertEqual(game.get_possible_squares("R", "D1"), None)

        game.board.clear_board()
        game.castling_rights = ["", "", "", ""]
        game.board.place_piece("K", "D2")
        game.board.place_piece("q", "D4")
        game.board.place_piece("R", "D3")
        self.assertEqual(game.get_possible_squares("R", "D3"), [[3, 3]])
示例#2
0
 def test_get_possible_squares_queen(self):
     """ Test for get_possible_squares("k") """
     game = Game()
     game.board.clear_board()
     game.move_count += 1
     game.board.place_piece("k", "E8")
     game.board.place_piece("K", "C8")
     game.board.place_piece("q", "D1")
     legal_moves = game.get_possible_squares("q", "D1")
     # Queen on empty board on d1
     self.assertEqual(
         legal_moves,
         [[1, 3], [2, 3], [3, 3], [4, 3], [5, 3], [6, 3], [7, 3], [1, 4],
          [2, 5], [3, 6], [4, 7], [0, 4], [0, 5], [0, 6], [0, 7], [0, 2],
          [0, 1], [0, 0], [1, 2], [2, 1], [3, 0]])
     game.board.set_up_pieces()
     # Queen on d1 on starting board
     self.assertEqual(game.get_possible_squares("Q", "D1"), None)
     game.board.clear_board()
     game.board.place_piece("K", "D1")
     game.board.place_piece("k", "E8")
     self.assertEqual(
         game.get_possible_squares("q", "D2"),
         [[2, 3], [3, 3], [4, 3], [5, 3], [6, 3], [7, 3], [2, 4], [3, 5],
          [4, 6], [5, 7], [1, 4], [1, 5], [1, 6], [1, 7], [0, 4], [0, 3],
          [0, 2], [1, 2], [1, 1], [1, 0], [2, 2], [3, 1], [4, 0]])
示例#3
0
 def test_get_possible_squares_bishop(self):
     """ Test for get_possible_squares("b") """
     game = Game()
     game.board.clear_board()
     game.move_count += 1
     game.board.place_piece("b", "D1")
     legal_moves = game.get_possible_squares("b", "D1")
     # Bishop on empty board on d1
     self.assertEqual(
         legal_moves,
         [[1, 4], [2, 5], [3, 6], [4, 7], [1, 2], [2, 1], [3, 0]])
     game.board.set_up_pieces()
     # Bishop on d1 on starting board
     self.assertEqual(game.get_possible_squares("B", "D1"), None)
示例#4
0
 def test_get_possible_squares_king(self):
     """ Test for get_possible_squares("k") """
     game = Game()
     game.board.clear_board()
     game.move_count += 1
     game.castling_rights = ["", "", "", ""]
     game.board.place_piece("k", "E1")
     game.board.place_piece("K", "E8")
     # King on empty board on e1
     self.assertEqual(game.get_possible_squares("k", "E1"),
                      [[1, 4], [1, 5], [0, 5], [0, 3], [1, 3]])
     game.board.set_up_pieces()
     # King on e1 on starting board
     self.assertEqual(game.get_possible_squares("K", "E1"), None)
示例#5
0
 def test_get_possible_squares_knight(self):
     """ Test for get_possible_squares("n") """
     game = Game()
     game.board.clear_board()
     game.board.place_piece("N", "B1")
     legal_moves = game.get_possible_squares("N", "E5")
     # Knight on empty board on e4
     self.assertEqual(
         legal_moves,
         [[6, 3], [6, 5], [2, 3], [2, 5], [5, 2], [5, 6], [3, 2], [3, 6]])
     game.board.set_up_pieces()
     # Knight on b1 on starting board
     self.assertEqual(game.get_possible_squares("N", "B1"),
                      [[2, 0], [2, 2]])
     # Knight on g1 on starting board
     self.assertEqual(game.get_possible_squares("N", "G1"),
                      [[2, 5], [2, 7]])