Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: sliding attacks in three #define

Author: Gerd Isenberg

Date: 04:57:59 04/09/04

Go up one level in this thread


On April 09, 2004 at 06:13:45, rasjid chan wrote:

<snip>
>
>Hi,
>
>How can we have #define that extends to the nexct line. My consultant
>newphew just back from Australia with a BSc(Computer Science) also
>said cannot be done. So just to make the appear on a page, I just
>have to cut them to the next line.


use backslashes:

#define 	brq_path_clear(x, y, path)                              \
	((x) <= (y)                                                     \
	? ((x) == (y)  || isqBit(y) - 1 & ~(isqBit(x) - 1 | isqBit(x))  \
          &     (path)        & all ? 0 : 1)                            \
		: (isqBit(x) - 1 & ~(isqBit(y) - 1 | isqBit(y))         \
                   & (path) & all ? 0 : 1))


or use typesafe inline functions ;-)

<snip>
>
>>
>>As far as i understand they act like boolean functions, whether two squares are
>>connected on an appropriate ray, or whether y is attacked by a bishop/rook on x
>>(or vice versa).
>>
>>So you do something like ...
>>
>
>Since you asked, I doubled checked that they have no bugs. Yes,
>I debug at every root nodes in debug auto play for non-stop games
>and they are compared to simple attacks using standard 0x88 style
>of sliding from square x to y and checked if they are not stopped.
>
>
>
>>bool isAttacked(BitBoard all, int targetSq, int sourceSq)
>>{
>>    // precondition: both squares share a common ray
>
>This is basically what it is but no need for the preconditions.
>ie, as long as you have your all bits "all" updated, they are for real
>attacks. Yes Ithink it is call boolean as the macros evaluate to
>either 0 / 1. But we could easily adapt them to functions that
>return bits, etc if we want.
>
>take the simple "if" statement :-
>
>if (bstyle_attack(sq1, sq2)){
>
>//execution will enter here if and only if
> 1) sq1 and sq2 along diagonals and sq1 != sq2
> 2) no bits (all) in between or arc clear -
>    meaning the squares can attack as bishop-style.
>  any other combinations will not come here
>
>}
>
>>    BitBoard inbetween = bbSquaresInbetween[targetSq][sourceSq];
>>    return (inbetween & all) == 0;
>>}
>>
>>... but you want to get rid of the huge 64*64 array and do some computation...
>
>
>>
>>Where do you need that macros? To check the validity of a move (e.g. from
>>hashtable) or to genetate moves or attacks with it, as your subject title
>>suggests? It it would be interesting to see the usage of bstyle_attack(x,y) and
>>rstyle_attack(x,y) macros. How do you compute sliding attacks with this macros?
>
>I find it a little humorous that you ask about usage, just in case ...
>
>eg evaluation().
>Say we dont have attack-tables implemented and want to know
>if my side bishop at bs_sq  can attack opponent xside queen at q_sq.
>we use :-
>
>if (bstyle_attack(bs_sq, q_sq)){
>   score[side] += 20;
>}
>
>In move odering; say  we have a rook that has a safe move
>(sq_from - sq_to) and we want to know if it is also a check move :
>
>if (rstyle_attack(to, xside_king_sq)){
>   //move is a check move.
>}
>
>They are complete sliding attacks and need only an updated "all" bits
>


Is see, that is fine!
I thought your intention was to generate complete sliding attack bitboards with
you boolean functions like:

BitBoard getRookAttacks(int rookSquare)
{
    BitBoard attacks = 0;
    for (int target = 0; target < 64; target++)
    {
        if ( target != rookSquare && commonStraightRay(rookSquare, target) )
            if ( rstyle_attack(rookSquare, target) == 1 )
                 setBit (attacks, target);
    }
    return attacks;
}

That would be a bit inefficient ;-)

>>
>>I am not quite sure, but my feeling with your macros is, that they are a bit to
>>complicated and therefore difficult to read for me ;-)
>>
>>Note that those boolean statements
>>
>>   booleanExpression ? true : false
>>   booleanExpression ? 1 : 0
>>   booleanExpression
>>
>>are equivalent.
>>
>>Expressions with relational operators (==,!=,...) are boolean expressions with
>>the value range {0,1}, as well a boolean operators (&&,||,!).
>>
>>Cheers,
>>Gerd
>
>But then I'm not sure how other programmers use bitboards.
>I can adapt the above to do a sliding bitboard generator (a silly one)
>that extracts the 4 paths of the queen and then using x & - x
>get the bits(moves) one at a time; but tell me
>how I'm to convert a single bit back to squares w/o huge overhead,
>even Dr Hyatt cannot do it. So I can't understand exactly why the term
>"bitboard generators" are use and discussed.
>
>Rasjid

A matter of taste and thinking schemes/paradigms?

For some programmers Bitboards are evil - for others it's simply a (redundant?)
setwise presentation of several board/position patterns and to do setwise
operations like intersection or set unions with bitwise and/or and so on.

With some shift (and masking some possible board wraps) one performs a kind of
parallel vector addition, eg. if you have a set of white pawns you may perform:

whitePawnRightAttacks = (whitePawns << 9) & ~AFILE;
whitePawnLeftAttacks  = (whitePawns << 7) & ~HFILE;

If you have an array of white pawn squares and you want a target array of pawn
attack squares you have to do one loop, and instead of shift left seven/nine,
you add seven/nine per square and check for boards wraps or out of board each
time.

The problem you mentioned, is the so called serialization of bitboards to square
metric. One may use x & -x to isolate one bit and do a deBruin-multiplication
with some magic constant and shifting and lookup or most common for X86, some
inline assembly or intrinsic with bsf/bsr bitscan instructions.

Yes bitscan is relative expensive, there are bitboard engine designs where those
bitscans may be avoided, e.g. see Dann Corbit's idea:

http://www.talkchess.com/forums/1/message.html?359187

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.