diff --git a/env.lisp b/env.lisp index fd26c55..0727a17 100644 --- a/env.lisp +++ b/env.lisp @@ -3,5 +3,5 @@ (defparameter *src-root* "/home/dan/src/my/gobot/") (load (compile-file (concatenate 'string *src-root* "packages.lisp"))) +(load (compile-file (concatenate 'string *src-root* "gobot.lisp"))) (load (compile-file (concatenate 'string *src-root* "gtp.lisp"))) -(load (compile-file (concatenate 'string *src-root* "gobot.lisp"))) \ No newline at end of file diff --git a/gobot.lisp b/gobot.lisp index 54c3579..fe4501c 100644 --- a/gobot.lisp +++ b/gobot.lisp @@ -3,7 +3,40 @@ (defparameter *name* "gobot") (defparameter *version* "0.01") (defparameter *author* "Dan Ballard") +(defparameter *default-komi* 5.5) +(defparameter *komi* *default-komi*) +(defparameter *default-boardsize* 19) +(defparameter *boardsize* *default-boardsize*) + +(defparameter *board* nil) (defun make-board (size) - (make-array size :initial-element (make-array size :initial-element nil))) + (let ((array (make-array size))) + (dotimes (i size) + (setf (aref array i) (make-array size :initial-element nil))) + array)) +(defun set-komi (new-komi) + (setf *komi* new-komi)) + +(defun set-boardsize (newsize) + (setf *boardsize* newsize)) + +(defun init-board () + (setf *board* (make-board *boardsize*))) + +(defun init () + ;(init other game specific stuff) + (init-board)) + +(defun str-to-coord (str) + `( ,(- (char-code (char (string-upcase str) 0)) 65) ,(- (parse-integer (subseq str 1)) 1))) + +(defun get-board (board coord) + (aref (aref board (first coord)) (second coord))) + +(defun set-board (board coord val) + (setf (aref (aref board (first coord)) (second coord)) val)) + + +(defun play (player coord-str) \ No newline at end of file diff --git a/gtp.lisp b/gtp.lisp index 4686b5c..e8f8ae7 100644 --- a/gtp.lisp +++ b/gtp.lisp @@ -22,19 +22,20 @@ (defun dispatch-gtp-command (command-string) (let* ((commands (cl-ppcre:split "\\s+" (string-upcase command-string))) (command (intern (first commands)))) - (progn (format t "'~a'~%" command) (case command (name go-bot:*name*) (version go-bot:*version*) - ;(boardsize (progn - ; (go-bot:set-boardsize (parse-integer (second commands))) - ; (go-bot:init-board))) - ;(komi (go-bot:set-komi (parse-integer (second commands)))) - ;(clearboard (go-bot:init) - ;(play (go-bot:play (second commands) (third commands))) + (boardsize (go-bot:set-boardsize (parse-integer (second commands))) + (go-bot:init-board) + "") + ; warning: read-from-string pulls full reader. not safe + (komi (go-bot:set-komi (read-from-string (second commands))) + "") + (clearboard (go-bot:init) "") + (play (go-bot:play (char (second commands) 0) (third commands))) ;(genmove (go-bot:genmove (char (second commands) 0))) ;(known_command) ;(list_commands - (quit (progn (setf *quit?* t)) "") - (otherwise (concatenate 'string "Unkown command '" (first commands) "'")))))) + (quit (setf *quit?* t) "") + (otherwise (concatenate 'string "Unkown command '" (first commands) "'"))))) \ No newline at end of file diff --git a/packages.lisp b/packages.lisp index dfca0be..59a1cab 100644 --- a/packages.lisp +++ b/packages.lisp @@ -10,4 +10,9 @@ (:use :common-lisp) (:export :*name* :*version* - :*author*)) \ No newline at end of file + :*author* + :set-komi + :set-boardsize + :init-board + :init + )) \ No newline at end of file