# HG changeset patch # User Steve Losh # Date 1474732604 0 # Node ID 39b13193bce2ad6632829384539c6d64e737f76c # Parent 6281f855797188c6dfddbe297011ea40f7811891 Fix and/or stuff diff -r 6281f8557971 -r 39b13193bce2 src/players/random-ii.lisp --- 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 diff -r 6281f8557971 -r 39b13193bce2 src/reasoners/prolog.lisp --- 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)