Пример #1
0
    def test_material_advantage_white_advantage(self):
        self.board = Board.init_default()
        self.board.position[7][0] = None

        self.assertEqual(
            self.board.material_advantage(color.white,
                                          piece_const.PieceValues()), 5)
        self.assertEqual(
            self.board.material_advantage(color.black,
                                          piece_const.PieceValues()), -5)

        self.board = Board.init_default()
        self.board.position[7][3] = None

        self.assertEqual(
            self.board.material_advantage(color.white,
                                          piece_const.PieceValues()), 9)
        self.assertEqual(
            self.board.material_advantage(color.black,
                                          piece_const.PieceValues()), -9)

        self.board = Board.init_default()
        self.board.position[7][2] = None

        self.assertEqual(
            self.board.material_advantage(color.white,
                                          piece_const.PieceValues()), 3.5)
        self.assertEqual(
            self.board.material_advantage(color.black,
                                          piece_const.PieceValues()), -3.5)
Пример #2
0
    def test_place_piece_at_square(self):
        test = Board.init_default()
        pawn = Pawn(color.white, Location.from_string("e3"))

        test.position[2][4] = pawn

        self.board.place_piece_at_square(pawn, Location.from_string("e3"))

        self.assertEqual(self.board, test)
Пример #3
0
    def test_move_piece(self):
        test = Board.init_default()
        pawn = test.position[1][4]
        test.position[1][4] = None
        test.position[3][4] = pawn

        self.board.move_piece(Location.from_string("e2"),
                              Location.from_string("e4"))

        self.assertEqual(self.board, test)
Пример #4
0
    def test_in_check(self):
        self.board = Board([[None for _ in range(8)] for _ in range(8)])
        my_king = King(color.white, Location.from_string("f3"))
        self.board.place_piece_at_square(my_king, Location.from_string("f3"))
        self.board.place_piece_at_square(Rook(color.black, Location.from_string("f1")), Location.from_string("f1"))

        print(self.board.piece_at_square(Location.from_string("f1")).color)

        print(self.board)
        print(my_king.color)
        print(color.white == color.black)
        self.assertTrue(my_king.in_check(self.board))

        self.board = Board.init_default()
        self.board.update(converter.long_alg("f2f3", self.board))
        self.board.move_piece(Location.from_string("d8"), Location.from_string("g3"))

        self.assertTrue(self.board.get_king(color.white).in_check(self.board))
Пример #5
0
 def setUp(self):
     self.test_board = Board.init_default()
     self.e_four_move = Move(end_loc=Location.from_string("e4"),
                             piece=Pawn(color.white, Location.from_string("e4")),
                             status=notation_const.MOVEMENT,
                             start_loc=Location.from_string("e2"))
Пример #6
0
 def setUp(self):
     self.board = Board.init_default()
Пример #7
0
    def test_copy(self):
        tester = Board.init_default()

        for num, row in enumerate(self.board.position):
            for index, piece in enumerate(row):
                self.assertEqual(piece, tester.position[num][index])
Пример #8
0
 def test_remove_piece_at_square(self):
     test_board = Board.init_default()
     test_board.position[0][0] = None
     self.board.remove_piece_at_square(Location(0, 0))
     self.assertEqual(self.board, test_board)