[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 02/03: [gnugo int] Add abstractions: gnugo--{user-}play-stone
From: |
Thien-Thi Nguyen |
Subject: |
[elpa] 02/03: [gnugo int] Add abstractions: gnugo--{user-}play-stone |
Date: |
Sun, 13 Apr 2014 09:14:59 +0000 |
ttn pushed a commit to branch master
in repository elpa.
commit 4af37c9dbd9b0b8cd7fdacc03ce73b363e14a9cb
Author: Thien-Thi Nguyen <address@hidden>
Date: Sun Apr 13 10:52:55 2014 +0200
[gnugo int] Add abstractions: gnugo--{user-}play-stone
* packages/gnugo/gnugo.el (gnugo--play-stone): New func.
(gnugo--user-play-stone): New defsubst.
(gnugo-move, gnugo-pass): Use ‘gnugo--user-play-stone’.
(gnugo-toggle-dead-group, gnugo-okay): Use ‘gnugo--play-stone’.
---
packages/gnugo/gnugo.el | 27 ++++++++++++++-------------
1 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/packages/gnugo/gnugo.el b/packages/gnugo/gnugo.el
index 3cc26d6..598767e 100644
--- a/packages/gnugo/gnugo.el
+++ b/packages/gnugo/gnugo.el
@@ -415,6 +415,14 @@ when you are sure the command cannot fail."
(push (cons prop value)
(cdr (last root))))))
+(defun gnugo--play-stone (color pos-or-PASS)
+ (let ((accept (gnugo--q (format "play %s %s" color pos-or-PASS))))
+ (unless (= ?= (aref accept 0))
+ (user-error "%s" accept))))
+
+(defsubst gnugo--user-play-stone (pos-or-PASS)
+ (gnugo--play-stone (gnugo-get :user-color) pos-or-PASS))
+
(defun gnugo-goto-pos (pos)
"Move point to board position POS, a letter-number string."
(goto-char (point-min))
@@ -1597,11 +1605,8 @@ To start a game try M-x gnugo."
(interactive)
(gnugo-gate t)
(let* ((buf (current-buffer))
- (pos (gnugo-position))
- (move (format "play %s %s" (gnugo-get :user-color) pos))
- (accept (gnugo--q move)))
- (unless (= ?= (aref accept 0))
- (user-error "%s" accept))
+ (pos (gnugo-position)))
+ (gnugo--user-play-stone pos)
(gnugo-push-move t pos) ; value always nil for non-pass move
(let (gnugo-inhibit-refresh)
(run-hooks 'gnugo-post-move-hook)
@@ -1624,9 +1629,7 @@ Signal error if done out-of-turn or if game-over.
To start a game try M-x gnugo."
(interactive)
(gnugo-gate t)
- (let ((accept (gnugo--q "play %s PASS" (gnugo-get :user-color))))
- (unless (= ?= (aref accept 0))
- (user-error "%s" accept)))
+ (gnugo--user-play-stone "PASS")
(let ((donep (gnugo-push-move t "PASS"))
(buf (current-buffer)))
(let (gnugo-inhibit-refresh)
@@ -1769,7 +1772,7 @@ to enable full functionality."
((populate (group)
(let ((color (caar group)))
(dolist (stone (cdr group))
- (gnugo-query "play %s %s" color stone)))))
+ (gnugo--play-stone color stone)))))
(if (eq now live)
(populate group)
;; drastic (and wrong -- clobbers capture info, etc)
@@ -2035,10 +2038,8 @@ Prefix arg means to redo all the undone moves."
finally do
(loop
for (color userp pos) in todo
- do (let* ((move (format "play %s %s" color pos))
- (accept (gnugo--q move)))
- (unless (= ?= (aref accept 0))
- (user-error "%s" accept))
+ do (progn
+ (gnugo--play-stone color pos)
(gnugo-push-move userp pos)
(gnugo-refresh)
(redisplay)))))))))