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

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

[elpa] externals/gnugo 5dcf9f6 185/357: [gnugo int] Add abstraction: gnu


From: Stefan Monnier
Subject: [elpa] externals/gnugo 5dcf9f6 185/357: [gnugo int] Add abstraction: gnugo--node-with-played-stone
Date: Sun, 29 Nov 2020 14:51:18 -0500 (EST)

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

    [gnugo int] Add abstraction: gnugo--node-with-played-stone
    
    * packages/gnugo/gnugo.el (gnugo--node-with-played-stone): New func.
    (gnugo-describe-position): Use ‘gnugo--node-with-played-stone’.
---
 gnugo.el | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/gnugo.el b/gnugo.el
index bd1437a..7c52087 100644
--- a/gnugo.el
+++ b/gnugo.el
@@ -2126,30 +2126,30 @@ which placed the stone at point."
   (gnugo-toggle-image-display)
   (save-excursion (gnugo-refresh)))
 
+(defun gnugo--node-with-played-stone (pos)
+  (let ((color (case (following-char)
+                 (?X :B)
+                 (?O :W))))
+    (when color
+      (loop with fruit = (cons color (funcall (gnugo--as-cc-func) pos))
+            for node in (aref (gnugo-get :monkey) 0)
+            if (equal fruit (car node))
+            return node
+            finally return nil))))
+
 (defun gnugo-describe-position ()
   "Display the board position under cursor in the echo area.
 If there a stone at that position, also display its move number."
   (interactive)
-  (let ((pos (gnugo-position))          ; do first (can throw)
-        (color (case (following-char)
-                 (?X :B)
-                 (?O :W))))
+  (let* ((pos (gnugo-position))         ; do first (can throw)
+         (node (gnugo--node-with-played-stone pos)))
     (message
      "%s%s" pos
-     (or (when color
-           (loop
-            with monkey = (gnugo-get :monkey)
-            with tree   = (gnugo-get :sgf-gametree)
-            with mnum   = (gnugo--tree-mnum tree)
-            with as-cc  = (gnugo--as-cc-func)
-            with fruit  = (cons color (funcall as-cc pos))
-            for node in (aref monkey 0)
-            if (member fruit node)
-            return
-            (format " (move %d)"
-                    (gethash node mnum))
-            finally return
-            nil))
+     (or (when node
+           (let* ((tree (gnugo-get :sgf-gametree))
+                  (mnum (gnugo--tree-mnum tree))
+                  (move-num (gethash node mnum)))
+             (format " (move %d)" move-num)))
          ""))))
 
 (defun gnugo-switch-to-another ()



reply via email to

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