glinscott / Garbochess-JS

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

Crash analyzing position #2

Closed glinscott closed 13 years ago

glinscott commented 13 years ago

FEN: 8/7R/p3k2B/Krn1p3/1p6/8/PP6/3R4 w - - 3 4 Crashes

casaschi commented 13 years ago

Hello, I'm the author of the pgn4web tool that emailed you about this issue.

I think I found a fix, just look at file garbochess.js and where you define function "PVFromHash" just add a check for "move" to be defined (similarly to what it's already done for ply), like this:

function PVFromHash(move, ply) {
    if (! move)
        return "";

    if (ply == 0) 
        return "";

    ...
}

This seems to fix the issue.

glinscott commented 13 years ago

Thanks, yes, the issue is the search is not returning a best move (it wasn't getting stored in the hashtable)

casaschi commented 13 years ago

I saw your change and I have a small issue, since your change does NOT send a PV message when analysing a checkmate position. conceptually true, but the GUI does not know what the evaluation is. The fix I proposed, instead, would send back a PV message with the proper checkmate evaluation (and an empty PV) to the GUI that can tell the user there's a checkmate... this works much better in my case. While not strictly a PV message, it would be a generalized PV message where the PV is an empty string :-)

glinscott commented 13 years ago

Good point! I think the issue is that mate scores from qsearch don't get stored. I'll commit a better fix in a few hours.

On Jul 23, 2011, at 1:44 PM, casaschireply@reply.github.com wrote:

I saw your change and I have a small issue, since your change does NOT send a PV message when analysing a checkmate position. conceptually true, but the GUI does not know what the evaluation is. The fix I proposed, instead, would send back a PV message with the proper checkmate evaluation (and an empty PV) to the GUI that can tell the user there's a checkmate... this works much better in my case. While not strictly a PV message, it would be a generalized PV message where the PV is an empty string :-)

Reply to this email directly or view it on GitHub: https://github.com/glinscott/Garbochess-JS/issues/2#issuecomment-1638115

glinscott commented 13 years ago

I just used your fix. Easiest way to deal with checkmate positions :). Thanks!

casaschi commented 13 years ago

Sorry to be a pain... but you should not return "checkmate" as the pv, either you return an empty string or you deal with the other alternative case where no moves are possible... statelmate... try this FEN with the new code: 5k2/5P2/5K2/8/8/8/8/8 b - - 0 1

glinscott commented 13 years ago

Indeed! Simple fix to detect stalemate, I just added that.

casaschi commented 13 years ago

looks perfect now, thanks!