I don't think an engine should be required to accept illegal positions, but I think it is nicer to do so. You usually don't need to sacrifice much to support impossible things, including positions with more than 9 queens. If your user wants to play around with impossible positions, why not allow it?
I would say an engine is free to reject any unreachable position it likes. It should e.g. not be required to accept positions with 10 queens of the same color or with 9 pawns of the same color.
In practice it is not feasible for an engine to detect all cases where a position given to it is unreachable. As long as the engine does not crash, I do not see a problem in an engine accepting some and rejecting other unreachable positions.
So just test whether the given position is one that your data structures can cope with.
ericlangedijk wrote:Well. Some very good engines DO crash in some unreachable positions.
In my view they should not do that.
One could argue that engines are free to crash whenever being fed input that does not fully comply with the UCI protocol (and the rules of chess), but personally I don't agree with that.
But then again, I don't really like the UCI protocol. As far as I can tell, it makes it impossible to easily test basic engine features from the command line. I don't understand why there is no easy way to just input e2e4 into these engines. It gives me the cramped feeling of Windows even when I'm in a Linux terminal that normally gives me full freedom.
How to handle these illegal positions when entered in an engine?
Prepare for the worst and accept?
In general, behaviour should be undefined, if the position is impossible. For example, if there are pawns on the 1st 8-th rank, I'm sure some engines would crash or behave strangely.
And it's a waste of time to do input validation. Input should be correct, as it is supposed to come from a GUI not the fat fingers of the user.
However in the position you give, I don't see any god reason for an engine to have problems. Why should a programmer add an extra logic that detects that a double check by a knight and a pawn is impossible ?
Theory and practice sometimes clash. And when that happens, theory loses. Every single time.
// ...........
checkers.&or(bba_knight[wksq] and b_knights);
if checkers = 0 then // (skipping code example)
checkers.&or((bba_whitepawnhit[wksq] and b_pawns));
// .........
Last edited by ericlangedijk on Wed Aug 14, 2013 1:17 am, edited 1 time in total.