Moderator: Andres Valverde
Dann Corbit wrote:queencount <= 9 for each side
rookcount bishopcount and knightcount <= 10 for each side
pawncount <= 8 for each side
Dann Corbit wrote:no other symbols in castling rights
Dann Corbit wrote:e.p. file 1-8
e.p. rank 3 or 6
Peter Fendrich wrote:We can of course blame the GUI that let such positions pass but...
What do you do in these cases?
/*isIllegalPosition()
*Determines whether the position is legal.
*The position can be illegal, but it must be legal enough for the engine to
*work without errors
*
*@returns true if the position is illegal
*/
bool isIllegalPosition()
{
//check if the number of Kings on each side is ok
if(popCount(piecesSide(mainboard,K))!=1 || popCount(piecesXSide(mainboard,K))!=1)
{
if(!openedInConsole)
printf("tellusererror Illegal Position: Wrong number of kings.\n");
return true;
}
//make sure the opposing side is not in check
if(inCheck(mainboard,mainboard.xside))
{
if(!openedInConsole)
printf("tellusererror Illegal Position: Opposite side in Check.\n");
return true;
}
//make sure the ep square matches with an ep pawn
if(mainboard.EP)
{
//if white just moved
if(mainboard.side && !((mainboard.EP>>8)&(mainboard.PiecesSide[WHITE]&mainboard.Pieces[P])))
{
if(!openedInConsole)
printf("tellusererror Illegal Position: Bad E.P. square\n");
return true;
}
//if black just moved
if(!((mainboard.EP<<8)&(mainboard.PiecesSide[BLACK]&mainboard.Pieces[P])))
{
if(!openedInConsole)
printf("tellusererror Illegal Position: Bad E.P. square\n");
return true;
}
}
//edit castling legality if the king and rook positions are to the contrary
if(hasCastlingPrivilages(mainboard,WHITE))
{
if(!(mainboard.Pieces[K]&mainboard.PiecesSide[WHITE]&toBit[4]))
mainboard.castling&=notAllCastlingBitsSide[WHITE];
else
{
if((mainboard.castling&WK) && !(mainboard.Pieces[R]&mainboard.PiecesSide[WHITE]&toBit[7]))
mainboard.castling&=notCastlingBits[WHITE][KINGSIDE];
if((mainboard.castling&WQ) && !(mainboard.Pieces[R]&mainboard.PiecesSide[WHITE]&toBit[0]))
mainboard.castling&=notCastlingBits[WHITE][QUEENSIDE];
}
}
if(hasCastlingPrivilages(mainboard,BLACK))
{
if(!(mainboard.Pieces[K]&mainboard.PiecesSide[BLACK]&toBit[56+4]))
mainboard.castling&=notAllCastlingBitsSide[BLACK];
else
{
if((mainboard.castling&BK) && !(mainboard.Pieces[R]&mainboard.PiecesSide[BLACK]&toBit[56+7]))
mainboard.castling&=notCastlingBits[BLACK][KINGSIDE];
if((mainboard.castling&BQ) && !(mainboard.Pieces[R]&mainboard.PiecesSide[BLACK]&toBit[56+0]))
mainboard.castling&=notCastlingBits[BLACK][QUEENSIDE];
}
}
return false;
}
Peter Fendrich wrote:In Arena it is possible to feed the engine with all sorts of positions. For instance the "wrong" side is in check or one King is missing etc.
Fabien Letouzey wrote:Hi Peter,Peter Fendrich wrote:In Arena it is possible to feed the engine with all sorts of positions. For instance the "wrong" side is in check or one King is missing etc.
Sending a bug report to the Arena team would be a useful step in any case. UCI interfaces are not allowed to send illegal positions to engines.
Fabien.
David Mitchell wrote:Y'all mostly answered how to test if a position is legal or not. Which is just not the same thing, really. Very interesting, for sure, but not the question at hand.
Dann Corbit wrote:Sometimes, illegal positions are wanted.
It is fun to solve positions that can never occur in a real game.
http://membres.lycos.fr/albillo/
I think an engine should know what it can handle and what it can't and this discussion shows a hole in both the Winboard and UCI protocol for setboard type of operations.
The interface should look for an "illegal" response from the engine.
Also, the variants might be expanded. If your program can handle 64 chessmen or expanded boards or other crazy things there should be a way to communicate that also.
Peter Fendrich wrote:What do you think is the best way of handling obvious illegal positions?
(I'm talking about UCI here and positions that can't be played with normal chess rules)
Return to Programming and Technical Discussions
Users browsing this forum: No registered users and 42 guests