next up previous
Next: 12.0.3 goal-searchの定義 Up: 12 迷路問題における状態空間の生成 Previous: 12.0.1 node-equalの定義

12.0.2 next-statesの定義

次に, 壁の無い方向を調べて,next-statesを 作るとすれば,
(defun position-name (p)
  (intern
   (concat 
    "p"
    (+ 1 (round (car p))
       (* 5 (round (cadr p))))))
  )

(defun next-dirs (state)
  (let* ((v (robot-position state))
         (sym (position-name v)))
    (set- '(n w s e)
          (get (position-name v) 'walls))))

(defun next-state (dir state)
  (let ((v (robot-position state)))
    (case
        dir
      (n (list 'robot 'at (v+ '(0 -1) v)))
      (w (list 'robot 'at (v+ '(-1 0) v)))
      (s (list 'robot 'at (v+ '(0 1) v)))
      (e (list 'robot 'at (v+ '(1 0) v))))))

(defun next-states (state)
  (let ((dirs (next-dirs state))
        result)
    (dolist
        (d dirs)
      (setq result
            (cons (next-state d state)
                  result)))
    result))
となって,場所ベクトルからシンボルを取り出し, シンボルから壁の無い方向を集合演算で取り出す というような形で計算をする.
> (next-states '(robot at (2 2)))
((robot at (1 2)))

> (next-states '(robot at (2 3)))
((robot at (2 4)))

> (next-states '(robot at (1 3)))
((robot at (1 4)) (robot at (0 3)))


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