39b13193bce2

Fix and/or stuff
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Sat, 24 Sep 2016 15:56:44 +0000
parents 6281f8557971
children 167ffd6a7a6a
branches/tags (none)
files src/players/random-ii.lisp src/reasoners/prolog.lisp

Changes

--- a/src/players/random-ii.lisp	Fri Sep 16 14:01:40 2016 +0000
+++ b/src/players/random-ii.lisp	Sat Sep 24 15:56:44 2016 +0000
@@ -44,9 +44,6 @@
 
 
 (defmethod ggp:player-start-game ((player random-ii-player) rules role timeout)
-  (format t "Game Started~%")
-  (loop :repeat 300 :do (princ #\=))
-  (terpri)
   (let ((reasoner (make-prolog-reasoner)))
     (load-rules reasoner rules)
     (setf (rp-role player) role
--- a/src/reasoners/prolog.lisp	Fri Sep 16 14:01:40 2016 +0000
+++ b/src/reasoners/prolog.lisp	Sat Sep 24 15:56:44 2016 +0000
@@ -6,6 +6,40 @@
 
 
 ;;;; Reasoner -----------------------------------------------------------------
+(defun load-gdl-preamble (db)
+  (push-logic-frame-with db
+    (rule db (ggp-rules::not ?x) (call ?x) ! fail)
+    (fact db (ggp-rules::not ?x))
+
+    (rule db (ggp-rules::or ?x ?y) (call ?x))
+    (rule db (ggp-rules::or ?x ?y) (call ?y))
+
+    (rule db (ggp-rules::and ?x ?y) (call ?x) (call ?y))
+
+    (rule db (ggp-rules::distinct ?x ?x) ! fail)
+    (fact db (ggp-rules::distinct ?x ?y))))
+
+(defun make-reasoner-database ()
+  (let ((db (make-database)))
+    (load-gdl-preamble db)
+    db))
+
+
+(defclass prolog-reasoner ()
+  ((database :initform (make-reasoner-database) :reader pr-database)
+   (current-state :initform nil :accessor pr-state)
+   (current-moves :initform nil :accessor pr-moves)))
+
+(defun make-prolog-reasoner ()
+  (make-instance 'prolog-reasoner))
+
+
+;;;; GDL Cleaning -------------------------------------------------------------
+;;; Some GDL authors use (or x y) and (and x y) in their game descriptions, even
+;;; though it's not part of the GDL "spec".  Worse still, some use n-ary
+;;; versions of those predicates, because fuck you.  So we'll do a quick pass
+;;; over the GDL to clean up these bugs.
+
 (defun clean-or (gdl)
   (destructuring-bind (or . arguments)
       gdl
@@ -34,34 +68,6 @@
     gdl))
 
 
-(defun load-gdl-preamble (db)
-  (push-logic-frame-with db
-    (rule db (ggp-rules::not ?x) (call ?x) ! fail)
-    (fact db (ggp-rules::not ?x))
-
-    (rule db (ggp-rules::or ?x ?y) (call ?x))
-    (rule db (ggp-rules::or ?x ?y) (call ?y))
-
-    (rule db (ggp-rules::and ?x ?y) (call ?x) (call ?y))
-
-    (rule db (ggp-rules::distinct ?x ?x) ! fail)
-    (fact db (ggp-rules::distinct ?x ?y))))
-
-(defun make-reasoner-database ()
-  (let ((db (make-database)))
-    (load-gdl-preamble db)
-    db))
-
-
-(defclass prolog-reasoner ()
-  ((database :initform (make-reasoner-database) :reader pr-database)
-   (current-state :initform nil :accessor pr-state)
-   (current-moves :initform nil :accessor pr-moves)))
-
-(defun make-prolog-reasoner ()
-  (make-instance 'prolog-reasoner))
-
-
 ;;;; State Normalization ------------------------------------------------------
 (defun dedupe-state (state)
   (iterate (for fact :in state)