eschulte pushed a commit to branch go
in repository elpa.
commit 7cf25156af355e4e092478fb885274db381843a2
Author: Eric Schulte <[email protected]>
Date: Mon May 20 14:50:01 2013 -0600
query backend for territory
---
back-ends/gtp.el | 11 +++++++++++
back-ends/igs.el | 3 +++
back-ends/sgf.el | 3 +++
go-api.el | 3 ++-
go-board.el | 9 +++++----
5 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/back-ends/gtp.el b/back-ends/gtp.el
index 4343edc..cbb247b 100644
--- a/back-ends/gtp.el
+++ b/back-ends/gtp.el
@@ -58,6 +58,14 @@
(:KM (format "komi %s" val))
(t nil))))
+(defun gtp-territory (gtp color)
+ (let ((output (ecase color
+ (:B (gtp-command gtp "final_status_list black_territory"))
+ (:W (gtp-command gtp "final_status_list white_territory")))))
+ (mapcar (lambda (gtp-point) (gtp-to-pos color gtp-point))
+ (mapcar #'symbol-name
+ (read (format "(%s)" output))))))
+
;;; Class and interface
(defclass gtp nil nil "Class for the GTP GO GO back end.")
@@ -136,4 +144,7 @@
(defmethod go-score ((gtp gtp)) (gtp-command gtp "final_score"))
+(defmethod go-territory ((gtp gtp))
+ (append (gtp-territory gtp :B) (gtp-territory gtp :W)))
+
(provide 'gtp)
diff --git a/back-ends/igs.el b/back-ends/igs.el
index 8ab9799..0c29097 100644
--- a/back-ends/igs.el
+++ b/back-ends/igs.el
@@ -458,4 +458,7 @@ This is used to re-send messages to keep the IGS server
from timing out.")
(defmethod go-score ((igs igs))
(signal 'unsupported-back-end-command (list igs :score)))
+(defmethod go-territory ((igs igs))
+ (signal 'unsupported-back-end-command (list igs :territory)))
+
(provide 'igs)
diff --git a/back-ends/sgf.el b/back-ends/sgf.el
index 185753b..6048dc3 100644
--- a/back-ends/sgf.el
+++ b/back-ends/sgf.el
@@ -191,4 +191,7 @@
(defmethod go-score ((sgf sgf))
(signal 'unsupported-back-end-command (list sgf :score)))
+(defmethod go-territory ((sgf sgf))
+ (signal 'unsupported-back-end-command (list sgf :territory)))
+
(provide 'sgf)
diff --git a/go-api.el b/go-api.el
index 13cd9f4..45908c4 100644
--- a/go-api.el
+++ b/go-api.el
@@ -75,6 +75,7 @@
(defgeneric go-resign (back-end) "Send resign to BACK-END.")
(defgeneric go-reset (back-end) "Send reset to BACK-END.")
(defgeneric go-quit (back-end) "Quit the BACK-END.")
-(defgeneric go-score (back-end) "Ask BACK-END to report the final score.")
+(defgeneric go-score (back-end) "Ask BACK-END to report the score.")
+(defgeneric go-territory (back-end) "Ask BACK-END to report the territory.")
(provide 'go-api)
diff --git a/go-board.el b/go-board.el
index 89e5e05..916a7b2 100644
--- a/go-board.el
+++ b/go-board.el
@@ -391,9 +391,10 @@
(setf *turn* (other-color *turn*))
(when *autoplay*
(when (equalp :pass (go-board-next))
- ;; TODO: print the score
- (message "final score: %s"
- (with-backends back (go-score back)))))))
+ (message "final score: %s territory:%s"
+ (with-backends back (go-score back))
+ ;; TODO: mark the territory
+ (with-backends back (go-territory back)))))))
(defun go-board-undo (&optional num)
(interactive "p")
@@ -404,7 +405,7 @@
(defun go-board-comment (&optional comment)
(interactive "MComment: ")
- (message "comment: %S" comment))
+ (with-backends back (setf (go-comment back) comment)))
(defun go-board-level (&optional level)
(interactive "nLevel: ")