next up previous
Next: 24.6 ハノイの塔の移動プログラムの生成 Up: 24 ハノイの塔のモデル sample/hanoi.l Previous: 24.4 表示画面の設定

24.5 ディスクの移動コマンド


(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*))
    )
  )


generated through LaTeX2HTML. M.Inaba 平成18年5月7日