Use the grounder in the vanilla random player
author |
Steve Losh <steve@stevelosh.com> |
date |
Thu, 29 Sep 2016 16:33:29 +0000 |
parents |
db764ac2697b
|
children |
90dd275f6e81
|
branches/tags |
(none) |
files |
package.lisp src/gdl.lisp src/grounders/fluxplayer.lisp src/players/random.lisp |
Changes
--- a/package.lisp Tue Sep 27 12:53:16 2016 +0000
+++ b/package.lisp Thu Sep 29 16:33:29 2016 +0000
@@ -9,7 +9,7 @@
(:export
#:read-gdl
#:load-rules
- ))
+ #:redump-gdl))
(defpackage #:scully.reasoners.prolog
(:use
@@ -52,7 +52,8 @@
#:smug
#:scully.quickutils)
(:export
- ))
+ #:ground-gdl-file
+ #:ground-gdl-string))
(defpackage #:scully.players.random
(:use
--- a/src/gdl.lisp Tue Sep 27 12:53:16 2016 +0000
+++ b/src/gdl.lisp Thu Sep 29 16:33:29 2016 +0000
@@ -17,3 +17,7 @@
(apply #'invoke-rule database (cdr rule))
(invoke-fact database rule)))
rules)))
+
+(defun redump-gdl (rules)
+ (let ((*package* (find-package :ggp-rules)))
+ (format nil "~(~{~S~%~}~)" rules)))
--- a/src/grounders/fluxplayer.lisp Tue Sep 27 12:53:16 2016 +0000
+++ b/src/grounders/fluxplayer.lisp Thu Sep 29 16:33:29 2016 +0000
@@ -115,19 +115,26 @@
(ensure-list rule)))))))
-;;;; API ----------------------------------------------------------------------
-(defun ground-raw (filename)
+;;;; Fluxplayer ---------------------------------------------------------------
+(defun ground-with-fluxplayer (string filename)
(uiop/run-program:run-program
`("/Users/sjl/src/fluxplayer/trunk/src/groundgdl.sh" ,filename "-")
:force-shell nil
+ :input (make-string-input-stream string)
:output :string))
-(defun ground-gdl (filename)
- (->> filename
- ground-raw
+
+;;;; API ----------------------------------------------------------------------
+(defun ground-gdl-string (string)
+ (->> (ground-with-fluxplayer string "-")
+ parse-raw-grounded
+ (apply #'rebuild-rules)))
+
+(defun ground-gdl-file (filename)
+ (->> (ground-with-fluxplayer "" filename)
parse-raw-grounded
(apply #'rebuild-rules)))
; (ground-gdl "gdl/buttons.gdl")
-; (ground-gdl "gdl/tictactoe.gdl")
+; (ground-gdl-file "gdl/tictactoe.gdl")
--- a/src/players/random.lisp Tue Sep 27 12:53:16 2016 +0000
+++ b/src/players/random.lisp Thu Sep 29 16:33:29 2016 +0000
@@ -13,7 +13,9 @@
(defmethod ggp:player-start-game ((player random-player) rules role timeout)
(let ((reasoner (make-prolog-reasoner)))
- (load-rules reasoner rules)
+ (load-rules reasoner (-> rules
+ scully.gdl:redump-gdl
+ scully.grounders.fluxplayer:ground-gdl-string))
(setf (rp-role player) role
(rp-reasoner player) reasoner
(rp-state player) (initial-state reasoner))))