1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
// Pieces :
#define BISHOP 1 // Fou
#define ROOK 2 // Tour
#define QUEEN 3 // Dame
#define OUT 8 // case "au dehors" de l'echiquier
enum {
NORTH=1, SOUTH=-1,
EAST=10, WEST=-10,
SE=9 , NW=-9,
NE=11 , SW=-11
};
// Echiquier :
signed char board[120]={
OUT, OUT, OUT, OUT, OUT, OUT, OUT, OUT, OUT, OUT,
OUT, OUT, OUT, OUT, OUT, OUT, OUT, OUT, OUT, OUT,
OUT, 0, 0, 0, 0, 0, 0, 0, 0, OUT,
OUT, 0, 0, 0, 0, 0, 0, 0, 0, OUT,
OUT, 0, ROOK, 0, 0, 0, 0, 0, 0, OUT,
OUT, 0, 0, 0, QUEEN, 0, 0, 0, 0, OUT,
OUT, 0, 0, 0, 0, 0, 0, 0, 0, OUT,
OUT, 0, 0, 0, 0, 0, 0, 0, 0, OUT,
OUT, 0, 0, 0, 0, 0,-BISHOP, 0, 0, OUT,
OUT, 0, 0, 0, 0, 0, 0, 0, 0, OUT,
OUT, OUT, OUT, OUT, OUT, OUT, OUT, OUT, OUT, OUT,
OUT, OUT, OUT, OUT, OUT, OUT, OUT, OUT, OUT, OUT,
};
#define XorTour(square,tab,bit,i) \
i=square+NORTH ; while( !board[i] ) { tab[i]^=bit; i+=NORTH; } tab[i]^=bit; \
i=square+SOUTH ; while( !board[i] ) { tab[i]^=bit; i+=SOUTH; } tab[i]^=bit; \
i=square+EAST ; while( !board[i] ) { tab[i]^=bit; i+=EAST; } tab[i]^=bit; \
i=square+WEST ; while( !board[i] ) { tab[i]^=bit; i+=WEST; } tab[i]^=bit;
#define XorFou(square,tab,bit,i) \
i=square+NO ; while( !board[i] ) { tab[i]^=bit; i+=NO; } tab[i]^=bit; \
i=square+NE ; while( !board[i] ) { tab[i]^=bit; i+=NE; } tab[i]^=bit; \
i=square+SO ; while( !board[i] ) { tab[i]^=bit; i+=SO; } tab[i]^=bit; \
i=square+SE ; while( !board[i] ) { tab[i]^=bit; i+=SE; } tab[i]^=bit;
// mark/unmark all the squares that are attacked by "piece"
// piece : BISHOP or ROOK or QUEEN
// square : square of the piece
// tab : unsigned[120] , ( tab[x] & bit ) != 0 <=> square x is attacked by piece
// bit : in { 1, 2, 4, ..., 2^15 } , bit corresponding to the piece that is being moved
void XorSlidingPiece(const unsigned piece,const int square,unsigned * const tab,const unsigned bit)
{
int i;
if( piece ^ BISHOP ) // not a BISHOP => QUEEN || ROOK
{
XorTour(square,tab,bit,i);
}
if( piece ^ ROOK ) // not a ROOK => QUEEN || BISHOP
{
XorFou(square,tab,bit,i);
}
}
// Inline versions : not faster
#define XorTour(sq,tab,bit,i) \
tab[sq+NORTH]^=bit; if( !board[sq+NORTH] ) { tab[sq+2*NORTH]^=bit; if( !board[sq+2*NORTH] ) { tab[sq+3*NORTH]^=bit; if( !board[sq+3*NORTH] ) { tab[sq+4*NORTH]^=bit; if( !board[sq+4*NORTH] ) { tab[sq+5*NORTH]^=bit; if( !board[sq+5*NORTH] ) { tab[sq+6*NORTH]^=bit; if( !board[sq+6*NORTH] ) tab[sq+7*NORTH]^=bit; } } } } } \
tab[sq+SOUTH]^=bit; if( !board[sq+SOUTH] ) { tab[sq+2*SOUTH]^=bit; if( !board[sq+2*SOUTH] ) { tab[sq+3*SOUTH]^=bit; if( !board[sq+3*SOUTH] ) { tab[sq+4*SOUTH]^=bit; if( !board[sq+4*SOUTH] ) { tab[sq+5*SOUTH]^=bit; if( !board[sq+5*SOUTH] ) { tab[sq+6*SOUTH]^=bit; if( !board[sq+6*SOUTH] ) tab[sq+7*SOUTH]^=bit; } } } } } \
tab[sq+EAST ]^=bit; if( !board[sq+EAST ] ) { tab[sq+2*EAST ]^=bit; if( !board[sq+2*EAST ] ) { tab[sq+3*EAST ]^=bit; if( !board[sq+3*EAST ] ) { tab[sq+4*EAST ]^=bit; if( !board[sq+4*EAST ] ) { tab[sq+5*EAST ]^=bit; if( !board[sq+5*EAST ] ) { tab[sq+6*EAST ]^=bit; if( !board[sq+6*EAST ] ) tab[sq+7*EAST ]^=bit; } } } } } \
tab[sq+OUEST]^=bit; if( !board[sq+OUEST] ) { tab[sq+2*OUEST]^=bit; if( !board[sq+2*OUEST] ) { tab[sq+3*OUEST]^=bit; if( !board[sq+3*OUEST] ) { tab[sq+4*OUEST]^=bit; if( !board[sq+4*OUEST] ) { tab[sq+5*OUEST]^=bit; if( !board[sq+5*OUEST] ) { tab[sq+6*OUEST]^=bit; if( !board[sq+6*OUEST] ) tab[sq+7*OUEST]^=bit; } } } } }
#define XorFou(sq,tab,bit,i) \
tab[sq+NW]^=bit; if( !board[sq+NW] ) { tab[sq+2*NW]^=bit; if( !board[sq+2*NW] ) { tab[sq+3*NW]^=bit; if( !board[sq+3*NW] ) { tab[sq+4*NW]^=bit; if( !board[sq+4*NW] ) { tab[sq+5*NW]^=bit; if( !board[sq+5*NW] ) { tab[sq+6*NW]^=bit; if( !board[sq+6*NW] ) tab[sq+7*NW]^=bit; } } } } } \
tab[sq+NE]^=bit; if( !board[sq+NE] ) { tab[sq+2*NE]^=bit; if( !board[sq+2*NE] ) { tab[sq+3*NE]^=bit; if( !board[sq+3*NE] ) { tab[sq+4*NE]^=bit; if( !board[sq+4*NE] ) { tab[sq+5*NE]^=bit; if( !board[sq+5*NE] ) { tab[sq+6*NE]^=bit; if( !board[sq+6*NE] ) tab[sq+7*NE]^=bit; } } } } } \
tab[sq+SW]^=bit; if( !board[sq+SW] ) { tab[sq+2*SW]^=bit; if( !board[sq+2*SW] ) { tab[sq+3*SW]^=bit; if( !board[sq+3*SW] ) { tab[sq+4*SW]^=bit; if( !board[sq+4*SW] ) { tab[sq+5*SW]^=bit; if( !board[sq+5*SW] ) { tab[sq+6*SW]^=bit; if( !board[sq+6*SW] ) tab[sq+7*SW]^=bit; } } } } } \
tab[sq+SE]^=bit; if( !board[sq+SE] ) { tab[sq+2*SE]^=bit; if( !board[sq+2*SE] ) { tab[sq+3*SE]^=bit; if( !board[sq+3*SE] ) { tab[sq+4*SE]^=bit; if( !board[sq+4*SE] ) { tab[sq+5*SE]^=bit; if( !board[sq+5*SE] ) { tab[sq+6*SE]^=bit; if( !board[sq+6*SE] ) tab[sq+7*SE]^=bit; } } } } } |
Partager