Code: Select all
int rook_mobility_white(int sq, int offsets[])
{
int p, *d = offsets, s = 0;
do {
for (p = sq + *d; board[p] == npiece && !pawn_attack(board[p], 0); p += *d)
s++;
} while (*++d);
if ((board[p] & 1) == 1)
s++;
return s;
}
Code: Select all
bool pawn_attack(int square, int color) {
/* this function will return TRUE if square "square" is attacked by a pawn
of color "color", and return FALSE otherwise */
int bishop_o[4] = { 11, -11, 13, -13 };
int a_sq, i;
/* white pawn attacks: */
if (color % 2) {
/* pawn-style moves: */
for (i = 0; i < 4; i++) {
a_sq = square + bishop_o[i];
/* check for pawn attacks: */
if (board[a_sq] == wpawn && i % 2)
return TRUE;
while (board[a_sq] != frame) {
if (board[a_sq] != npiece)
break;
a_sq += bishop_o[i];
}
}
/* if we haven't hit a white attacker by now, there are none: */
return FALSE;
}
/* black pawn attacks: */
else {
/* pawn-style moves: */
for (i = 0; i < 4; i++) {
a_sq = square + bishop_o[i];
/* check for pawn attacks: */
if (board[a_sq] == bpawn && !(i % 2))
return TRUE;
while (board[a_sq] != frame) {
if (board[a_sq] != npiece)
break;
a_sq += bishop_o[i];
}
}
/* if we haven't hit a black attacker by now, there are none: */
return FALSE;
}
}
