Author: Álvaro Begué
Date: 09:15:50 09/09/04
Go up one level in this thread
On September 09, 2004 at 11:37:07, Rick Bischoff wrote:
>Hello all,
>
>I am bored with my mediocre chess engine, so I decided to start a mediocre
>checkers engine instead. Anyway, I am scratching my head how to store the
>moves.. I was thinking that a structure similar to:
>
>struct Move {
>int startIndex;
>int n;
>int array[8];
>}
>
>Where n is the number of elements in the array.. (i.e., a single move/capture
>would have n = 1, a double jump would have n = 2 )
>
>Where each array[i] would store the direction of the move (NW,NE,SW,SE) and two
>bits to represent capture/no capture/king capture/X
>
>However, I have a couple of questions regarding this format:
>
>I do not know the longest sequence of captures possible-- i.e., is there a 9
>step double jump possible? a 12 step? I mean, if it were only 8, I could just
>use a single integer instead of an array.
>
>Also, is there a better way to represent moves?
If your board is 8x8, you only have 32 squares. You can encode the pieces to be
removed from the board in a single int.
typedef unsigned int u32; // Or whatever type happens to be 32 bits in your
compiler
struct Move{
int from;
int to;
u32 captured;
};
A common representation of the board is
struct Board{
u32 white_pieces;
u32 black_pieces;
u32 kings;
};
So to make a white move you would do something like
void make_white_move(Board &b, Move &m){
u32 encoded_move = 1u << m.to - 1u << m.from;
b.white_pieces += encoded_move;
if(b.kings & (1u << m.from))
b.kings += encoded_move;
else if(to>28)
b.kings += 1u << m.to;
b.black_pieces &= ~m.captured;
}
Actually, you could just always store (1u << square) instead of the square
itself.
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.