Wing Lee wrote:hi everyone,
quite a few sites tell me to forget about the in check test during search,
Which sites are these? It seems like a bad idea to me, and I am pretty sure almost all programs do an in check test at all nodes. I don't see any good reason to skip the test. Testing whether the side to move is a very cheap operation.
also, as an aside, is there a good way to generate valid castling moves? do we need to do the incheck test for every square the king will pass by? i can't seem to read about a good procedure anywhere.
Just do it in whatever way you think is most natural, and don't worry about speed. Castling moves are just a tiny minority of all the moves your program generates during the search, and even if you generate them in a very slow and inefficient way it will not slow down your program noticably. FWIW, here is my code for generating castling moves:
- Code: Select all
if(!SearchStack[Ply].check) {
if(OO_POSSIBLE(Side)) {
int e1=E1+Side*A8, f1=F1+Side*A8, g1=G1+Side*A8;
if(Board[f1]==EMPTY && Board[g1]==EMPTY &&
!is_attacked(f1, XSide) && !is_attacked(g1, XSide))
(ms++)->move = (KING<<17)|(e1<<7)|g1;
}
if(OOO_POSSIBLE(Side)) {
int e1=E1+Side*A8, d1=D1+Side*A8, c1=C1+Side*A8, b1=B1+Side*A8;
if(Board[d1]==EMPTY && Board[c1]==EMPTY && Board[b1]==EMPTY &&
!is_attacked(d1, XSide) && !is_attacked(c1, XSide))
(ms++)->move = (KING<<17)|(e1<<7)|c1;
}
}
'Side' is the side to move, 'XSide' is the other side. The OO_POSSIBLE and OOO_POSSIBLE macros simply test whether the side to move still has the right to castle kingside or queenside. As you can see, I simply look at the squares between the king and rook and check that they are empty and not attacked by the opponent, and generate a castling move if everything is OK.
Tord