Evert wrote:lucasart wrote:
Also regarding rules used to initialize the generation, are these rules
100% correct at detecting a draw ? (even if the white pawn is on the 2nd rank and/or on a rook file)
- Black king directly in front of the pawn, white king directly behind it, black to move.
- Black king directly in front of the pawn, white king diagonally behind the pawn, white to move.
Can't you use
key squares to test that more generally?
I am not looking to generalize or complicate the rules so that I can predict all with static rules. This would lead to an immense and incomprehensible code base (that would almost certainly be buggy too). I want to have a few basic and simple rules that are 100% accurate for the first iteration. Then I will generate the bitbase iteratively. Here are the fules I've coded so far:
Code: Select all
int rules(unsigned idx)
{
assert(idx < IndexMax);
int wk, bk, stm, wp;
decode(idx, &wk, &bk, &stm, &wp);
// pieces overlapping or kings checking each other
if (kdist(wk, bk) <= 1 || wp == wk || wp == bk)
return ILLEGAL;
// cannot be white's turn if black is in check
if (stm == WHITE && test_bit(PAttacks[WHITE][wp], bk))
return ILLEGAL;
// black king can capture the pawn immediately
if (stm == BLACK && test_bit(KAttacks[bk], wp) && !test_bit(KAttacks[wk], wp))
return DRAW;
// rule of the square (unstoppable passer)
const int psq = square(RANK_8, file(wp));
if (kdist(bk, psq) - (stm == BLACK) > RANK_8 - rank(wp))
return WIN;
// black king in front of the pawn
if (wp+8 == bk) {
// white king behind the pawn, black to move
if (stm == BLACK && wk+8 == wp)
return DRAW;
// white king diagonally behind the pawn, white to move
if (stm == WHITE && test_bit(PAttacks[BLACK][wp], wk))
return DRAW;
}
return UNKNOWN;
}
Results of applying these rules to the N = 64*64*24*2 positions:
Code: Select all
30932 ILLEGAL
74355 UNKNOWN
9164 DRAW
82157 WIN
Now I need to code the iteration part.
I should have some total results soon
**edit** Just realized that my "rule of the square" implementation is wrong. White king should be outside of the promotion path... obviously...
Theory and practice sometimes clash. And when that happens, theory loses. Every single time.