anchor.diff:      :type integer
       :documentation "The integer encoding the solitaire state.")
      (game
  -    :initform 0
       :initarg :game
       :reader game
       :type solitaire
  
positive.code:                         &key (verbose t) (show-game t))
    (let ((nfmd 0) (steps 0))
      (loop
       (incf steps)
       (let ((current-state (current-state self))
             (moves (get-valid-moves (game self))))
         (setf (valid-moves current-state) moves)
         (when show-game
           (format t "~A" (game self)))
         (when verbose
           ;; (format t "~%~A~%" (state current-state ))
           (format t "Valid moves: ~%~{    ~S~%~}" moves))
         (let ((forced-move (select-forced-move moves)))
           (if forced-move
             (progn
               (when verbose
                 (format t "Forced move: ~S~%" forced-move))
               (if (eq :deal (car forced-move))
                 (if (<= (incf nfmd)
                         (+ (length (stock (game self)))
                            (length (discard (game self)))))
                   (play-move self forced-move)
                   (progn   (format t "Draw~%")
                            (return-from play-game (values nil steps))))
                 (progn
                   (setf nfmd 0)
                   (play-move self forced-move)
                   (when (every (lambda (f) (and f (= 13 (card-figure (car f)))))
                                (foundations (game self)))
                     (format t "Solitaire won!~%")
                     (return-from play-game (values t steps))))))
             (progn
               (setf nfmd 0)
               (setf moves (set-difference moves (played-moves current-state)
                                           :test (function equalp)))
               (cond
                ((null moves)
                 (format t "Remains no unplayed move. I give up.~%")
                 (return-from play-game (values  nil steps)))
                ((= 1 (length moves))
                 (when verbose
                   (format t "Remains to play: ~S~%" (car moves)))
                 (play-move self (car moves)))
                (t
                 (when verbose
                   (format t "Choose to play: ~S~%" (car moves)))
                 (play-move self (car moves))  )))))))));;search-game
  
  
  (defmethod play-game ((self solitaire-player)
                        &key (verbose t) (show-game t))
    (let ((nfmd 0) (steps 0))
      (loop
       (incf steps)
       (let ((current-state (current-state self))
             (moves (get-valid-moves (game self))))
         (when show-game
           (format t "~A" (game self)))
         (when verbose
           ;; (format t "~%~A~%" (state current-state ))
           (format t "Valid moves: ~%~{    ~S~%~}" moves))
         (let ((forced-move (select-forced-move moves)))
           (if forced-move
             (progn
               (when verbose
                 (format t "Forced move: ~S~%" forced-move))
               (if (eq :deal (car forced-move))
                 (if (<= (incf nfmd)
                         (+ (length (stock (game self)))
                            (length (discard (game self)))))
                   (play-move self forced-move)
                   (progn   (format t "Draw~%")
                            (return-from play-game (values nil steps))))
                 (progn
                   (setf nfmd 0)
                   (play-move self forced-move)
                   (when (every (lambda (f) (and f (= 13 (card-figure (car f)))))
                                (foundations (game self)))
                     (format t "Solitaire won!~%")
                     (return-from play-game (values t steps))))))
             (progn
               (setf nfmd 0)
               (setf moves (set-difference moves (played-moves current-state)
                                           :test (function equalp)))
               (cond
                ((null moves)
                 (format t "Remains no unplayed move. I give up.~%")
                 (return-from play-game (values  nil steps)))
                ((= 1 (length moves))
                 (when verbose
                   (format t "Remains to play: ~S~%" (car moves)))
                 (play-move self (car moves)))
                (t
                 (when verbose
                   (format t "Choose to play: ~S~%" (car moves)))
                 (play-move self (car moves))  )))))))));;play-game
  
  
  
  
negative.code:           (foundations copy) (copy-array-of-list (foundations self))
            (hidden      copy) (copy-array-of-list (hidden      self))
            (visible     copy) (copy-array-of-list (visible     self)))
      copy))
  
  
  (defmethod can-deal ((self solitaire))
  