Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Quick bit extraction question

Author: Tord Romstad

Date: 05:29:42 07/20/04

Go up one level in this thread


On July 20, 2004 at 08:19:25, Andrew Wagner wrote:

>Being the great genius that I am, it dawned on me the other day that creating a
>custom class to handle things like moves, which can be stored easily in
>integers, was not terribly efficient.

I also needed a long time to realize this.  In Gothmog, moves are encoded
as structs with slots for 'from' and 'to' squares, the moving piece, the
captured piece, and the promotion piece.  This is nice when making and
unmaking moves, but not so nice when comparing moves or stuffing them in
the hash table.  In my new engine, moves are encoded like ints in the way
you suggest.

>So, let's say, for example, I'm storing
>the 'to' square for a move in the right-most (least-significant) 7 bits of an
>integer, the 'from' square in the next 7 least significant bits, and possibly
>other information in other (more significant) bits. What's the most efficient
>way to knock off extra, more significant bits? I want to do something like this:
>to = move MOD 128;
>from = (move>>7) MOD 128;
>
>...but not sure if that's most efficient. Thanks! Andrew

At least it is exactly what I do.  Here are the #defines I use to extract
data from moves:

#define FROM(x) (((x)>>7)&127)
#define TO(x) ((x)&127)
#define PROMOTION(x) (((x)>>14)&7)
#define PIECE(x) (((x)>>17)&7)
#define CAPTURE(x) (((x)>>20)&7)
#define EP_FLAG (1<<23)
#define EP(x) ((x)&EP_FLAG)

Tord




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.