Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Position representation

Author: Sean Mintz

Date: 17:03:43 01/21/02

Go up one level in this thread


I use an 0x88 board which looks like follows:

+---------------------------------+
| r n b q k b n r x x x x x x x x |
| p p p p p p p p x x x x x x x x |
|   -   -   -   - x x x x x x x x |
| -   -   -   -   x x x x x x x x |
|   -   -   -   - x x x x x x x x |
| -   -   -   -   x x x x x x x x |
| P P P P P P P P x x x x x x x x |
| R N B Q K B N R x x x x x x x x |
+---------------------------------+

You're looking for exactly what you get with this board. An easy way to loop is
this:

int i;

for (i=0; i<128; i++) {
   if (i & 0x88) {
      continue; /* not a legal square so skip */
   }
   /* ... put whatever you want here */
}

to go right one square do i + 1, left one square is i - 1, up one square is i -
16, left one square is i + 16, down diagonal left is i + 15, etc etc. if i &
0x88 is true then its an illegal square. simple, eh?

but theres some even neater tricks you can use (which work for other board
representations too ...)

go through the faile/sjeng source for the code. basically you have 2 special
arrays and one variable: pieces[32] and squares[128 (or however many squares in
your board)] and num_pieces. if filled correctly you'll only have to loop
num_pieces times. whenever a capture occurs (if you update these) you'll loop
less and less which should help speedup even more!



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.