Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Bitboards generate moves King, Knight

Author: Gerd Isenberg

Date: 12:45:15 09/21/04

Go up one level in this thread


On September 21, 2004 at 15:07:33, Russell Reagan wrote:

>On September 21, 2004 at 06:57:37, Gerd Isenberg wrote:
>
>>>enum { white, black };
>>>
>>>// pawn moves forward
>>>pawnMoves = (pawns << 8) >> (16 * side);
>
>>Yes, this "generalized" shift by one rank works well for pawns, because they
>>don't occupy first or eight rank.
>>
>>BitBoard pawnPushTargets(BitBoard pawns, int side) {
>>  return (pawns << 8) >> (16 * side);
>>}
>>
>>What about left and right pawn attacks with this trick?
>
>Maybe something like this? I didn't have time to test it right now.
>
>enum { white, black };
>
>// For this function, left means left from white's point of view.
>// Examples of pawn attacks left: e4d5 for white
>//                                e4d3 for black
>
>Bitboard PawnAttacksLeft (Bitboard pawns, int side)
>{
>    return ((pawns << 7) >> (16 * side)) & notFileH;
>}

Yep!

I first had some vague concerns about the right pawn case.

  return ((pawns << 9) >> (16 * side)) & notFileA;

That a black pawn on the seventh rank is first shifted left off the board.

That really happens with the h7 pawn.
But exactly this rook pawn has of course no attacks in the right direction ;-)

rdtsc test of your code: 13 (14) cycles

I guess for such small cycle counts are a bit error prone.
But loop tests ( ) with i&1 side confirm the trend.

The conditional one:

BitBoard leftPawnAttacks(BitBoard pawns, int side)
{
   if ( side )
      return (pawns << 7) & 0x7f7f7f7f7f7f7f7f;
   return (pawns >> 9) & 0x7f7f7f7f7f7f7f7f;
}

rdtsc test: 7(5) cycles predicted
           20 cycles miss predicted

Cheers,
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.