(self)
return move
Restores the previous position and removes the last move from the stack.

        :return: The move removed from the stack.
Restores the previous position and removes the last move from the stack.
Restores the previous position and removes the last move from the stack .
def pop(self):
        """
        Restores the previous position and removes the last move from the stack.

        :return: The move removed from the stack.
        """
        move = self.move_stack.pop()

        # Decrement ply.
        if self.turn == WHITE:
            self.ply -= 1

        # Restore state.
        self.half_moves = self.half_move_stack.pop()
        self.castling_rights = self.castling_right_stack.pop()
        self.ep_square = self.ep_square_stack.pop()
        captured_piece = self.captured_piece_stack.pop()
        captured_piece_color = self.turn

        # On a null move simply swap the turn.
        if not move:
            self.turn ^= 1
            return move

        # Restore the source square.
        piece = PAWN if move.promotion else self.piece_type_at(move.to_square)
        self.set_piece_at(move.from_square, Piece(piece, self.turn ^ 1))

        # Restore target square.
        if captured_piece:
            self.set_piece_at(move.to_square, Piece(captured_piece, captured_piece_color))
        else:
            self.remove_piece_at(move.to_square)

            # Restore captured pawn after en-passant.
            if piece == PAWN and abs(move.from_square - move.to_square) in (7, 9):
                if self.turn == WHITE:
                    self.set_piece_at(move.to_square + 8, Piece(PAWN, WHITE))
                else:
                    self.set_piece_at(move.to_square - 8, Piece(PAWN, BLACK))

        # Restore rook position after castling.
        if piece == KING:
            if move.from_square == E1 and move.to_square == G1:
                self.remove_piece_at(F1)
                self.set_piece_at(H1, Piece(ROOK, WHITE))
            elif move.from_square == E1 and move.to_square == C1:
                self.remove_piece_at(D1)
                self.set_piece_at(A1, Piece(ROOK, WHITE))
            elif move.from_square == E8 and move.to_square == G8:
                self.remove_piece_at(F8)
                self.set_piece_at(H8, Piece(ROOK, BLACK))
            elif move.from_square == E8 and move.to_square == C8:
                self.remove_piece_at(D8)
                self.set_piece_at(A8, Piece(ROOK, BLACK))

        # Swap turn.
        self.turn ^= 1

        return move
def pop ( self ) : move = self . move_stack . pop ( ) # Decrement ply. if self . turn == WHITE : self . ply -= 1 # Restore state. self . half_moves = self . half_move_stack . pop ( ) self . castling_rights = self . castling_right_stack . pop ( ) self . ep_square = self . ep_square_stack . pop ( ) captured_piece = self . captured_piece_stack . pop ( ) captured_piece_color = self . turn # On a null move simply swap the turn. if not move : self . turn ^= 1 return move # Restore the source square. piece = PAWN if move . promotion else self . piece_type_at ( move . to_square ) self . set_piece_at ( move . from_square , Piece ( piece , self . turn ^ 1 ) ) # Restore target square. if captured_piece : self . set_piece_at ( move . to_square , Piece ( captured_piece , captured_piece_color ) ) else : self . remove_piece_at ( move . to_square ) # Restore captured pawn after en-passant. if piece == PAWN and abs ( move . from_square - move . to_square ) in ( 7 , 9 ) : if self . turn == WHITE : self . set_piece_at ( move . to_square + 8 , Piece ( PAWN , WHITE ) ) else : self . set_piece_at ( move . to_square - 8 , Piece ( PAWN , BLACK ) ) # Restore rook position after castling. if piece == KING : if move . from_square == E1 and move . to_square == G1 : self . remove_piece_at ( F1 ) self . set_piece_at ( H1 , Piece ( ROOK , WHITE ) ) elif move . from_square == E1 and move . to_square == C1 : self . remove_piece_at ( D1 ) self . set_piece_at ( A1 , Piece ( ROOK , WHITE ) ) elif move . from_square == E8 and move . to_square == G8 : self . remove_piece_at ( F8 ) self . set_piece_at ( H8 , Piece ( ROOK , BLACK ) ) elif move . from_square == E8 and move . to_square == C8 : self . remove_piece_at ( D8 ) self . set_piece_at ( A8 , Piece ( ROOK , BLACK ) ) # Swap turn. self . turn ^= 1 return move