[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/gnugo 1020a7f 237/357: [gnugo int] Simplify towards-roo
From: |
Stefan Monnier |
Subject: |
[elpa] externals/gnugo 1020a7f 237/357: [gnugo int] Simplify towards-root loop termination check. |
Date: |
Sun, 29 Nov 2020 14:51:29 -0500 (EST) |
branch: externals/gnugo
commit 1020a7fda5f9665da01b227e51cbbde5d51d2b5e
Author: Thien-Thi Nguyen <ttn@gnu.org>
Commit: Thien-Thi Nguyen <ttn@gnu.org>
[gnugo int] Simplify towards-root loop termination check.
* packages/gnugo/gnugo.el (gnugo--climb-towards-root):
Don't construct local func ‘done’; instead, pre-compute
final MEM and loop until it's reached, as per ‘eq’.
---
gnugo.el | 46 +++++++++++++++++++---------------------------
1 file changed, 19 insertions(+), 27 deletions(-)
diff --git a/gnugo.el b/gnugo.el
index ad6f15b..8cf2a7c 100644
--- a/gnugo.el
+++ b/gnugo.el
@@ -1942,44 +1942,36 @@ If FILENAME already exists, Emacs confirms that you
wish to overwrite it."
(defun gnugo--climb-towards-root (spec &optional noalt keep)
(gnugo-gate)
- (let* ((n 0)
- (user-color (gnugo-get :user-color))
+ (let* ((user-color (gnugo-get :user-color))
(monkey (gnugo-get :monkey))
(tree (gnugo-get :sgf-gametree))
(ends (gnugo--tree-ends tree))
(remorseful (not (gnugo--no-regrets monkey ends)))
- done)
- (cond ((numberp spec)
- (setq n (if (zerop spec)
- (if (string= user-color (gnugo-get :last-mover))
- 1
- 2)
- spec)
- done (lambda () (zerop n))))
- ((string-match "^[a-z]" spec)
- (let ((pos (upcase spec)))
- (setq done `(lambda ()
- (gnugo-goto-pos ,pos)
- (memq (following-char) '(?. ?+))))
- (when (funcall done)
- (user-error "%s already clear" pos))
- (when (= (save-excursion
- (gnugo-goto-pos pos)
- (following-char))
- (if (gnugo--blackp user-color)
- ?O
- ?X))
- (user-error "%s not occupied by %s" pos user-color))))
- (t (user-error "Bad spec: %S" spec)))
+ (stop (if (numberp spec)
+ (nthcdr (if (zerop spec)
+ (if (string= (gnugo-get :last-mover)
+ user-color)
+ 1
+ 2)
+ spec)
+ (aref monkey 0))
+ (let* ((pos spec)
+ (hmm (or (gnugo--mem-with-played-stone pos)
+ (user-error "%s already clear" 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)))))
(when (gnugo-get :game-over)
(gnugo--unclose-game))
- (while (not (funcall done))
+ (while (not (eq stop (aref monkey 0)))
(gnugo--q/ue "undo")
(pop (aref monkey 0))
(gnugo-put :last-mover (gnugo-current-player))
(gnugo-merge-showboard-results) ; all
(gnugo-refresh) ; this
- (decf n) ; is
(redisplay)) ; eye candy
(let* ((ulastp (string= (gnugo-get :last-mover) user-color))
- [elpa] externals/gnugo 82b6000 198/357: [gnugo] Mention ‘gnugo-frolic-mode-hook’., (continued)
- [elpa] externals/gnugo 82b6000 198/357: [gnugo] Mention ‘gnugo-frolic-mode-hook’., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 32e8547 199/357: [gnugo int] Add abstraction: gnugo--user-play, Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 001228c 205/357: [gnugo] Drop support for ‘(gnugo-move-history 'count)’., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 106a279 211/357: [gnugo int] Consolidate paren overlays access., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 17d907d 210/357: [gnugo int] Shave one ‘gnugo-other’ call., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 1d6b241 214/357: [gnugo] Use ‘define-derived-mode’ for GNUGO Board mode., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 167ba89 213/357: [gnugo int] Decruft: Streamline game-over handling on SGF load., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo b3d3da0 220/357: [gnugo int] Use functional style more., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo e96b88b 218/357: [gnugo] Decruft: Use ‘gnugo-program’ directly as executable., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 3670b0b 228/357: [gnugo] On SGF load, leave cursor at last user board position., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 1020a7f 237/357: [gnugo int] Simplify towards-root loop termination check.,
Stefan Monnier <=
- [elpa] externals/gnugo 7114ed6 234/357: [gnugo int] Add abstraction: gnugo--mem-with-played-stone, Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 9ae1363 236/357: [gnugo] Internalize ‘gnugo-magic-undo’., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo a92e184 255/357: fixup! [gnugo int] Decorate w/ plist instead of alist., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 71e1500 245/357: [gnugo] Fix bug: Use ‘gnugo-gate’ for abdication enable., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 46f49e3 246/357: [gnugo int] Use ‘gnugo-current-player’ more., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 443903e 249/357: [gnugo int] Drop abstraction: pretty, Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo a0ecdea 257/357: [gnugo] Conditionalize xform warping on abdication disable., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 85e3d91 253/357: [gnugo int] Snoop ‘--handicap N’ for empty new board., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 7c7d43c 261/357: [gnugo int] Avoid superfluous ‘gnugo-other’ call., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 6ddf38f 269/357: [gnugo int] Add abstraction: gnugo--assist-state, Stefan Monnier, 2020/11/29