--- a/package.lisp Mon Nov 21 16:52:13 2016 +0000
+++ b/package.lisp Wed Nov 23 11:08:33 2016 +0000
@@ -7,9 +7,10 @@
:temperance
:scully.quickutils)
(:export
+ :gensym-ggp
:read-gdl
:load-rules
- :redump-gdl))
+ :dump-gdl))
(defpackage :scully.graphviz
--- a/src/gdl.lisp Mon Nov 21 16:52:13 2016 +0000
+++ b/src/gdl.lisp Wed Nov 23 11:08:33 2016 +0000
@@ -1,6 +1,15 @@
(in-package :scully.gdl)
+(defvar *ggp-gensym-counter* 0)
+
+(defun gensym-ggp ()
+ "Return a unique symbol in the `ggp-rules` package."
+ (values (intern (mkstr 'rule- (incf *ggp-gensym-counter*))
+ (find-package :ggp-rules))))
+
+
(defun read-gdl (filename)
+ "Read GDL from the given file"
(let ((*package* (find-package :ggp-rules)))
(with-open-file (stream filename)
(loop
@@ -18,6 +27,6 @@
(invoke-fact database rule)))
rules)))
-(defun redump-gdl (rules)
+(defun dump-gdl (rules)
(let ((*package* (find-package :ggp-rules)))
(format nil "~(~{~S~%~}~)" rules)))
--- a/src/grounders/fluxplayer.lisp Mon Nov 21 16:52:13 2016 +0000
+++ b/src/grounders/fluxplayer.lisp Wed Nov 23 11:08:33 2016 +0000
@@ -104,7 +104,7 @@
(setf (gethash (index-entry-id entry) index)
(index-entry-term entry)))
(flet ((get-rule (id)
- (ensure-gethash id index (gensym))))
+ (ensure-gethash id index (scully.gdl:gensym-ggp))))
(iterate
(for entry :in rule-entries)
(for rule = (get-rule (rule-id entry)))
@@ -139,17 +139,15 @@
(defun dump-grounded (filename)
- (with-output-to-file (*standard-output*
- (mkstr "gdl/" filename "-grounded.gdl")
- :if-exists :supersede)
- (let ((*package* (find-package :ggp-rules)))
- (map nil #'print (ground-gdl-file (mkstr "gdl/" filename ".gdl"))))))
+ (let ((grounded (ground-gdl-file (mkstr "gdl/" filename ".gdl"))))
+ (write-string-into-file (scully.gdl:dump-gdl grounded)
+ (mkstr "gdl/" filename "-grounded.gdl")
+ :if-exists :supersede))
+ 'ok)
; (dump-grounded "buttons")
; (dump-grounded "8puzzle")
; (dump-grounded "tictactoe")
-; (dump-grounded "roshambo2")
+(dump-grounded "roshambo2")
; (dump-grounded "hanoi")
-
-
--- a/src/logic.lisp Mon Nov 21 16:52:13 2016 +0000
+++ b/src/logic.lisp Wed Nov 23 11:08:33 2016 +0000
@@ -2,7 +2,11 @@
(defparameter *rules*
- (scully.gdl::read-gdl "gdl/tictactoe-grounded.gdl"))
+ ; (scully.gdl::read-gdl "gdl/tictactoe-grounded.gdl")
+ ; (scully.gdl::read-gdl "gdl/hanoi-grounded.gdl")
+ ; (scully.gdl::read-gdl "gdl/8puzzle-grounded.gdl")
+ (scully.gdl::read-gdl "gdl/roshambo2-grounded.gdl")
+ )
(defun make-stratum-rule-trees (stratum)
@@ -12,17 +16,19 @@
(mapcar #'scully.rule-trees::make-rule-tree <>)))
-; (setf *print-length* 10000)
-(destructuring-bind (term->number number->term rule-layers)
- (scully.terms::integerize-rules *rules*)
- ; (let ((*print-length* 1000))
- ; (print-hash-table number->term))
- ; (print-hash-table rule-layers)
+(setf *print-length* 10
+ *print-depth* 5)
+
+(defun make-rule-forest (rules)
+ (destructuring-bind (term->number number->term rule-layers)
+ (scully.terms::integerize-rules rules)
(flet ((draw (rt)
(scully.graphviz::draw-rule-tree
rt :label-fn (lambda (n)
(gethash n number->term)))
- (break)))
+ (break)
+ ))
+ (print-hash-table rule-layers)
(-<> rule-layers
(gethash :possible <>)
scully.terms::stratify-layer
@@ -40,3 +46,18 @@
; (break))
; <>)
)))
+ )
+
+(make-rule-forest *rules*)
+
+
+
+
+;;;; PLAN
+;;;
+;;; 1. Receive GDL from server
+;;; 2. Ground it
+;;; 3. Integerize the ground GDL
+;;; 4. Find initial state
+;;; 5. Build rule trees for integerized rules
+;;; 6. ...
--- a/src/players/random.lisp Mon Nov 21 16:52:13 2016 +0000
+++ b/src/players/random.lisp Wed Nov 23 11:08:33 2016 +0000
@@ -14,7 +14,7 @@
(defmethod ggp:player-start-game ((player random-player) rules role timeout)
(let ((reasoner (make-prolog-reasoner)))
(load-rules reasoner (-> rules
- scully.gdl:redump-gdl
+ scully.gdl:dump-gdl
scully.grounders.fluxplayer:ground-gdl-string))
(setf (rp-role player) role
(rp-reasoner player) reasoner
--- a/vendor/make-quickutils.lisp Mon Nov 21 16:52:13 2016 +0000
+++ b/vendor/make-quickutils.lisp Wed Nov 23 11:08:33 2016 +0000
@@ -20,6 +20,7 @@
:set-equal
:with-gensyms
:with-output-to-file
+ :write-string-into-file
)
:package "SCULLY.QUICKUTILS")
--- a/vendor/quickutils.lisp Mon Nov 21 16:52:13 2016 +0000
+++ b/vendor/quickutils.lisp Wed Nov 23 11:08:33 2016 +0000
@@ -2,7 +2,7 @@
;;;; See http://quickutil.org for details.
;;;; To regenerate:
-;;;; (qtlc:save-utils-as "quickutils.lisp" :utilities '(:COMPOSE :COPY-HASH-TABLE :CURRY :ENSURE-BOOLEAN :ENSURE-GETHASH :ENSURE-LIST :FLATTEN-ONCE :HASH-TABLE-KEYS :HASH-TABLE-VALUES :MAP-PRODUCT :MKSTR :ONCE-ONLY :RCURRY :SET-EQUAL :WITH-GENSYMS :WITH-OUTPUT-TO-FILE) :ensure-package T :package "SCULLY.QUICKUTILS")
+;;;; (qtlc:save-utils-as "quickutils.lisp" :utilities '(:COMPOSE :COPY-HASH-TABLE :CURRY :ENSURE-BOOLEAN :ENSURE-GETHASH :ENSURE-LIST :FLATTEN-ONCE :HASH-TABLE-KEYS :HASH-TABLE-VALUES :MAP-PRODUCT :MKSTR :ONCE-ONLY :RCURRY :SET-EQUAL :WITH-GENSYMS :WITH-OUTPUT-TO-FILE :WRITE-STRING-INTO-FILE) :ensure-package T :package "SCULLY.QUICKUTILS")
(eval-when (:compile-toplevel :load-toplevel :execute)
(unless (find-package "SCULLY.QUICKUTILS")
@@ -22,7 +22,8 @@
:MAPPEND :MAP-PRODUCT :MKSTR
:ONCE-ONLY :RCURRY :SET-EQUAL
:STRING-DESIGNATOR :WITH-GENSYMS
- :WITH-OPEN-FILE* :WITH-OUTPUT-TO-FILE))))
+ :WITH-OPEN-FILE* :WITH-OUTPUT-TO-FILE
+ :WRITE-STRING-INTO-FILE))))
(eval-when (:compile-toplevel :load-toplevel :execute)
(defun make-gensym-list (length &optional (x "G"))
"Returns a list of `length` gensyms, each generated as if with a call to `make-gensym`,
@@ -363,10 +364,23 @@
`(with-open-file* (,stream-name ,file-name :direction :output ,@args)
,@body))
+
+ (defun write-string-into-file (string pathname &key (if-exists :error)
+ if-does-not-exist
+ external-format)
+ "Write `string` to `pathname`.
+
+The `external-format` parameter will be passed directly to `with-open-file`
+unless it's `nil`, which means the system default."
+ (with-output-to-file (file-stream pathname :if-exists if-exists
+ :if-does-not-exist if-does-not-exist
+ :external-format external-format)
+ (write-sequence string file-stream)))
+
(eval-when (:compile-toplevel :load-toplevel :execute)
(export '(compose copy-hash-table curry ensure-boolean ensure-gethash
ensure-list flatten-once hash-table-keys hash-table-values
map-product mkstr once-only rcurry set-equal with-gensyms
- with-unique-names with-output-to-file)))
+ with-unique-names with-output-to-file write-string-into-file)))
;;;; END OF quickutils.lisp ;;;;