(defparameter *game-file* #p"game-state.lisp")
(setf *read-eval* nil *print-circle* t
*print-pretty* t)
(defvar *board*)
(with-open-file (unused #p".lck" :direction :output
:if-does-not-exist :create
:if-exists :supersede)
(setq *board*
(let ((array (if (probe-file *game-file*)
(with-open-file (in *game-file*
:direction :input)
(read in))
(make-array '(19 19) :initial-element "."))))
(lambda (stream &optional (move nil) (write nil))
(when move (setf (aref array (- 19 (second move)) (1- (first move)))
(third move)))
(if write (prin1 array stream)
(princ array stream)))))
(handler-case
(let* ((query-string (ext:getenv "QUERY_STRING"))
(move (with-input-from-string (s query-string)
(when (peek-char #\( #|)|# s nil nil)
(read s)))))
(terpri)
(if move (funcall *board* t move)
(funcall *board* t)))
(t (e) (format t "I am unhappy about ~a~%" e)))
(with-open-file (out *game-file*
:direction :output
:if-exists :supersede
:if-does-not-exist :create)
(funcall *board* out nil t)))
(terpri)
(quit)