コード例 #1
0
ファイル: test_chessboard.py プロジェクト: miyanda2/Chess
    def test_can_en_passant(self):
        """
        Test that a pawn can perform en passant move.
        :return:
        """
        board = ChessBoard()

        # En passant from white's perspective.
        board['b5'] = Pawn(Color.WHITE)
        board['a7'] = Pawn(Color.BLACK)
        board.move_piece('a7', 'a5')
        self.assertTrue(board.can_en_passant('b5', MoveDirection.F_LEFT_DIAG),
                        'Pawn should be able to perform en passant')

        # En passant from black's perspective.
        board['g4'] = Pawn(Color.BLACK)
        board['h2'] = Pawn(Color.WHITE)
        board.move_piece('h2', 'h4')
        self.assertTrue(board.can_en_passant('g4', MoveDirection.F_LEFT_DIAG),
                        'Pawn should be able to perform en passant')
コード例 #2
0
ファイル: test_chessboard.py プロジェクト: miyanda2/Chess
    def test_cannot_en_passant(self):
        """
        Test that a pawn cannot perform en passant move.
        :return:
        """
        board = ChessBoard()

        # Confirm pawn that just moved 2 spaces can't perform enpassant.
        board['b5'] = Pawn(Color.WHITE)
        board['a7'] = Pawn(Color.BLACK)
        board.move_piece('a7', 'a5')
        self.assertFalse(board.can_en_passant('a5', MoveDirection.F_LEFT_DIAG),
                         'Pawn should not be able to perform en passant')

        # Confirm when all condition have been met but push pawn moved one square twice, en passant can't happen.
        board['g4'] = Pawn(Color.BLACK)
        board['h2'] = Pawn(Color.WHITE)
        board.move_piece('h2', 'h3')
        board.move_piece('h3', 'h4')
        self.assertFalse(board.can_en_passant('g4', MoveDirection.F_LEFT_DIAG),
                         'Pawn should be able to perform en passant')