Python-chess : how to get a list for the best engine moves 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
As per: https://python-chess.readthedocs.io/en/latest/engine.html#indefinite-or-infinite-analysis

engine.analysis(board) now returns an AnalysisResult object, which has the property info that you want.

So instead of:

nwinfo = engine.analysis(...)
print(nwinfo["score"])


You would loop over info in the AnalysisResult, and print the score property from each element:

with engine.analysis(...) as analysis:
    for info in analysis:
        print(info.get("score"))


However, your use case looks like it may benefit from engine.analyse more than engine.analysis.