Exemple #1
0
 def test_Knight(self):
     self.assertEqual(str(Knight(1, 1, WHITE, None)), 'Na1')
     self.assertEqual(str(Knight(1, 1, BLACK, None)), 'na1')
     cases = [
         ('Ne4', ['d6', 'f6', 'g5', 'g3', 'f2', 'd2', 'c3', 'c5']),
         ('Ng4,Pe3,Rg2,pf6,rh6', ['f6', 'h6', 'h2', 'f2', 'e5']),
     ]
     self.check_cases(WHITE, KNIGHT, cases)
     self.check_cases_visible(WHITE, KNIGHT, cases)
Exemple #2
0
    def test_simple(self):
        """Verifies that a knight'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)
        knight_white = Knight(white, [3, 4])  # d4
        board.add_to_board(knight_white)
        # c6, e6, f5, f3, e2, c2, b3, b5
        correct_move_list = [[2, 2], [4, 2], [5, 3], [5, 5],
                             [4, 6], [2, 6], [1, 5], [1, 3]]

        returned_moves = knight_white.get_legal_moves(board, True)
        self.assertTrue(len(returned_moves) == 8)
        for move in correct_move_list:
            self.assertTrue(move in returned_moves)
Exemple #3
0
    def test_capture(self):
        """Verifies that a knights's returned movelist correctly includes
        a capture opportunity."""
        board, white, black = create_board_and_players()
        knight_white = Knight(white, [3, 4])  # d4
        board.add_to_board(knight_white)

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

        correct_move1 = [2, 2]  # c6

        returned_moves = knight_white.get_legal_moves(board, True)
        self.assertTrue(len(returned_moves) == 8)
        self.assertTrue(correct_move1 in returned_moves)