[edit : SEE is used here to prune QS captures and to sort to tail quiet moves in full width search. ]
The codes here is a debug version of SEE that uses the QS move generator.
I just can't figure out why the commented asserts within see_search() were never triggered. I expect them to be triggered almost immediately.
Code: Select all
int see_search(const int at, const int side, const int see_side, int gain) {
move_t *move, list[256], targ = BRD_PC(at);
check_t check_s;
int x, pc, incheck;
assert(gain <= 0);/* why never triggered ? */
assert(gain + vPiece[targ] >= 0);
getSideIncheck(&check_s, side);
incheck = check_s.type;
/* If there is a discovered check, SEE stops.
*/
if (incheck && (check_s.sq ^ at || incheck == DBL_CHECK)) {
/* discovered check; returns */
if (gain > 0 && side ^ see_side) {
assert(0);/* why never triggered ? */
/* see side lost, but gives check; don't see prune. */
gain = 0;
}
return gain;
}
/* If no discovered check and gain > 0 returns. Others side failed to equalize material. */
if (gain > 0 || targ == King) {
assert(0);/* why never triggered ? */
return gain;
}
/* gen() must be in order of P/N/B/R/Q/K */
gen(list, side, GEN_QS_NO_EXCLUDE_CAPTURE, -INFI, 0);
for (move = list; *move; ++move) {
if (TO(*move) == at && is_move_valid(*move, side, incheck)) {
/* if captures does not equalize material, SEE stops and the side lost. The exception is when a
* move gives indirect check.
* So must call see_search() to determine if there is a discovered check; even for King's move
* that may fail to equalize..
* */
gain += vPiece[targ];
pc = BRD_PC(FROM(*move));
if ((gain >= 0 && pc == King) || (gain - vPiece[pc] > 0)) {/* side wins */
return gain;
}
if (gain < 0) {
if (side == see_side); /* call see_search to determine if indirect check oppn */
else {
return gain;
}
}
makemove(*move, side);
x = -see_search(at, side ^ 1, see_side, -gain);
assert(x > -INFI && x < INFI);
unmake(*move, side);
return x; /* gain */
}
}
return gain;
}
int debug_see(const move_t move, const int side, const int incheck) {
int x, gain, at = TO(move), targ = BRD_PC(at);
if (is_move_valid(move, side, incheck));
else return SEE_INVALID;
makemove(move, side);
gain = vPiece[targ];
x = -see_search(at, side ^ 1, side, -gain);
assert(x > -INFI && x < INFI);
unmake(move, side);
if (x < 0 ){
return SEE_PRUNE;
}
return 0;
}
Chan Rasjid.
