Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Easy programmers question: game history

Author: Russell Reagan

Date: 15:29:30 02/23/04

Go up one level in this thread


On February 23, 2004 at 17:59:53, Andreas Guettinger wrote:

>Currently my engine only knows about the current position, which is quite dumb,
>I know.
>
>I want to record the current game now as it is played, for takebacks, move
>repetition etc. What is the best way to do this:
>
>1) just record the moves that are made to be able to undo them
>
>2) make an array of my position structure and drop the current position into the
>array, and upon takeback jump back to the requested position.

I think most people use the first approach, but I know there are some who use
the second also. Some information requires copying, since you cannot undo
anything to get the previous state. For instance, the castling rights fall into
this category. If you undo a castling move, how do you know what the castling
rights were before you made the castling move? You can't know this unless you
backed up the previous castling rights.

So what I do is create a stack of all the information that needs to be backed
up. Something like this:

struct PlyInfo
{
    unsigned castling_rights;
    int      ep_square;
    int      fifty_move_count;
    Move     move_played;
    Move *   move_list; // start generating moves here
    // and whatever else you want to add
};

PlyInfo ply_stack[MAX_PLY];
int ply; // current ply

Or I might use a PlyInfo pointer to the top of the stack and just increment and
decrement that. I think Bruce Moreland does this in Gerbil. He has a struct
called STE (I think), which stands for "stack element" (I think). You can
download the source code for Gerbil at his website: http://www.brucemo.com



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.