Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Comparison of board representations

Author: Russell Reagan

Date: 17:21:45 01/22/02

Go up one level in this thread


On January 22, 2002 at 17:51:21, Heiner Marxen wrote:

>On January 22, 2002 at 17:02:00, Russell Reagan wrote:

>>So you save a few cycles with 16x16 or 0x88 but do you lose a few
>>back from computing the offset?
>
>I do not follow.  What offset is to be computed?

I was referring to the addition you have to do on the pointer. An array is just
a pointer, and when you do something like squares[i] that is the exact same
thing as doing *(squares+i) so you have to account for an addition, and I'm not
sure if the pointer dereference takes up a cycle or not.

>>For example to compute whether the king is in
>>check, just do a 1-cycle AND operation on two bitboards (more in reality since
>>most users are on 32-bit machines) and you've got your answer. No tracing along
>>rays searching for attacking pieces.
>
>Sounds interesting.  Could you elaborate, what bitboards are to be used, here?

For example, you could have a bitboard containing the square of the king:

0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 1 0 0 0
king on e1

And when you start your program it can generate some attack bitboards. For
example:

Bitboard bishop_attacks[64];

And bishop_attacks would contain a bitboard for each square on the board, so the
bitboard for a bishop on a5 would be:

0 0 0 1 0 0 0 0
0 0 1 0 0 0 0 0
0 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 0
0 0 0 1 0 0 0 0
0 0 0 0 1 0 0 0
bishop on a5

So you could just AND the bitboards together and if the result is non-zero, then
the king is in check.

if(bishop_attacks[A5] & white_king_bitboard) {
    // king is in check
}

Thanks for your post, it was very helpful!

Russell



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.