gnugo-devel
[Top][All Lists]
Advanced

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

[gnugo-devel] undo patch


From: Gunnar Farneback
Subject: [gnugo-devel] undo patch
Date: Wed, 06 Mar 2002 21:03:52 +0100
User-agent: EMH/1.14.1 SEMI/1.14.3 (Ushinoya) FLIM/1.14.2 (Yagi-Nishiguchi) APEL/10.3 Emacs/20.7 (sparc-sun-solaris2.7) (with unibyte mode)

I've put up my fabled "undo" patch at
http://www.lysator.liu.se/~gunnar/gnugo/patches/gunnar_1_28.1.gz

- global variable last_moves[] removed
- move history added to board state
- static function undo_move() in board.c renamed to undo_trymove()
- new global functions store_board(), restore_board(), undo_move(),
  get_last_opponent_move(), and get_last_move() in board.c 
- macros do_add_stone() and do_remove_stone() removed from board.c
- Position struct removed
- Gameinfo struct revised
- new board_state struct
- API functions gnugo_* work on an internal board state instead of on
  an externally provided board state
- board_size workaround in influence.c obsoleted and removed
- revised order of operations in main.c; in particular playing up the
  position specified by -l and -L options centralized
- revised modes for --score option
- all undo implementations in GTP, GMP, and ASCII interfaces replaced
  by the new undo_move() function in the board code

First of all this patch adds move history to the board state. This has
at least the following benefits:

1. It allows the board code to provide undo for "permanent moves".

2. The separate undo implementations in the GTP, GMP, and ASCII
   interfaces can be replaced (and this is done by the patch) by a
   call to the board code. This simplifies the code and has a good
   potential to eliminate the mysterious "multiple undo in Cgoban"
   crashes that we've had reports of. At the very least the new code
   should give a better assertion failure if the crash wasn't directly
   related to the old undo implementation.

3. We can do away with the last_moves[] array and do more general
   reasoning about move history like "have we passed sometime during
   the last five moves?".

4. It simplifies a future implementation of superko detection.

The move history is implemented as an initial position plus an array
of moves. The move array is of fixed size (default 500 moves) to avoid
memory allocation issues. Should this not be sufficient the
implementation provides graceful degradation by collapsing the first
10% of the moves into the initial position. Undo can be made all the
way back to the initial position but it cannot be used to clear away
the initial position. E.g. in a handicap game the handicap stones are
stored in the initial position and cannot be undone.

Second the patch revises the gnugo_* API functions to use an internal
board state instead of an external, as discussed in a previous
message. As a consequence of this the Position struct in gnugo.h has
been replaced by a board_state struct in liberty.h.

Third the --score option has been revised to work as expected with the
-L option and now has the modes "--score estimate", "--score finish",
and "--score aftermath".

Fourth I have done some cleanup of the code in main.c and play_*.c in
interface/. In particular I have eliminated a certain amount of code
duplication. For example it wasn't really necessary to have 15
distinct calls to the gameinfo_play_sgftree[_rot]() function.


This patch is big and complex enough that it ought to be a few bugs
left and I need help to test it. All different playing modes are
affected and of course the undo functionality needs particular
attention.

I'll be out of town for two days and won't add the patch to CVS until
I'm back. Dan, feel free to add it before then if you think it's a
good idea. At the very least it passes the regressions (or did before
merging with the most recent patches).

/Gunnar



reply via email to

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