Пример #1
0
    def test_path_impeded(self):
        """Verifies that a rook's returned moves stops when encountering
        another of the rook's owner's pieces."""
        board, white = Board(), Player(Color.W)
        rook_white = Rook(white, [3, 4])  # d4
        board.add_to_board(rook_white)

        pawn_white = Pawn(white, [2, 4])  # c4
        board.add_to_board(pawn_white)

        incorrect_move1 = [2, 4]  # c4

        returned_moves = rook_white.get_legal_moves(board, True)
        self.assertTrue(len(returned_moves) == 11)
        self.assertTrue(incorrect_move1 not in returned_moves)
Пример #2
0
    def test_capture(self):
        """Verifies that a rook's returned move list correctly includes
        a capture opportunity."""
        board, white, black = create_board_and_players()
        rook_white = Rook(white, [3, 4])  # d4
        board.add_to_board(rook_white)

        pawn_black = Pawn(black, [2, 4])  # c4
        board.add_to_board(pawn_black)

        correct_move1 = [2, 4]  # c4

        returned_moves = rook_white.get_legal_moves(board, True)
        self.assertTrue(len(returned_moves) == 12)
        self.assertTrue(correct_move1 in returned_moves)
Пример #3
0
    def test_simple(self):
        """Verifies that a rook's returned move list has the correct
        number of moves and that the boundaries of it's movelist is correct."""
        board, white = Board(), Player(Color.W)
        rook_white = Rook(white, [3, 4])  # d4
        board.add_to_board(rook_white)

        correct_move1 = [0, 4]  # a4
        correct_move2 = [7, 4]  # h4
        correct_move3 = [3, 0]  # d8
        correct_move4 = [3, 7]  # d1

        returned_moves = rook_white.get_legal_moves(board, True)
        self.assertTrue(len(returned_moves) == 14)
        self.assertTrue(correct_move1 in returned_moves)
        self.assertTrue(correct_move2 in returned_moves)
        self.assertTrue(correct_move3 in returned_moves)
        self.assertTrue(correct_move4 in returned_moves)
Пример #4
0
    def test_get_all_legal_moves_simple(self):
        """Simply verify that getting the legal moves of two pieces
        sum to the returned value of get_all_legal_moves."""
        board, white = Board(), Player(Color.W)
        pos_white = [4, 6]  # e2
        pawn_white = Pawn(white, pos_white)
        board.add_to_board(pawn_white)

        pos_white2 = [3, 3]  # d5
        rook_white = Rook(white, pos_white2)
        board.add_to_board(rook_white)

        combined_positions = []
        for move in pawn_white.get_legal_moves(board, True):
            combined_positions += [pawn_white, move],
        for move in rook_white.get_legal_moves(board, True):
            combined_positions += [rook_white, move],

        self.assertEqual(board.get_all_legal_moves(white), combined_positions)