For example, why doesn't the below code with an illegal FEN raise an exception? The code below DOESN'T print Oops like it should. How can I get Stockfish to raise an exception when an illegal FEN is given?
import chess
import chess.engine
engine = chess.engine.SimpleEngine.popen_uci("stockfish_10_x64.exe")
try:
with engine.analysis(chess.Board('5rk1/ppp2pbp/3pk1p1/1q6/4r1P1/1nPrBB2/PP2nPP1/R2QR2K')) as analysis:
for info in analysis:
print(info.get("score"), info.get("pv"))
# Unusual stop condition.
if info.get("hashfull", 0) > 50:
break
except:
print("oops")
engine.quit()
The UCI specification does not specify how to handle invalid input.
The UCI specification does not specify how to handle invalid input.
So there is no way to catch an illegal FEN?
GUIs should be able to catch, and in some cases correct bad FENS , at the command line the user should ensure the FEN is correct. I know xBoard can correct some faulty FENs. The behavior to exit is correct since that is a signal to the user at the command line that the FEN is improper.
@rayoh123 Note that python-chess did the following:
>>> import chess
>>> chess.Board("5rk1/ppp2pbp/3pk1p1/1q6/4r1P1/1nPrBB2/PP2nPP1/R2QR2K")
Board('5rk1/ppp2pbp/3pk1p1/1q6/4r1P1/1nPrBB2/PP2nPP1/R2QR2K w - - 0 1')
Also it's very unlikely that you really want the silly stop condition (which was just an example in the python-chess documentation):
# Unusual stop condition.
if info.get("hashfull", 0) > 50:
break