fink/gobot.lisp

93 lines
2.2 KiB
Common Lisp
Raw Normal View History

2008-05-05 15:00:06 +00:00
(in-package :go-bot)
(defparameter *name* "fink")
2008-05-27 00:46:43 +00:00
(defparameter *version* "0.3.0-dev")
(defparameter *author* "Dan Ballard")
(defparameter *default-komi* 5.5)
(defparameter *komi* *default-komi*)
(defparameter *default-boardsize* 19)
(defparameter *boardsize* *default-boardsize*)
(defparameter *board* nil)
2008-05-26 23:30:59 +00:00
(defparameter *cputime* 0.0)
2008-05-07 09:07:47 +00:00
(defparameter *passed* nil)
(defparameter *player* nil)
(defparameter *last-player* nil)
2008-06-21 06:03:06 +00:00
(defclass composite-board (liberty-shape-board)
((final
:initform 0)))
(defun set-komi (new-komi)
(setf *komi* new-komi))
(defun set-boardsize (newsize)
(setf *boardsize* newsize))
(defun init-board ()
(setf *board* (make-instance 'composite-board :boardsize *boardsize*))
2008-05-07 09:07:47 +00:00
(setf *passed* nil)
(setf *player* nil)
(setf *last-player* nil))
(defun init ()
;(init other game specific stuff)
(setf *random-state* (make-random-state t))
2008-05-26 23:30:59 +00:00
(setf *cputime* 0.0)
(init-board))
2008-05-07 09:07:47 +00:00
2008-05-26 19:13:18 +00:00
(defun play (board coords player)
(set-stone board coords player))
2008-05-19 04:00:04 +00:00
2008-05-19 04:00:04 +00:00
(defun do-play (player coord-str)
2008-05-07 09:07:47 +00:00
(setf *last-player* player)
(if (string= coord-str "PASS")
(setf *passed* t)
2008-05-19 04:00:04 +00:00
;(set-stone *board* (str-to-coord coord-str) player)))
(progn
(setf *passed* nil)
(play *board* (str-to-coord coord-str) player))))
2008-05-07 09:07:47 +00:00
2008-05-19 04:00:04 +00:00
(defun do-genmove (player)
2008-05-29 10:32:39 +00:00
; (format t "do-genmove ~a~%" player)
2008-05-07 09:07:47 +00:00
(setf *player* player)
(if (or (eql *passed* t) (eql *last-player* player))
"pass"
2008-05-26 19:16:07 +00:00
(let* ((move (genmove *board* player))
; (board-score (first move))
(coord (second move)))
2008-05-29 10:32:39 +00:00
;(format t "score: ~a for player ~a ~%" board-score player)
(if (listp coord) ; string= coord "pass"))
(let ((coord-str (coord-to-str coord)))
(do-play player coord-str)
coord-str)
coord))))
;(if (< board-score 0)
; "pass"
; (progn
; (do-play player coord)
; coord)))))
2008-05-07 09:07:47 +00:00
(defun analyze-score ()
(analyze-board-score *board* *player*))
(defun analyze-liberty ()
(liberty-to-analyze *board*))
(defun analyze-shapes ()
(shapes-to-analyze *board*))
2008-06-21 06:03:06 +00:00
(defun analyze-shape-liberties ()
(liberty-shape-to-analyze *board*))
(defun analyze-shape-stone-liberties ()
(liberty-shape-stone-to-analyze *board*))