0.2.0 and beyond

This commit is contained in:
Dan 2008-05-26 16:30:59 -07:00
parent feed1cef21
commit 3fc0e0f89e
5 changed files with 29 additions and 10 deletions

3
fink.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
sbcl --noinform --load fink.fasl --eval '(gtp-handler:gtp-client)' --eval '(quit)'

View File

@ -10,6 +10,7 @@
(defparameter *boardsize* *default-boardsize*) (defparameter *boardsize* *default-boardsize*)
(defparameter *board* nil) (defparameter *board* nil)
(defparameter *cputime* 0.0)
(defparameter *passed* nil) (defparameter *passed* nil)
(defparameter *player* nil) (defparameter *player* nil)
@ -29,6 +30,7 @@
(defun init () (defun init ()
;(init other game specific stuff) ;(init other game specific stuff)
(setf *cputime* 0.0)
(init-board)) (init-board))

View File

@ -2,33 +2,39 @@
(defparameter *quit?* nil) (defparameter *quit?* nil)
;(defparameter *cputime*) ;(defparameter *cputime* 0)
(defun gtp-net-client (server port) (defun gtp-net-client (server port)
(go-bot:init) (go-bot:init)
(setf *quit?* nil) (setf *quit?* nil)
(let ((socket (tcp-connect server port))) (let ((socket (netpipe:tcp-connect server port)))
(if (eql socket nil) (if (eql socket nil)
() ()
(progn (progn
; (format t "Connection establish, playing...~%") ; (format t "Connection establish, playing...~%")
(do () (do ()
((or (eql socket nil) (eql *quit?* t))) ((or (eql socket nil) (eql *quit?* t)))
(let ((cmd (tcp-read socket))) (let ((cmd (netpipe:tcp-read socket)))
(format t "cmd: '~a'~%'" cmd) (format t "cmd: '~a'~%'" cmd)
(let ((resp (dispatch-gtp-command cmd))) (let ((resp (inc-cpu-timer (dispatch-gtp-command cmd))))
(print resp) (print resp)
(tcp-print socket (concatenate 'string "= " resp (string #\newline) (string #\newline)))))))))) (netpipe:tcp-print socket (concatenate 'string "= " resp (string #\newline) (string #\newline))))))))))
(defmacro inc-cpu-timer (body)
`(let ((start (get-internal-run-time))
(val ,body)
(end (get-internal-run-time)))
(setf go-bot:*cputime* (+ go-bot:*cputime* (float (/ (- end start) 1000))))
val))
(defun gtp-client () (defun gtp-client ()
(go-bot:init) (go-bot:init)
(setf *quit?* nil) (setf *quit?* nil)
(do () (do ()
((eql *quit?* t)) ((eql *quit?* t))
(format t "= ~a~%~%" (dispatch-gtp-command (read-line t))))) (format t "= ~a~%~%" (inc-cpu-timer (dispatch-gtp-command (read-line t))))))
(defun split-string (string pivot-str) (defun split-string (string pivot-str)
(do ((pivot (char pivot-str 0)) (do ((pivot (char pivot-str 0))
@ -40,6 +46,10 @@
(progn (push (subseq string beg i) strings) (setf beg (+ i 1)))))) (progn (push (subseq string beg i) strings) (setf beg (+ i 1))))))
(defparameter *supported_commands* '("name" "version" "protocol_version" "komi" "boardsize" "clear_board" "play" "genmove" "cputime" "quit" "game_score" "lisT_commands" "known_command"))
(defun match-string (str)
(lambda (elem) (string-equal str elem)))
(defun dispatch-gtp-command (command-string) (defun dispatch-gtp-command (command-string)
(let* ((commands (split-string (string-upcase command-string) " ")) (let* ((commands (split-string (string-upcase command-string) " "))
@ -61,9 +71,12 @@
(genmove (go-bot:do-genmove (char (second commands) 0))) (genmove (go-bot:do-genmove (char (second commands) 0)))
(genmove_black (go-bot:do-genmove #\b)) (genmove_black (go-bot:do-genmove #\b))
(genmove_white (go-bot:do-genmove #\w)) (genmove_white (go-bot:do-genmove #\w))
(cputime (write-to-string go-bot:*cputime*))
;(get_random_seed "0") ;(get_random_seed "0")
;(known_command) (known_command (write-to-string (count-if (match-string (second commands)) *supported_commands*)))
;(list_commands) (list_commands (let ((str ""))
(loop for command in *supported_commands* do (setf str (concatenate 'string str command " ")))
str))
(game_score (format t "Score for ~c: ~s~%" go-bot:*player* (string-trim (string #\newline) (second commands))) "") (game_score (format t "Score for ~c: ~s~%" go-bot:*player* (string-trim (string #\newline) (second commands))) "")
(quit (setf *quit?* t) "") (quit (setf *quit?* t) "")
(otherwise (concatenate 'string "? unknown command: " (string-downcase (first commands))))))) (otherwise (concatenate 'string "? unknown command: " (string-downcase (first commands)))))))

View File

@ -39,7 +39,7 @@ using namespace std;
#define TRUE 1 #define TRUE 1
#define FALSE 0 #define FALSE 0
#define TCPPORT 10001 /* server port value */ #define TCPPORT 10000 /* server port value */
#define BUFSIZE 1024 /* size of i/o buffer */ #define BUFSIZE 1024 /* size of i/o buffer */
#define NOREADS 10 /* number of buffers transferred */ #define NOREADS 10 /* number of buffers transferred */

View File

@ -40,6 +40,7 @@
:*version* :*version*
:*author* :*author*
:*player* :*player*
:*cputime*
:set-komi :set-komi
:set-boardsize :set-boardsize
:init-board :init-board