Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: sliding attacks in three inlines

Author: Dann Corbit

Date: 13:12:20 04/14/04

Go up one level in this thread


On April 14, 2004 at 15:52:39, Gerd Isenberg wrote:

>Hi Rasjid,
>
>i found a slight improvement in one of your three interesting sliding attack
>macros. It replaces the "inbetween"-expression
>
> isqBit(y)-1 & ~( isqBit(x)-1 | isqBit(x) )
>by
> isqBit(y) - isqBit(x+1)
>or
> isqBit(y) -(isqBit(x)<<1)
>
>If one subtracts power of two values, greater minus less:
>  0100 0000
> -0000 0100  the result is
> =0011 1100  a "inner" sequence of ones, except "less" is included.
>So we start with next greater bit of "less".
>
>Couldn't resist to use inlines instead of macros ;-)
>(not tested!)
>
>Cheers,
>Gerd
>
>
>typedef unsigned _int64		U64
>
>#define GetFile64(sq)             ((sq) & 7)
>#define GetRank64(sq)	          ((sq) >> 3)
>#define iGetFile(sq88)            ((sq88) & 7)
>#define iGetRank(sq88)            ((sq88) >> 4)
>#define sq88Bit(sq88)             ((U64)1 << (((sq88) + ((sq88) & 7)) >> 1))
>#define sq64Bit(sq64)	          (((U64)1) << (sq64))
>#define sq88RankBits(sq88)       ((U64)0xff << ((sq88) >> 1 & 0370))
>#define sq88FileBits(sq88)        ((U64) 0x0101010101010101 << ((sq88) & 7))
>
>//*** global variables
>U64 all, diagonal[2][15];
>
>inline // __forceinline
>bool brq_path_clear(int x, int y, U64 path) {
>   if (x < y) return ((isqBit(y) - isqBit(x+1)) & path & all) == 0;
>   if (x > y) return ((isqBit(x) - isqBit(y+1)) & path & all) == 0;
>   return false;
>}
>
>inline // __forceinline
>bool bstyle_attack(int x, int y) {
>   if ( iGetRank(x) + iGetFile(x) == iGetRank(y) + iGetFile(y) )
>      return brq_path_clear(x, y, diagonal[1][iGetRank(x) + iGetFile(x)]);
>   if ( iGetRank(x) - iGetFile(x) == iGetRank(y) - iGetFile(y) )
>      return brq_path_clear(x, y, diagonal[0][7 + iGetRank(x) - iGetFile(x)]);
>   return false;
>}
>
>inline // __forceinline
>bool rstyle_attack(int x, int y) {
>   if ( iGetRank(x) == iGetRank(y) )
>      return brq_path_clear(x, y, isqRankBits(x));
>   if ( iGetFile(x) == iGetFile(y) )
>      return brq_path_clear(x, y, isqFileBits(x));
>   return false;
>}

Instead of macros, I would just spell out the code.  Function macros give me the
heebie-jeebies.

typedef unsigned _int64		U64

U64 all, diagonal[2][15];

inline
bool brq_path_clear(int x, int y, U64 path) {
   if (x < y) return ((isqBit(y) - isqBit(x+1)) & path & all) == 0;
   if (x > y) return ((isqBit(x) - isqBit(y+1)) & path & all) == 0;
   return false;
}

inline
bool bstyle_attack(int x, int y) {
   if ( ((x) >> 4) + ((x) & 7) == ((y) >> 4) + ((y) & 7) )
      return brq_path_clear(x, y, diagonal[1][((x) >> 4) + ((x) & 7)]);
   if ( ((x) >> 4) - ((x) & 7) == ((y) >> 4) - ((y) & 7) )
      return brq_path_clear(x, y, diagonal[0][7 + ((x) >> 4) - ((x) & 7)]);
   return false;
}

inline
bool rstyle_attack(int x, int y) {
   if ( ((x) >> 4) == ((y) >> 4) )
      return brq_path_clear(x, y, isqRankBits(x));
   if ( ((x) & 7) == ((y) & 7) )
      return brq_path_clear(x, y, isqFileBits(x));
   return false;
}




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.