Author: Gerd Isenberg
Date: 13:48:53 01/28/02
Go up one level in this thread
On January 28, 2002 at 15:23:09, Gerd Isenberg wrote: >BITBOARD RookAttacksForward(BOARD &occupied, char square) >{ > BITBOARD a,x,y; > > x=occupied>>square; // shift board so square ends in lower left corner > y=x&RANK1; // mask out ewerything but the first rank > a=y^(y-2); // get the attacked bits on this rank > y=x&FILE1; // now mask so we get a clean first file > y=y^(y-2); // get the attacked squares > a=a|(y&FILE1); // add the attacked bits after masking with the file again > a=a<<square; // shift the attacked bits back (for ease of readability) > > return a; >} > >Thanks, very interesting. I can imagine, that this is faster than a table lookup >with the risc of cache miss, specially when you do it with assembler with mmx >registers (or waiting for hammer and 64bit compiler). Impressed about the >y^(y-2) operation, to get the attacked squares. I have to study it a while. > >Gerd OK, i understood. Nice for rooks on a1. The RookAttacksBackward(BOARD &occupied, char square) using the Reversed BitBoard is also "Reversed", and than the Bishops... You have to use Foreward and Reverse BitBoards for all Sliders or you have to reverse the "Reverse" Bitboard before oring them together. I use rotated, but i reduce the occupied state to 6Bits, ignoring the outer ones. Some lines of code: BitBoard sRankAtta[64][64]; // [square][six inner square state] BitBoard sFileAtta[64][64]; // [square][six inner square state] BitBoard sA1H8Atta[64][64]; // [square][six inner square state] BitBoard sH1A8Atta[64][64]; // [square][six inner square state] __forceinline unsigned int Square(unsigned int file, unsigned int rank) {return (rank<<3) | file;} __forceinline unsigned int Rank (unsigned int sq) {return sq >> 3;} __forceinline unsigned int File (unsigned int sq) {return sq & 7;} __forceinline BitBoard FileAttacks(unsigned int sq) const { return sFileAtta[sq][(*(((BYTE*)&(m_Inc.m_OccuBB90))+File(sq)) >> 1) & 0x3f]; } __forceinline BitBoard RankAttacks(unsigned int sq) const { return sRankAtta[sq][(*(((BYTE*)&(m_Inc.m_PieceBB[ALLPIECES]))+Rank(sq)) >> 1) & 0x3f]; } __forceinline BitBoard A1H8Attacks(unsigned int sq) const { return sA1H8Atta[sq][(*(((BYTE*)&(m_Inc.m_OccuBBA1H8))+((sq-Rank(sq)) & 7)) >> 1) & 0x3f]; // (file-rank) & 7 } __forceinline BitBoard H1A8Attacks(unsigned int sq) const { return sH1A8Atta[sq][(*(((BYTE*)&(m_Inc.m_OccuBBH1A8))+(((~sq)-Rank(sq)) & 7)) >> 1) & 0x3f];// (mirrorfile-rank) & 7 } ... Gerd
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.