[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/gnugo 4028102 271/357: [gnugo] Make climb-to-root "GNU
From: |
Stefan Monnier |
Subject: |
[elpa] externals/gnugo 4028102 271/357: [gnugo] Make climb-to-root "GNU Go to play" reaction customizable. |
Date: |
Sun, 29 Nov 2020 14:51:37 -0500 (EST) |
branch: externals/gnugo
commit 4028102f7dfea9a4a522fae0db93b31e20463f87
Author: Thien-Thi Nguyen <ttn@gnu.org>
Commit: Thien-Thi Nguyen <ttn@gnu.org>
[gnugo] Make climb-to-root "GNU Go to play" reaction customizable.
* packages/gnugo/gnugo.el (gnugo-undo-reaction): New defvar.
(gnugo--user-play): Inhibit karmic error for one-shot.
(gnugo--climb-towards-root): Don't take 2nd arg NOALT;
instead, take 2nd arg REACTION; drop "POS not occupied by COLOR"
check and error; rewrite handling for "GNU Go to play" case.
(gnugo-undo-one-move): Call ‘gnugo--climb-towards-root’ w/
‘gnugo-undo-reaction’ value clamped to ‘zombie’/‘one-shot’.
---
NEWS | 1 +
gnugo.el | 57 +++++++++++++++++++++++++++++++++++----------------------
2 files changed, 36 insertions(+), 22 deletions(-)
diff --git a/NEWS b/NEWS
index 54a4cb2..026d67d 100644
--- a/NEWS
+++ b/NEWS
@@ -31,6 +31,7 @@ NB: "RCS: X..Y " means that the particular release includes
- new command: ‘L’ (gnugo-frolic-in-the-leaves)
- new command: ‘C-c C-a’ (gnugo-assist-mode)
- new command: ‘C-c C-z’ (gnugo-zombie-mode)
+ - new var: gnugo-undo-reaction
- new major mode: GNUGO Frolic (gnugo-frolic-mode)
- GNUGO Board mode now derived from Special mode
- position arg validated for direct GTP commands ‘undo’, ‘gg-undo’
diff --git a/gnugo.el b/gnugo.el
index 9f475dc..a01ae63 100644
--- a/gnugo.el
+++ b/gnugo.el
@@ -162,6 +162,19 @@ For ~t, the value is a snapshot, use `gnugo-refresh' to
update it.")
(defvar gnugo-grid-face 'default
"Name of face to use for the grid (A B C ... 1 2 3 ...).")
+(defvar gnugo-undo-reaction 'play!
+ "What to do if undo (or oops) leaves GNU Go to play.
+After `gnugo-undo-one-move', `gnugo-undo-two-moves' or `gnugo-oops',
+when GNU Go is to play, this can be a symbol:
+ play -- make GNU Go play (unless in Zombie mode)
+ play! -- make GNU Go play unconditionally (traditional behavior)
+ zombie -- enable Zombie mode (`gnugo-zombie-mode')
+ one-shot -- like `zombie' but valid only for the next move
+Any other value, or (as a special case) for `gnugo-undo-one-move',
+any value other than `zombie', is taken as `one-shot'. Note that
+making GNU Go play will probably result in the recently-liberated
+board position becoming re-occupied.")
+
;;;---------------------------------------------------------------------------
;;; Variables for the inquisitive programmer
@@ -1747,8 +1760,10 @@ cursor to the suggested position. Prefix arg inhibits
warp."
(let ((color (gnugo-current-player)))
;; Don't get confused by mixed signals.
(when (gnugo--karma color)
- (user-error "Sorry, you cannot play for %s at this time"
- color))
+ (if (equal color (gnugo-get :one-shot))
+ (gnugo--forget :one-shot)
+ (user-error "Sorry, you cannot play for %s at this time"
+ color)))
(gnugo-push-move color pos-or-pass))
(gnugo--finish-move t))
@@ -2001,7 +2016,7 @@ If FILENAME already exists, Emacs confirms that you wish
to overwrite it."
return mem
finally return nil))))
-(defun gnugo--climb-towards-root (spec &optional noalt keep)
+(defun gnugo--climb-towards-root (spec &optional reaction keep)
(gnugo-gate)
(gnugo--assist-state t)
(let* ((user-color (gnugo-get :user-color))
@@ -2017,16 +2032,10 @@ If FILENAME already exists, Emacs confirms that you
wish to overwrite it."
2)
spec)
(aref monkey 0))
- (let* ((pos (if (stringp spec)
- spec
- (gnugo-position)))
- (hmm (gnugo--mem-with-played-stone pos)))
- ;; todo: relax ‘gnugo--user-play’ then lift restriction
- (unless (eq (gnugo--prop<-color user-color)
- (car (gnugo--move-prop (car hmm))))
- (user-error "%s not occupied by %s"
- pos user-color))
- (cdr hmm)))))
+ (cdr (gnugo--mem-with-played-stone
+ (if (stringp spec)
+ spec
+ (gnugo-position)))))))
(when (gnugo-get :game-over)
(gnugo--unclose-game))
(while (and (not (eq stop (aref monkey 0)))
@@ -2037,7 +2046,6 @@ If FILENAME already exists, Emacs confirms that you wish
to overwrite it."
(gnugo-refresh) ; this
(redisplay)) ; eye candy
(let* ((ulastp (string= (gnugo-get :last-mover) user-color))
-
(ubpos (gnugo-move-history (if ulastp 'car 'cadr))))
(gnugo-put :last-user-bpos (if (and ubpos (not (gnugo--passp ubpos)))
ubpos
@@ -2045,13 +2053,16 @@ If FILENAME already exists, Emacs confirms that you
wish to overwrite it."
(gnugo-refresh t)
(unless (or keep remorseful)
(aset ends (aref monkey 1) (aref monkey 0)))
- (when (and ulastp (not noalt))
- (let ((wheel (gnugo-get :wheel)))
- ;; ugh, backward compat
- ;; todo: add auto-Zombie (see also "relax" above)
- (letf (((cdr wheel) (remove (gnugo-get :gnugo-color)
- (cdr wheel))))
- (gnugo--turn-the-wheel t)))))))
+ (when ulastp
+ (let ((g (gnugo-get :gnugo-color)))
+ (cl-flet ((turn () (gnugo--turn-the-wheel t)))
+ (case (or reaction gnugo-undo-reaction)
+ (play (turn))
+ (play! (let ((wheel (gnugo-get :wheel)))
+ (letf (((cdr wheel) (cons g (cdr wheel))))
+ (turn))))
+ (zombie (gnugo-zombie-mode 1))
+ (t (gnugo-put :one-shot g)))))))))
(defun gnugo-undo-one-move (&optional me-next)
"Undo exactly one move (perhaps GNU Go's, perhaps yours).
@@ -2073,7 +2084,9 @@ See also `gnugo-undo-two-moves'."
(gnugo-put :user-color play)
(gnugo-put :gnugo-color wait)
(gnugo--who-is-who wait play samep)))
- (gnugo--climb-towards-root 1 t))
+ (gnugo--climb-towards-root 1 (case gnugo-undo-reaction
+ (zombie gnugo-undo-reaction)
+ (t 'one-shot))))
(defun gnugo-undo-two-moves ()
"Undo a pair of moves (GNU Go's and yours).
- [elpa] externals/gnugo d96223f 209/357: [gnugo] Move most of ‘gnugo-board-mode’ to ‘gnugo’., (continued)
- [elpa] externals/gnugo d96223f 209/357: [gnugo] Move most of ‘gnugo-board-mode’ to ‘gnugo’., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo eb77485 215/357: [gnugo int] Don't make ‘font-lock-defaults’ buffer-local., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 4d5f998 217/357: [gnugo int] Decruft: Drop unused local var., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo e6c0a07 229/357: [gnugo int] Fix bug: On -l/--infile, don't set :last-mover., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 11543e5 232/357: [gnugo] Reduce modifier key bouncing for "quick peek" frolics., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo dae8f08 231/357: [gnugo] Fix bug: DTRT for :last-user-bpos in undo-one-move ME-NEXT., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo f102d7f 240/357: [gnugo] Allow user to move for GNU Go., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 9969838 260/357: [gnugo int] Drop abstractions: gnugo--{ERR-wait, gate-game-over}, Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo b9fa668 265/357: [gnugo int] Drop redundant ‘gnugo-gate’ calls., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo a766f0c 282/357: [gnugo] Replace ‘gnugo-toggle-grid’ w/ ‘gnugo-grid-mode’., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 4028102 271/357: [gnugo] Make climb-to-root "GNU Go to play" reaction customizable.,
Stefan Monnier <=
- [elpa] externals/gnugo 46eec46 285/357: [gnugo int] Simplify COND expression., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo eaae57d 324/357: [gnugo int] Add Juanma Barranquero to THANKS; nfc., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo bb986d7 323/357: [gnugo] Release: 3.0.2, Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 64bd753 327/357: [gnugo int] Simplify SGF-write subroutine., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo c6eb3d1 325/357: [gnugo maint] Add people from ttn-pers-elisp THANKS file; nfc., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 981d75e 341/357: [gnugo] Fix bug: Don't clobber dead-group indication on refresh., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo e4344ac 350/357: [gnugo] Release: 3.1.0, Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo af82527 356/357: [gnugo] Release: 3.1.1, Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 53da06f 329/357: [gnugo] Make ‘gnugo-comment’ fall back to root node., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 781a385 332/357: [gnugo] Drop trailing fullstop for "... done" messages., Stefan Monnier, 2020/11/29