Example #1
0
 def test_Queen(self):
     self.assertEqual(str(Queen(1, 1, WHITE, None)), 'Qa1')
     self.assertEqual(str(Queen(1, 1, BLACK, None)), 'qa1')
     cases = [
         ('Qd4', [
             'c3', 'b2', 'a1', 'c5', 'b6', 'a7', 'e3', 'f2', 'g1', 'e5',
             'f6', 'g7', 'h8', 'd1', 'd2', 'd3', 'd5', 'd6', 'd7', 'd8',
             'a4', 'b4', 'c4', 'e4', 'f4', 'g4', 'h4'
         ]),
         ('Qd4,Nb4,Nd2,Ra1,Bf2,qd5,pc5,pe4,nf6',
          ['c3', 'b2', 'c5', 'e3', 'e5', 'f6', 'd3', 'd5', 'c4', 'e4']),
     ]
     self.check_cases(WHITE, QUEEN, cases)
     self.check_cases_visible(WHITE, QUEEN, cases)
Example #2
0
    def test_simple(self):
        """Verifies that a queen'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)
        queen_white = Queen(white, [3, 4])  # d4
        board.add_to_board(queen_white)

        correct_move_list = [[7, 0]]  # h8
        correct_move_list += [6, 7],  # g1
        correct_move_list += [0, 1],  # a7
        correct_move_list += [0, 7],  # a1
        correct_move_list += [0, 4],  # a4
        correct_move_list += [7, 4],  # h4
        correct_move_list += [3, 0],  # d8
        correct_move_list += [3, 7],  # d1

        returned_moves = queen_white.get_legal_moves(board, True)
        self.assertTrue(len(returned_moves) == 27)
        for move in correct_move_list:
            self.assertTrue(move in returned_moves)
Example #3
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)
        queen_white = Queen(white, [3, 4])  # d4
        board.add_to_board(queen_white)

        pawn_white1 = Pawn(white, [2, 3])  # c5
        board.add_to_board(pawn_white1)

        incorrect_move1 = [2, 3]  # c6

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

        incorrect_move2 = [2, 4]  # c4

        returned_moves = queen_white.get_legal_moves(board, True)
        self.assertTrue(len(returned_moves) == 21)
        self.assertTrue(incorrect_move1 not in returned_moves)
        self.assertTrue(incorrect_move2 not in returned_moves)
Example #4
0
    def test_capture(self):
        """Verifies that a queen's returned movelist correctly includes
        a capture opportunity."""
        board, white, black = create_board_and_players()
        queen_white = Queen(white, [3, 4])  # d4
        board.add_to_board(queen_white)

        pawn_black = Pawn(black, [2, 3])  # c5
        board.add_to_board(pawn_black)

        correct_move1 = [2, 5]  # c6

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

        correct_move2 = [2, 4]  # c4

        returned_moves = queen_white.get_legal_moves(board, True)
        self.assertTrue(len(returned_moves) == 23)
        self.assertTrue(correct_move1 in returned_moves)
        self.assertTrue(correct_move2 in returned_moves)