glinscott / Garbochess-JS

A strong javascript chess engine using WebWorkers
http://forwardcoding.com/projects/ajaxchess/chess.html
Other
310 stars 100 forks source link

pv move on checkmate #9

Closed casaschi closed 11 years ago

casaschi commented 12 years ago

Kind of an odd situation, more than anything else it does not look nice.

Enter this FEN in Garbochess-JS and start analyzing: k6R/8/K7/8/8/8/8/8 w - - 0 1

It's already checkmate, so it should just report the position as illegal instead it announces the "checkmate" max score, and also provides the PV as "Rg8#".

Also this FEN is already checkmate: kb6/8/KN6/8/8/8/8/8 w - - 0 1 Here Garbochess-JS happily goes on with Nd7

glinscott commented 12 years ago

Thanks, there is just no check at the root for mate positions. Should be an easy fix!

casaschi commented 12 years ago

good.

since you are looking into this, it might be worth doing a better check for "invalid" FEN strings in general, I've seen some go through and causing exceptions later, such as fischerandom FENs with white rooks in b1 and g1 and castling rights KQ, finally confusing garbochess (that in fact should reject the FEN)... but maybe I'm asing for too much

glinscott commented 12 years ago

I think the biggest thing is verifying that castling is legal in the given position. That's easy to check, if king and rooks are on original squares, all is well. Should have a chance to take a look at this something this week.

casaschi commented 12 years ago

Any plans to fix this issue anytime soon? I'm preparing a new version of my chrome extension, I thought of asking before releasing...

glinscott commented 12 years ago

Sorry, this is one of those things where "this week" turned into "forgot about it" :). Probably not any time soon, I haven't had much free time lately.

glinscott commented 11 years ago

So, I didn't realize that in the original FENs it was possible to capture the king. These are not legal FENs, so adding code to check for that would be more work. I did add a check for checkmate/stalemate though: 8213a2e.

I'm not sure how far I should go on the legal FEN detection. I don't think it's too likely for someone to paste an invalid checkmate FEN in?

casaschi commented 11 years ago

For my purposes, a checkmate/stalemate check should be enough. I wanted to have a function that allows to switch the side to move, this might generate an invalid FEN if the new side to move is giving check. In that case garbochess was starting analyzing anyway and that looked funny. Thanks for this fix anyway.

casaschi commented 11 years ago

...But I see you patched your UI only, it would be nice if the garbochess.js also refused to start analyzing the invalid FEN returning some kind of error

casaschi commented 11 years ago

On second thought... I might have found an easy way to avoid the issue from my UI, checking for checks before switching sides as you do in your UI. Still, as a safety net, it would be nice for the engine to notice the illegal FEN input.

glinscott commented 11 years ago

I've added some detection for invalid castling rights, and checkmate/king-capture invalid FENs.

InitializeFromFen() will return a string describing the FEN error. If running garbochess as a worker, it will return a message with "message ..." which describes the error.