Author: Reinhard Scharnagl
Date: 03:24:53 12/25/03
Go up one level in this thread
On December 25, 2003 at 02:33:00, Russell Reagan wrote:
>This is a question mainly directed at chess programmers. Why do some of you
>store a chess move as a structure, and others of you store it as a packed int?
>Crafty stores them as a packed int, while many others use a struct.
>
>An example of the packed int approach is:
>
>typedef int Move;
>Move m = from_square | (to_square << 6) | (move_flags << 12);
>
>Pros: Handling of a move as a whole entity is fast (i.e. copying, sorting, etc.)
>Cons: Accessing fields of a move and packing the move requires some overhead
>
>An example of the struct approach is:
>
>struct Move
>{
> int from;
> int to;
> unsigned flags;
>};
>
>Move m;
>m.from = from_square;
>m.to = to_square;
>m.flags = move_flags;
>
[...]
Hi, my approach is: (commented in german language)
// bestimmte Spezialzug-Kodes
enum eZugTyp {
eFigIndex = 0x0F,
eSpezEpSchlag = 0x10,
eSpezRochade = 0x20,
eSpezWandlung = 0x40,
eSpezial = eSpezEpSchlag | eSpezRochade | eSpezWandlung,
eSchlagzug = 0x80,
};
// kodierter Spielzug
union TZug {
struct TZugBytes {
// bewegter Figurtyp mit Flags
unsigned char Typ;
// Quellfeld-Koordinate
unsigned char Her;
// Zielfeld-Koordinate
unsigned char Hin;
// Schachrichtung, Doppelschach oder Zero
char Dir;
} B;
// gesamter Zugriff
int Voll;
};
Regards, Reinhard.
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.