# HG changeset patch # User Steve Losh # Date 1468230905 0 # Node ID 2a7cb53fb03f2da8165975bad907df789adce0b0 # Parent 4d17e3cb6fa2ace64a715cb15b1f7d3b09b3a17b Clean up the GGP a tiny bit diff -r 4d17e3cb6fa2 -r 2a7cb53fb03f examples/ggp-wam.lisp --- a/examples/ggp-wam.lisp Sun Jul 10 21:08:12 2016 +0000 +++ b/examples/ggp-wam.lisp Mon Jul 11 09:55:05 2016 +0000 @@ -221,13 +221,21 @@ (pop-logic-frame)) -(defvar *count* 0) +(defun perform-move (joint-move) + (prog2 + (apply-moves joint-move) + (next-state) + (clear-moves))) -; (declaim (optimize (speed 0) (debug 3))) +(defvar *count* 0) +(defvar *role* nil) + + ;; nodes: (state . path) (defun depth-first-search (&key exhaust) (let ((*count* 0) + (*role* (first (roles))) (nodes (make-queue))) (enqueue (cons (initial-state) nil) nodes) (pprint @@ -237,18 +245,16 @@ (dequeue nodes) (apply-state state) ; (format t "Searching: ~S (~D remaining)~%" state (length remaining)) - (if (and (not exhaust) (eql 'num100 (goal-value 'robot))) - (progn - (clear-state) - (return (list state (reverse path)))) + (if (terminalp) + (prog1 + (if (and (not exhaust) (eq 'num100 (goal-value *role*))) + (list state (reverse path)) + nil) + (clear-state)) (let ((children - (when (not (terminalp)) - (loop :for joint-move :in (legal-moves) - :collect (prog2 - (apply-moves joint-move) - (cons (next-state) - (cons joint-move path)) - (clear-moves)))))) + (loop :for joint-move :in (legal-moves) + :collect (cons (perform-move joint-move) + (cons joint-move path))))) (clear-state) (queue-append nodes children)))))) (format t "~%Searched ~D nodes.~%" *count*)))