notnil / chess

chess package for go
MIT License
508 stars 126 forks source link

UCI engine.Run fails to return search result when the position being searched is checkmate #138

Open tarunbod opened 3 months ago

tarunbod commented 3 months ago

When running the following code where pos is a checkmate position:

cmdPosition := uci.CmdPosition{Position: pos}
cmdGo := uci.CmdGo{Depth: depth}
if err := engine.Run(cmdPosition, cmdGo); err != nil {
    panic(err)
}

The error encountered is:

chess: failed to decode long algebraic notation text \"(none)\" for position <nil>

This is because when a checkmate position is supplied to an engine, the go command returns the following output (> signifies an input line, < signifies output):

> position fen 1nb5/1p1pk1p1/5n2/1p2K3/4p3/2b5/5r2/r7 w - - 6 28
> go depth 20
< info string NNUE evaluation using nn-ae6a388e4a1a.nnue (132MiB, (22528, 3072, 15, 32, 1))
< info string NNUE evaluation using nn-baff1ede1f90.nnue (6MiB, (22528, 128, 15, 32, 1))
< info depth 0 score mate 0
< bestmove (none)

It looks like the code is trying to parse the (none) in the last line of the UCI output as a valid position.

I think a good fix for this would be to simply parse the output such that engine.SearchResults() returns the zero-value uci.SearchResults struct.