Hi there,
I have Stockfish working well with a silverlight project. If an illegal move gets entered somehow the program straight up crashes even if I have a try catch. In the C++ code there are asserts, like is_ok, move_isok(I think thats what its called). Anyways, I wasn;t sure what to do so in the C++ code if the move happens to be MOVE_NULL I simply do a cout << "Invalid move" just before the asserts and exit out right away. My UI can handle the Invalid Move text coming back. Other chess GUI's probably handle the asserts other ways so the program doesnt crash but I'm not sure how it's done.
Thanks much for any ideas other than what I've done.
David
Illegal Move handling
Moderators: hgm, Rebel, chrisw
-
- Posts: 85
- Joined: Sun May 29, 2011 11:56 pm
- Location: San Diego
-
- Posts: 4052
- Joined: Thu May 15, 2008 9:57 pm
- Location: Berlin, Germany
- Full name: Sven Schüle
Re: Illegal Move handling
The assert's are only active in a debug version. Also successfully using try/catch requires to compile with exception handling enabled, which is not the default for most chess programs.whittenizer wrote:Hi there,
I have Stockfish working well with a silverlight project. If an illegal move gets entered somehow the program straight up crashes even if I have a try catch. In the C++ code there are asserts, like is_ok, move_isok(I think thats what its called). Anyways, I wasn;t sure what to do so in the C++ code if the move happens to be MOVE_NULL I simply do a cout << "Invalid move" just before the asserts and exit out right away. My UI can handle the Invalid Move text coming back. Other chess GUI's probably handle the asserts other ways so the program doesnt crash but I'm not sure how it's done.
Thanks much for any ideas other than what I've done.
I guess you are talking about a "position fen XXX moves YYY" command where YYY contains any illegal move. Stockfish seems to rely on the GUI to provide legal moves only. In uci.cpp it has:
Code: Select all
pos.do_setup_move(move_from_uci(pos, token));
To solve your problem I would perhaps try something like this in uci.cpp, at the end of function set_position():
Code: Select all
while (up >> token)
{
Move m = move_from_uci(pos, token);
if (m != MOVE_NONE)
{
pos.do_setup_move(m);
}
else return;
}
Sven
-
- Posts: 2684
- Joined: Sat Jun 14, 2008 9:17 pm
Re: Illegal Move handling
The fundamental philosphy seems a bit changhed in the latest versionSven Schüle wrote: I think this looks slightly inconsistent but may also be part of fundamental philosophy.
Code: Select all
// Parse move list (if any)
while (is >> token && (m = move_from_uci(pos, token)) != MOVE_NONE)
{
pos.do_move(m, *SetupState);
-
- Posts: 85
- Joined: Sun May 29, 2011 11:56 pm
- Location: San Diego
Re: Illegal Move handling
Hi there,
I actually did something very similar. In the while loop I check for null move and simply do a cout for my UI and then return.
Awesome. Thanks for the info
I actually did something very similar. In the while loop I check for null move and simply do a cout for my UI and then return.
Awesome. Thanks for the info
-
- Posts: 85
- Joined: Sun May 29, 2011 11:56 pm
- Location: San Diego
Re: Illegal Move handling
HI,
This is pretty much what I've done but added the cout for my UI.
Thanks so much for the reply.
David
This is pretty much what I've done but added the cout for my UI.
Thanks so much for the reply.
David
-
- Posts: 85
- Joined: Sun May 29, 2011 11:56 pm
- Location: San Diego
Re: Illegal Move handling
Just wanted to add that my Silverlight GUI is not UCI compliant. It's able to handle most interactions from the engine. As I progress I'll make it fully UCI compliant. For now I'm finally able to interact with the engine in some form.
Thanks for the ideas.
David
Thanks for the ideas.
David
-
- Posts: 4052
- Joined: Thu May 15, 2008 9:57 pm
- Location: Berlin, Germany
- Full name: Sven Schüle
Re: Illegal Move handling
I looked at 2.1. Of course I should have used the most recent version (now I downloaded 2.2.1), but the behaviour reported by David matched what I saw so I was lazy and assumed he had the latest SF which would the same code. I know I should not "assume" ...mcostalba wrote:The fundamental philosphy seems a bit changhed in the latest versionSven Schüle wrote: I think this looks slightly inconsistent but may also be part of fundamental philosophy.
Code: Select all
// Parse move list (if any) while (is >> token && (m = move_from_uci(pos, token)) != MOVE_NONE) { pos.do_move(m, *SetupState);
Thanks also for your fundamental change
Sven
-
- Posts: 4052
- Joined: Thu May 15, 2008 9:57 pm
- Location: Berlin, Germany
- Full name: Sven Schüle
Re: Illegal Move handling
Note that "null move" (MOVE_NULL) and "no move" (MOVE_NONE) is not the same, look at "types.h". In case of illegal move handling of Stockfish the relevant constant is MOVE_NONE.whittenizer wrote:I actually did something very similar. In the while loop I check for null move and simply do a cout for my UI and then return.
Sven
-
- Posts: 27795
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: Illegal Move handling
Also known as MOVE_NONCOMPLIANT.
-
- Posts: 85
- Joined: Sun May 29, 2011 11:56 pm
- Location: San Diego
Re: Illegal Move handling
Yes, I made a typo. Imeant MOVE_NONE.
Thanks much,
David
Thanks much,
David