I am working on a simple cheat detection script to find if a user used one of the top engine moves in a game, so I found this great python-chess library Additionally, I found this example to getting the moves score. But that topic is an old version of the lib so I tried to update the script. However, I keep getting errors, and I don't know how to get the scores in the right way.
import asyncio import chess #import chess.uci import chess.engine import chess.pgn import io #Let's try our code with the starting position of chess: fen = 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1' board = chess.Board(fen) #Now make sure you give the correct location for your stockfish engine file #...in the line follows: e.g., /home/.../stockfish_6_x64 engine = chess.engine.SimpleEngine.popen_uci('/home/shar/Desktop/cheat detect python/stockfish-10-linux/Linux/stockfish_10_x64') if board.turn: print( 'White to move'); else: print( 'black to move'); for el in board.legal_moves: pgn = io.StringIO(board.san(el)) thnwpgntofen = chess.pgn.read_game(pgn); nwinfo = engine.analysis(thnwpgntofen.board()); print(nwinfo["score"]) print("-------------------------");
I get this error after running my code:
Traceback (most recent call last): File "prntengmv.py", line 37, in print(nwinfo["score"]) TypeError: 'SimpleAnalysisResult' object is not subscriptable