Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Storing a chess move

Author: Toni

Date: 04:32:22 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
>

I'm thinking about that too. I use a packed int because of the reasons you've
stated and:

* Ahother pro is size. You use 6 bits for 'from', while in the struct approach
you need at least 8 bits. It's a 25% of space saved.

* On the orher hand the packed int approach reduces the amuont of poiner
handling needed to put a move in the move array.

Regards

Toni

>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;
>
>Pros: Accessing fields and initializing the move requires less overhead
>Cons: Moving these things around will be less efficient (copying, etc.)
>
>Are there any endianess issues with using the packed int approach?
>
>I'm not sure if those pros and cons are actually correct. For instance, consider
>initializing a move with data. With the packed int, you have a few quick
>operations (shifts, ORs) and one assignment. With the struct method, you have
>three assignments and possibly some ORs for the move flags. So while the struct
>method appears faster at first glance (since it doesn't have the packing
>"overhead"), there are other operations involved (namely extra assignments). I
>guess the copying around of a struct doesn't have to be slow, if you made the
>entire structure 32-bits (on a 32-bit machine), but then accessing 8-bit members
>of the struct is probably a hair slower than accessing 32-bit members.
>
>If I had to make a guess, well, my brain would probably explode. So tell me your
>thoughts programming experts.



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.