1

Our chess game project uses chess.uci and the stockfish engine. We used engine = chess.uci.popen_engine("/some_address/stockfish") to start an engine. However, I want to know if there is a way to change this engine's skill level. Could I achieve that by passing parameters to engine.go()? I saw there are options such as movetime and depth. Some Stack Overflow post says that there is a "skill level" option in stockfish but I didn't find it. What I want to achieve is to match the engine's skill to the player's skill. Thanks!

Jim Yang
  • 177
  • 2
  • 10
  • You can use an `options` dictionary that you pass in to your popen call. The argument's name will vary by the engine you use, but it might simply be the depth that you want to change to control the skill level. – Prof Feb 01 '21 at 13:31
  • Do you mean that I can pass in a dictionary to popen call? Like if I am using stockfish, I pass in ```{"Skill Level": 0}```? I am sure if that is what you mean. Or I also saw that in chess.uci there is a function called ```setoption()```, would that work? – Jim Yang Feb 01 '21 at 13:36

1 Answers1

1

Have you read the documentation? It is all in there.

Here is an example from the documentation on how to limit the level given it a fixed amount of search time:

Playing

Example: Let Stockfish play against itself, 100 milliseconds per move.

import chess import chess.engine

engine = chess.engine.SimpleEngine.popen_uci("/usr/bin/stockfish")

board = chess.Board() while not board.is_game_over():
    result = engine.play(board, chess.engine.Limit(time=0.1))
    board.push(result.move)

engine.quit()
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
eligolf
  • 1,682
  • 1
  • 6
  • 22
  • I have read the other [document](https://python-chess.readthedocs.io/en/v0.25.0/uci.html#options), which includes the functions posted in my question. Not sure what's the relationship between these docs. If we are using time or depth to limit the engine level, is there a way that I can know the rating of the engine? Like I want to limit the engine skill to a specific range of ELO rating. – Jim Yang Feb 08 '21 at 00:32
  • Setting a low amount of time for the engine to think does not necessarily reduce its playing strength. This answer does not address the question that was posted. – Valentin Brasso Jan 21 '23 at 09:47
  • @ValentinBrasso, Of course it reduces the playing strength. If it doesn't have time to go for more than e.g. depth 4 it will be way weaker than if it can go to depth 8. – eligolf Jan 21 '23 at 10:18
  • @eligolf And yet, that reduces the playing strength only in some situations, and it keeps the playing strength perhaps higher than what OP might intend (even at 100ms it still plays better than international masters). An answer that would address OP's question would involve sending the UCI commands `setoption name UCI_LimitStrength value true` and `setoption name UCI_Elo value ${elo}` before the start of the game. Which I did with `stockfish.js` (searching for the answer is what brought me here) but I'm not familiar with the Python API, so I won't leave a proper answer. – Valentin Brasso Jan 24 '23 at 16:07