Пример #1
0
 def test_Bishop(self):
     self.assertEqual(str(Bishop(1, 1, WHITE, None)), 'Ba1')
     self.assertEqual(str(Bishop(1, 1, BLACK, None)), 'ba1')
     cases = [
         ('Bd4', [
             'c3', 'b2', 'a1', 'c5', 'b6', 'a7', 'e3', 'f2', 'g1', 'e5',
             'f6', 'g7', 'h8'
         ]),
         ('Bd4,pb6,pe5,Ra1',
          ['e5', 'c3', 'b2', 'e3', 'f2', 'g1', 'c5', 'b6']),
     ]
     self.check_cases(WHITE, BISHOP, cases)
     self.check_cases_visible(WHITE, BISHOP, cases)
Пример #2
0
    def test_path_impeded(self):
        """Verifies that a bishop's returned moves stops when encountering
        another of the bishop's owner's pieces."""
        board, white = Board(), Player(Color.W)
        bishop_white = Bishop(white, [3, 4])  # d4
        board.add_to_board(bishop_white)

        pawn_white = Pawn(white, [2, 5])  # c3
        board.add_to_board(pawn_white)

        incorrect_move1 = [2, 4]  # c3

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

        pawn_black = Pawn(black, [2, 5])  # c3
        board.add_to_board(pawn_black)

        correct_move1 = [2, 5]  # c3

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

        correct_move1 = [7, 0]  # h8
        correct_move2 = [6, 7]  # g1
        correct_move3 = [0, 1]  # a7
        correct_move4 = [0, 7]  # a1

        returned_moves = bishop_white.get_legal_moves(board, True)
        self.assertTrue(len(returned_moves) == 13)
        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)
Пример #5
0
    def test_determine_check(self):
        """Creates two check situations and verifies that is_in_check returns
        True in both situations."""
        # Check 1:
        board, white, black = create_board_and_players()

        pos_rook_black = [4, 0]  # e8
        rook_black = Rook(black, pos_rook_black)

        pos_king_white = [4, 7]  # e1
        king_white = King(white, pos_king_white)

        board.add_to_board(rook_black)
        board.add_to_board(king_white)

        self.assertTrue(board.is_in_check(white))

        # Add a separation pawn, should no longer be in check

        pos_pawn_black = [4, 3]  # e5
        pawn_black = Pawn(black, pos_pawn_black)
        board.add_to_board(pawn_black)
        self.assertFalse(board.is_in_check(white))

        # Check 2:
        board, white, black = create_board_and_players()

        pos_bishop_black = [1, 0]  # b8
        bishop_black = Bishop(black, pos_bishop_black)

        pos_king_white = [5, 4]  # f4
        king_white = King(white, pos_king_white)

        board.add_to_board(bishop_black)
        board.add_to_board(king_white)

        self.assertTrue(board.is_in_check(white))

        # Add a separation pawn, should no longer be in check

        pos_pawn_black = [3, 2]  # d6
        pawn_black = Pawn(black, pos_pawn_black)
        board.add_to_board(pawn_black)
        self.assertFalse(board.is_in_check(white))