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

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

[elpa] 02/02: [gnugo] New command: ‘ O’ (gnugo-okay)


From: Thien-Thi Nguyen
Subject: [elpa] 02/02: [gnugo] New command: ‘ O’ (gnugo-okay)
Date: Sat, 12 Apr 2014 17:28:21 +0000

ttn pushed a commit to branch master
in repository elpa.

commit d1dd484d1b2c0b2e4b8963f773143774656ce481
Author: Thien-Thi Nguyen <address@hidden>
Date:   Sat Apr 12 19:30:48 2014 +0200

    [gnugo] New command: ‘O’ (gnugo-okay)
    
    * packages/gnugo/gnugo.el (gnugo-okay): New command.
    (gnugo-board-mode-map): Add binding for ‘O’.
---
 packages/gnugo/NEWS     |    1 +
 packages/gnugo/gnugo.el |   48 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/packages/gnugo/NEWS b/packages/gnugo/NEWS
index 99340b7..4c39fde 100644
--- a/packages/gnugo/NEWS
+++ b/packages/gnugo/NEWS
@@ -19,6 +19,7 @@ NB: "RCS: X..Y " means that the particular release includes
   - new keybinding for ‘gnugo-undo-one-move’: M-u
   - ‘gnugo-undo-one-move’ can optionally arrange for you to play next
   - new command: ‘o’ (gnugo-oops)
+  - new command: ‘O’ (gnugo-okay)
   - new command: ‘L’ (gnugo-frolic-in-the-leaves)
   - new major mode: GNUGO Frolic (gnugo-frolic-mode)
   - ‘gnugo-move-history’ returns last two moves w/ RSEL ‘two’
diff --git a/packages/gnugo/gnugo.el b/packages/gnugo/gnugo.el
index 2afca86..4f00a34 100644
--- a/packages/gnugo/gnugo.el
+++ b/packages/gnugo/gnugo.el
@@ -1996,6 +1996,53 @@ the move which placed the stone at point, like 
`\\[gnugo-fancy-undo]'."
                       0)
                     nil t))
 
+(defun gnugo-okay (&optional full)
+  "Redo a pair of undone moves.
+Prefix arg means to redo all the undone moves."
+  (interactive "P")
+  (gnugo-gate)
+  (let* ((tree (gnugo-get :sgf-gametree))
+         (ends (gnugo--tree-ends tree))
+         (monkey (gnugo-get :monkey)))
+    (if (gnugo--no-regrets monkey ends)
+        (message "Oop ack!")
+      (let* ((as-pos (gnugo--as-pos-func))
+             (mnum (gnugo--tree-mnum tree))
+             (mem (aref monkey 0))
+             (bidx (aref monkey 1))
+             (end (aref ends bidx))
+             (ucolor (gnugo-get :user-color))
+             (gcolor (gnugo-other ucolor))
+             (uprop (if (gnugo--blackp ucolor)
+                        :B :W)))
+        (cl-flet ((mvno (node) (gethash node mnum)))
+          (loop
+           with ok = (if full
+                         (mvno (car end))
+                       (+ 2 (mvno (car mem))))
+           with (node move todo)
+           for ls on end
+           do (progn
+                (setq node (car ls)
+                      move (gnugo--move-prop node))
+                (when (and move (>= ok (mvno node)))
+                  (let ((userp (eq uprop (car move))))
+                    (push (list (if userp ucolor gcolor)
+                                userp
+                                (funcall as-pos (cdr move)))
+                          todo))))
+           until (eq mem (cdr ls))
+           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))
+                 (gnugo-push-move userp pos)
+                 (gnugo-refresh)
+                 (redisplay)))))))))
+
 (defun gnugo-display-final-score ()
   "Display final score and other info in another buffer (when game over).
 If the game is still ongoing, Emacs asks if you wish to stop play (by
@@ -2454,6 +2501,7 @@ starting a new one.  See `gnugo-board-mode' documentation 
for more info."
           ("u"        . gnugo-undo-two-moves)
           ("\C-?"     . gnugo-undo-two-moves)
           ("o"        . gnugo-oops)
+          ("O"        . gnugo-okay)
           ("\C-l"     . gnugo-refresh)
           ("\M-_"     . gnugo-boss-is-near)
           ("_"        . gnugo-boss-is-near)



reply via email to

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