PythonChess - Get engine to predict a list of the best moves in a position Say that I currently have a board, and then on that board I move my e2 pawn to e4. I'm looking for a way to get the engine to predict the X amount of best moves for black.

I know how to predict the best move given a position:

result = engine.play(board, chess.engine.Limit(time=0.1))
board.push(result.move)


But that only predicts the number 1 best move. I want a list containing the second, third ... X best moves.

How would I do that?
In the world of chess engines, what you're looking for is called multi-PV (multiple principal variations): telling the engine to look for and return up to n best moves and the associated principal variations for each. ("Up to" because sometimes there's only 1 legal move in a position.)

In python-chess, this is part of the engine protocols, as one of the optional parameters when calling engine.analyse(). From the documentation:


  class chess.engine.EngineProtocol
  
  coroutine analyse( [...] )
  
  
  multipv – Optional. Analyse multiple root moves. Will return a list of at most multipv dictionaries rather than just a single info dictionary.
  


The .analyse() method tells the engine to analyse the position, returning a dictionary of information, which includes among other things the moves of the principal variation. Specifying for instance .analyse(multipv = 3) will tell the engine to return a list of (up to) 3 such dictionaries -- the first moves in the pv value of each dictionary should be what you are looking for.