(defun hanoi-init (n initial-table) (setq *disks* (disks n)) (setq *worlds* (append *disks* *tables*)) (dotimes (i n) (move-disk (disk (- n i)) 'ground initial-table)) ) (defun table-top (table) (if (get table :disks) (car (get table :disks)) table)) (defun move-disk (d from to &optional kdraw) (move-on d (table-top to)) (setf (get from :disks) (cdr (get from :disks))) (setf (get to :disks) (cons d (get to :disks))) )
(defun move-on (o to) (send o :locate (v+ (send (get to :top-coords) :worldpos) #f(0 0 0.05)) :world) (hanoi-draw) ) (defun hanoi-draw (&optional num) (cls) (hid *worlds*) (if num (setq *hanoi-draw-number* num)) (when *hanoi-kdraw-file* (kdraw (format nil "disk~A-~A~A.eps" (length *disks*) *hanoi-kdraw-file* *hanoi-draw-number*) (send *viewer* :pane) (hid *viewer* *worlds*)) (setq *hanoi-draw-number* (1+ *hanoi-draw-number*)) ) )