emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] 07/13: [gnugo int] Add abstraction: gnugo--q/ue


From: Thien-Thi Nguyen
Subject: [elpa] 07/13: [gnugo int] Add abstraction: gnugo--q/ue
Date: Mon, 21 Apr 2014 21:32:09 +0000

ttn pushed a commit to branch master
in repository elpa.

commit 9ad395773e0904fe45b5681728bde657944ac419
Author: Thien-Thi Nguyen <address@hidden>
Date:   Mon Apr 21 14:04:04 2014 +0200

    [gnugo int] Add abstraction: gnugo--q/ue
    
    * packages/gnugo/gnugo.el (gnugo--q/ue): New func.
    (gnugo-push-move, gnugo-read-sgf-file, gnugo-magic-undo): Use it.
---
 packages/gnugo/gnugo.el |   24 +++++++++++-------------
 1 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/packages/gnugo/gnugo.el b/packages/gnugo/gnugo.el
index 7edebf6..10e29e2 100644
--- a/packages/gnugo/gnugo.el
+++ b/packages/gnugo/gnugo.el
@@ -420,6 +420,12 @@ status of the command.  See also `gnugo-query'."
     (prog1 (substring (process-get proc :srs) 0 -2)
       (process-put proc :srs ""))))
 
+(defun gnugo--q/ue (fmt &rest args)
+  (let ((ans (apply 'gnugo--q fmt args)))
+    (unless (= ?= (aref ans 0))
+      (user-error "%s" ans))
+    (substring ans 2)))
+
 (defun gnugo-query (message-format &rest args)
   "Send GNU Go a command formatted with MESSAGE-FORMAT and ARGS.
 Return a string that omits the first two characters (corresponding
@@ -1284,9 +1290,7 @@ This fails if the monkey is on the current branch
          (onep (and head (gnugo--passp head)))
          (donep (or resignp (and onep passp))))
     (unless resignp
-      (let ((accept (gnugo--q (format "play %s %s" color move))))
-        (unless (= ?= (aref accept 0))
-          (user-error "%s" accept))))
+      (gnugo--q/ue "play %s %s" color move))
     (unless passp
       (gnugo-merge-showboard-results))
     (gnugo-put :last-mover color)
@@ -1885,14 +1889,10 @@ If FILENAME already exists, Emacs confirms that you 
wish to overwrite it."
   (interactive "fSGF file to load: ")
   (when (file-directory-p filename)
     (user-error "Cannot load a directory (try a filename with extension 
.sgf)"))
-  (let (ans play wait samep coll tree game-over)
+  (let (play wait samep coll tree game-over)
     ;; problem: requiring GTP `loadsgf' complicates network subproc support;
     ;; todo: skip it altogether when confident about `gnugo/sgf-create'
-    (unless (= ?= (aref (setq ans (gnugo--q "loadsgf %s"
-                                            (expand-file-name filename)))
-                        0))
-      (user-error "%s" ans))
-    (setq play (substring ans 2)
+    (setq play (gnugo--q/ue "loadsgf %s" (expand-file-name filename))
           wait (gnugo-other play)
           samep (string= (gnugo-get :user-color) play))
     (gnugo-put :last-mover wait)
@@ -1957,7 +1957,7 @@ when play resumes."
          (tree (gnugo-get :sgf-gametree))
          (ends (gnugo--tree-ends tree))
          (remorseful (not (gnugo--no-regrets monkey ends)))
-         done ans)
+         done)
     (cond ((numberp spec)
            (setq n (if (zerop spec)
                        (if (string= user-color (gnugo-get :last-mover))
@@ -1983,9 +1983,7 @@ when play resumes."
     (when (gnugo-get :game-over)
       (gnugo--unclose-game))
     (while (not (funcall done))
-      (setq ans (gnugo--q "undo"))
-      (unless (= ?= (aref ans 0))
-        (user-error "%s" ans))
+      (gnugo--q/ue "undo")
       (pop (aref monkey 0))
       (gnugo-put :last-mover (gnugo-current-player))
       (gnugo-merge-showboard-results)   ; all



reply via email to

[Prev in Thread] Current Thread [Next in Thread]