Next: 18.1 3つの積み木の場合の縦型・横型探索
Up: ソフトウェア第三 講義資料 クロージャ,スコープ,遅延評価,オブジェクト,立体モデル
Previous: 17 迷路の問題
積み木の世界の問題は同様に以下のように書くことができる.
blockworld-nodeのstateを比較する手続きとして:node=メソッドに,集合の
exorを使えば状態記述内の記述子の順番が入れ替わっていても問題なくなる.
(defclass blockworld-graph
:super graph
:slots
(blocks)
)
(defclass blockworld-node
:super node
:slots (state)
)
(defun set^ (a b &key (test #'eq))
(cond
((null a) b)
((member (car a) b :test test)
(set^ (cdr a) (remove (car a) b :test test)
:test test))
(t (cons (car a) (set^ (cdr a) b :test test)))))
(defun blocks-state= (a b)
(null (set^ a b :test #'equal)))
(defmethod blockworld-node
(:init (&rest args &key ((:state s))
&allow-other-keys)
(send-super-lexpr :init args)
(setq state s)
self)
(:state () state)
(:node= (x)
(blocks-state= state (send x :state)))
(:distance (n)
1
)
(:all-blocks
nil
(mapcar #'car state))
)
generated through LaTeX2HTML. M.Inaba 平成18年5月7日