2a7cb53fb03f

Clean up the GGP a tiny bit
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Mon, 11 Jul 2016 09:55:05 +0000
parents 4d17e3cb6fa2
children d6b6684d6b7b
branches/tags (none)
files examples/ggp-wam.lisp

Changes

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