]> code.delx.au - gnu-emacs-elpa/commitdiff
[gnugo] Add abstraction: gnugo-current-player
authorThien-Thi Nguyen <ttn@gnu.org>
Wed, 16 Apr 2014 09:48:18 +0000 (11:48 +0200)
committerThien-Thi Nguyen <ttn@gnu.org>
Wed, 16 Apr 2014 09:48:18 +0000 (11:48 +0200)
* packages/gnugo/gnugo.el (gnugo-current-player): New func.
(gnugo-refresh, gnugo-magic-undo, gnugo): Use it.

packages/gnugo/NEWS
packages/gnugo/gnugo.el

index 3c51bdf53eea504f3471b8a56c6ea5161f3141f6..98ee2914fd14a9c3669ffaeddaa004c55b1c6969 100644 (file)
@@ -36,6 +36,7 @@ NB: "RCS: X..Y " means that the particular release includes
     - ‘:sgf-gametree’ internal representation inverted (BI)
     - ‘gnugo-magic-undo’ handles SPEC ‘0’
     - dropped ‘(gnugo-move-history 'count)’ (BI)
+    - new func: ‘gnugo-current-player’
 
 - 2.3.1 | 2014-02-27
   - portability fixes
index 7e7f446721b4b4ba138b6ea637363dcc3640f6f2..59db6dd3c3a9b9904133dcf669c478904b196cdb 100644 (file)
@@ -332,6 +332,10 @@ Handle the big, slow-to-render, and/or uninteresting ones specially."
 (defun gnugo-other (color)
   (if (gnugo--blackp color) "white" "black"))
 
+(defun gnugo-current-player ()
+  "Return the current player, either \"black\" or \"white\"."
+  (gnugo-other (gnugo-get :last-mover)))
+
 (defsubst gnugo--gate-game-over (enable)
   (when (and enable (gnugo-get :game-over))
     (user-error "Sorry, game over")))
@@ -1545,7 +1549,7 @@ its move."
                         ,(case c
                            (?b '(or (gnugo-get :black-captures) 0))
                            (?w '(or (gnugo-get :white-captures) 0))
-                           (?p '(gnugo-other (gnugo-get :last-mover)))
+                           (?p '(gnugo-current-player))
                            (?t '(let ((ws (gnugo-get :waiting-start)))
                                   (if ws
                                       (cadr (time-since ws))
@@ -1957,7 +1961,7 @@ when play resumes."
       (unless (= ?= (aref ans 0))
         (user-error "%s" ans))
       (pop (aref monkey 0))
-      (gnugo-put :last-mover (gnugo-other (gnugo-get :last-mover)))
+      (gnugo-put :last-mover (gnugo-current-player))
       (gnugo-merge-showboard-results)   ; all
       (gnugo-refresh)                   ; this
       (decf n)                          ; is
@@ -2546,10 +2550,12 @@ starting a new one.  See `gnugo-board-mode' documentation for more info."
       (let ((g (gnugo-get :gnugo-color))
             (n (or (gnugo--root-prop :HA) 0))
             (u (gnugo-get :user-color)))
-        (gnugo-put :last-mover g)
-        (when (or (and (gnugo--blackp u) (< 1 n))
+        (gnugo-put :last-mover
+          (if (or (and (gnugo--blackp u) (< 1 n))
                   (and (gnugo--blackp g) (< n 2)))
-          (gnugo-put :last-mover u)
+              u
+            g))
+        (when (string= g (gnugo-current-player))
           (gnugo-refresh t)
           (gnugo-get-move g))))))