Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Two question about crbmg.cpp

Author: Gerd Isenberg

Date: 13:02:30 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:


Hi Maurizio,

is it Crafty source?


>
>#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))


Aha, requires only file/rank address instead of square but some more computation
(one additional 64-bit shift left). Nice to have some such conditional
compiling, to try memory size versus some extra instruction(s) from time to
time, specially on new architectures such as AMD64.

It needs only cachefriendly 8*64 arrays = 512 Bitboards = 4KByte each,
instead of 32KByte or even 128KByte with 256 state index!

For more readabilty, AttackRank as a function:

BitBoard AttackRank(unsigned int square, BitBoard occupied)
{
   unsigned int file, ...;

   file = square & 7;  // == square shifted to rank 0

   // & ~7 resets file to zero ==> square shifted to file 0 == rank * 8
   amount2shift2rank0 = square & ~7;   // 0,8,16,24,32,40,48,56

   // occupiedStateOfRank don't considers boarder files
   // only 64 possible ray states versus 256
   // for 256 states     (occupied >>  amount2shift2rank0   ) & 255
   occupiedStateOfRank = (occupied >> (amount2shift2rank0+1)) & 63;

   // get the rank0 attacks and shift left back to the initial rank
   return RookL00[file][occupiedStateOfRank] << amount2shift2rank0;
}


>#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



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.