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

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

[elpa] externals/gnugo e019871 206/357: [gnugo] Add abstraction: gnugo-c


From: Stefan Monnier
Subject: [elpa] externals/gnugo e019871 206/357: [gnugo] Add abstraction: gnugo-current-player
Date: Sun, 29 Nov 2020 14:51:22 -0500 (EST)

branch: externals/gnugo
commit e0198717ea5704a3b58240811d9196103222f609
Author: Thien-Thi Nguyen <ttn@gnu.org>
Commit: Thien-Thi Nguyen <ttn@gnu.org>

    [gnugo] Add abstraction: gnugo-current-player
    
    * packages/gnugo/gnugo.el (gnugo-current-player): New func.
    (gnugo-refresh, gnugo-magic-undo, gnugo): Use it.
---
 NEWS     |  1 +
 gnugo.el | 16 +++++++++++-----
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/NEWS b/NEWS
index 3c51bdf..98ee291 100644
--- a/NEWS
+++ b/NEWS
@@ -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
diff --git a/gnugo.el b/gnugo.el
index 7e7f446..59db6dd 100644
--- a/gnugo.el
+++ b/gnugo.el
@@ -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))))))
 



reply via email to

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