I have been writing a 0x88 move generation scheme over the past few weeks. I read that one of the advantages was the speed up for 'In check' detection.
I made an array[256] that sets the correct piece bits depending on the delta between squares, and add 128 to make all -ve deltas +ve.
So far, I have only a skeleton for the function, because of an efficiency problem.
- Code: Select all
int sq_attacked(int sq)
{
//---assign opposing side
int oside = 1 - ourside;
//---integers
register int i, tdet;
register const int delta = -sq + 128;
if (oside == WHITE)
{
for( i = 0;i < 64; ++i)
{
if (ISWHITE(game_board[board_index[i]]))
{
if (attackarray[board_index[i]+delta] & game_board[board_index[i]])
{
/*
we've found a possible attack
*/
//------one square pieces fist-----------//
if (ISPAWN(game_board[board_index[i]]) ||
ISKNIGHT(game_board[board_index[i]]) ||
ISKING(game_board[board_index[i]]) )
{
return TRUE;
}
...............
etc etc...... and now the next part should deal with pieces not adjacent to sq.
For example, sq = H8 and there is a wBishop on A1.
if (attackarray[board_index[i]+delta] & game_board[board_index[i]])
will be true, but the function needs to check B2, C3, D4 etc. to see if the diagonal is empty.
How is this done efficiently? The problem, as I see it, is that the function doesn't 'know' that this is a diagonal - to do this, I tried a structure with
- Code: Select all
typedef struct lookupdelta {
int d, int diff
};
where 'd' is the difference (H8-A1) and diff is the ray direction to loop from to check the diagonal. The structure is pre-computed when the program boots.
This all seems a bit slow to me?
Am I missing a simple solution?
For reference,
- Code: Select all
#define ISEMPTY(sq) ((sq)&1)
#define ISPIECE(sq) ((sq)&2)
#define ISWHITE(sq) ((sq)&4)
#define ISBLACK(sq) ((sq)&8)
#define ISSLIDE(sq) ((sq)&16)
#define ISPAWN(sq) ((sq)&32)
#define ISKNIGHT(sq) ((sq)&64)
#define ISKING(sq) ((sq)&128)
#define ISBISHOP(sq) ((sq)&256)
#define ISROOK(sq) ((sq)&512)
#define ISQUEEN(sq) ((sq)&1024)
#define OFFBOARD(sq) ((sq)&0x88)
const int board_index[64] = {
0,1,2,3,4,5,6,7,
16,17,18,19,20,21,22,23,
32,33,34,35,36,37,38,39,
48,49,50,51,52,53,54,55,
64,65,66,67,68,69,70,71,
80,81,82,83,84,85,86,87,
96,97,98,99,100,101,102,103,
112,113,114,115,116,117,118,119
};
Thanks,
Richard