gnugo-devel
[Top][All Lists]
Advanced

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

[gnugo-devel] Undo vs. Magic Undo


From: bump
Subject: [gnugo-devel] Undo vs. Magic Undo
Date: Sat, 6 Nov 2004 10:33:16 -0800

Thi's latest gnugo.el-2.2.6 is now in the CVS and will be in
the next tarball, which will be called gnugo-3.6-pre4.tar.gz
and available (probably) today.

It implements Undo but in a way that I find less useful
than the simple gnugo-undo from the following patch. The patch
includes both undo implementations, with gnugo-magic-undo
bound to U and gnugo-undo bound to u, so you can use
whichever version you like best.

Thi's version is called gnugo-magic-undo and it has the
following description:

  "Undo moves on the GNUGO Board, based on SPEC, a string.
If SPEC has the form of a board position (begins with a letter),
check that the position is occupied by a stone of the user's color,
and if so, remove moves from the history until that position is clear.
If SPEC has the form of a positive number, remove exactly that many
moves from the history, signaling an error if the history is exhausted
before finishing.  Otherwise, signal \"bad spec\" error.

Refresh the board for each move undone.  If (in the case where SPEC is
a number) after finishing, the color to play is not the user's color,
schedule a move by GNU Go."

The problem with magic-undo (maybe just a bug) is that the
way you'd really like to use undo is to type U repeatedly
until you get to the board position before you messed up,
then start playing again. If you use magic undo, after the
first undo you cannot undo again. (Try it.) To take back
multiple moves, you have to calculate which move you want
to go back to and type in the number of moves you want to
retract or a board location.

The version of gnugo-undo listed above allows you to
change colors since taking back an odd number of moves
then placing a stone on the board switches the roles of
the computer and user. By contrast gnugo-magic-undo
always takes back an even number of moves.

Thi, what do you think?

Dan



Index: interface/gnugo.el
===================================================================
RCS file: /cvsroot/gnugo/gnugo/interface/gnugo.el,v
retrieving revision 1.5.2.2
diff -u -r1.5.2.2 gnugo.el
--- interface/gnugo.el  6 Nov 2004 01:33:06 -0000       1.5.2.2
+++ interface/gnugo.el  6 Nov 2004 18:29:17 -0000
@@ -1177,6 +1177,20 @@
   (interactive "fSGF file to load: ")
   (gnugo-command (format "loadsgf %s" (expand-file-name filename))))
 
+(defun gnugo-undo ()
+  "Undo one move. Interchange the colors of the two players."
+  (interactive)
+  (gnugo-gate)
+  (gnugo-synchronous-send/return "undo")
+  (gnugo-put :move-history (cdr (gnugo-get :move-history)))
+  (gnugo-put :sgf-tree (cdr (gnugo-get :sgf-tree)))
+  (gnugo-put :user-color (gnugo-get :last-mover))
+  (gnugo-put :gnugo-color (gnugo-other (gnugo-get :last-mover)))
+  (gnugo-put :last-mover (gnugo-get :gnugo-color))
+  (gnugo-merge-showboard-results)
+  (gnugo-refresh t)
+)
+
 (defun gnugo-magic-undo (spec)
   "Undo moves on the GNUGO Board, based on SPEC, a string.
 If SPEC has the form of a board position (begins with a letter),
@@ -1419,6 +1433,8 @@
 
   R             Resign.
 
+  u             Undo one move.
+
   U             Pass to `gnugo-magic-undo' either the board position
                 at point (if no prefix arg), or the prefix arg converted
                 to a number.  E.g., to undo 16 moves: `C-u C-u U' (see
@@ -1642,6 +1658,7 @@
             ("\C-m"     . gnugo-move)
             (" "        . gnugo-move)
             ("P"        . gnugo-pass)
+            ("u"        . gnugo-undo)
             ("R"        . gnugo-resign)
             ("q"        . (lambda () (interactive)
                             (if (or (gnugo-get :game-over)




reply via email to

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