Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Two question about crbmg.cpp

Author: Sune Fischer

Date: 08:52:51 01/27/04

Go up one level in this thread


On January 27, 2004 at 11:24:18, Maurizio Di Vitto wrote:

>Thank for your help.
>I just want to receive some explanation about this part of code:
>
>#ifdef USE_COMPACT_ATTACK_TABLES
># define AttackRank(s,o)
>(((BitBoard)RookL00[(s)&7][((o)>>(((s)&~7)+1))&63])<<((s)&~7))
># define AttackFile(s,o) (RookL90[(s)>>3][((o)>>((((s)&7)<<3)+1))&63]<<((s)&7))
>#else
># define AttackRank(s,o) (RookL00[s][((o)>>(((s)&~7)+1))&63])
># define AttackFile(s,o) (RookL90[s][((o)>>((((s)&7)<<3)+1))&63])
>#endif
># define AttackRook(s)   (AttackRank(s,occupied)|AttackFile(s,occupied_l90))
># define AttackR45(s,o)  (BishopR45[s][((o)>>ShiftR45[s])&63])
># define AttackL45(s,o)  (BishopL45[s][((o)>>ShiftL45[s])&63])
># define AttackBishop(s) (AttackR45(s,occupied_r45)|AttackL45(s,occupied_l45))
># define AttackQueen(s)  (AttackRook(s)|AttackBishop(s))
>
>and so:
>
>inline BitBoard KnightAttacksFrom(int s)  { return (Knight[s]); }
>	inline BitBoard BishopAttacksFrom(int s)  { return (AttackBishop(s)); }
>	inline BitBoard RookAttacksFrom(int s)    { return (AttackRook(s)); }
>	inline BitBoard QueenAttacksFrom(int s)   { return (AttackQueen(s)); }
>	inline BitBoard KingAttacksFrom(int s)    { return (King[s]); }
>	inline uint IsAttackedBy(uint co,uint sq) {
>		if (King[sq]&(kings|queens)&Occupied(co))           return 1;
>		if (Pawn[co^1][sq]&(pawns|bishops)&Occupied(co))    return 1;
>		if (Knight[sq]&knights&Occupied(co))                return 1;
>		if (AttackRook(sq)&(rooks|queens)&Occupied(co))     return 1;
>		if (AttackBishop(sq)&(bishops|queens)&Occupied(co)) return 1;
>		return 0;
>	}
>	inline uint InCheck() {
>		return IsAttackedBy(stm^1,ksq[stm]);
>	}
>
>I need to know more about Attack..[] array.
>I think I know what the should do but I don't know how they work.
>Thank you for your time and help.
>Maurizio Di Vitto

The Attack arrays are not really arrays but macros.

The macros job is to extract the occupied rank information from the rotated
boards and use it to index the precalculated arrays which stores the attack
bitboards we are looking for.

Phew.

Think of it as precalculated raytracing.

We're on e5, there are pieces on a5, e5 and g5, otherwise the rank is empty.
What should this attack rank look like?

Ok, only thing that matters here is 5th rank, so we shift down
(occupied>>(square&~7)) to get the 5th rank onto the first rank. Now we have the
occupied state ready for indexing by ANDing with 255.

Due to the aforementioned trick of using only 6 bits, we must shift by one more
and AND with 63 instead of 255.

Same trick for files and diagonals only harder to visualize because we must use
the rotated boards.

-S.



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.