more basics in board management and creation
This commit is contained in:
parent
38a2a0cccf
commit
a90e7da354
2
env.lisp
2
env.lisp
|
@ -3,5 +3,5 @@
|
||||||
(defparameter *src-root* "/home/dan/src/my/gobot/")
|
(defparameter *src-root* "/home/dan/src/my/gobot/")
|
||||||
|
|
||||||
(load (compile-file (concatenate 'string *src-root* "packages.lisp")))
|
(load (compile-file (concatenate 'string *src-root* "packages.lisp")))
|
||||||
(load (compile-file (concatenate 'string *src-root* "gtp.lisp")))
|
|
||||||
(load (compile-file (concatenate 'string *src-root* "gobot.lisp")))
|
(load (compile-file (concatenate 'string *src-root* "gobot.lisp")))
|
||||||
|
(load (compile-file (concatenate 'string *src-root* "gtp.lisp")))
|
||||||
|
|
35
gobot.lisp
35
gobot.lisp
|
@ -3,7 +3,40 @@
|
||||||
(defparameter *name* "gobot")
|
(defparameter *name* "gobot")
|
||||||
(defparameter *version* "0.01")
|
(defparameter *version* "0.01")
|
||||||
(defparameter *author* "Dan Ballard")
|
(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)
|
(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)
|
19
gtp.lisp
19
gtp.lisp
|
@ -22,19 +22,20 @@
|
||||||
(defun dispatch-gtp-command (command-string)
|
(defun dispatch-gtp-command (command-string)
|
||||||
(let* ((commands (cl-ppcre:split "\\s+" (string-upcase command-string)))
|
(let* ((commands (cl-ppcre:split "\\s+" (string-upcase command-string)))
|
||||||
(command (intern (first commands))))
|
(command (intern (first commands))))
|
||||||
(progn (format t "'~a'~%" command)
|
|
||||||
(case command
|
(case command
|
||||||
(name go-bot:*name*)
|
(name go-bot:*name*)
|
||||||
(version go-bot:*version*)
|
(version go-bot:*version*)
|
||||||
;(boardsize (progn
|
(boardsize (go-bot:set-boardsize (parse-integer (second commands)))
|
||||||
; (go-bot:set-boardsize (parse-integer (second commands)))
|
(go-bot:init-board)
|
||||||
; (go-bot:init-board)))
|
"")
|
||||||
;(komi (go-bot:set-komi (parse-integer (second commands))))
|
; warning: read-from-string pulls full reader. not safe
|
||||||
;(clearboard (go-bot:init)
|
(komi (go-bot:set-komi (read-from-string (second commands)))
|
||||||
;(play (go-bot:play (second commands) (third commands)))
|
"")
|
||||||
|
(clearboard (go-bot:init) "")
|
||||||
|
(play (go-bot:play (char (second commands) 0) (third commands)))
|
||||||
;(genmove (go-bot:genmove (char (second commands) 0)))
|
;(genmove (go-bot:genmove (char (second commands) 0)))
|
||||||
;(known_command)
|
;(known_command)
|
||||||
;(list_commands
|
;(list_commands
|
||||||
(quit (progn (setf *quit?* t)) "")
|
(quit (setf *quit?* t) "")
|
||||||
(otherwise (concatenate 'string "Unkown command '" (first commands) "'"))))))
|
(otherwise (concatenate 'string "Unkown command '" (first commands) "'")))))
|
||||||
|
|
|
@ -10,4 +10,9 @@
|
||||||
(:use :common-lisp)
|
(:use :common-lisp)
|
||||||
(:export :*name*
|
(:export :*name*
|
||||||
:*version*
|
:*version*
|
||||||
:*author*))
|
:*author*
|
||||||
|
:set-komi
|
||||||
|
:set-boardsize
|
||||||
|
:init-board
|
||||||
|
:init
|
||||||
|
))
|
Loading…
Reference in New Issue