Search code examples
pythonchess

Is the depth of a chess engine its strength?


I am using python's library for chess with Stockfish as chess engine in my program that will create StockfishVsPlayer games and I want to be able to make the user select the difficulty of the game. I know that the higher the depth, the more moves the chess engine checks but is that all it is needed to define its strength? Could I then say difficulty=engine's depth? Like in this line, where I select the depth

[...while it's the computer's turn to move...]
[...]
best_move = engine.go(depth=difficulty)[0]
[...]

Solution

  • 1. Let's be clear:

    • Python chess is chess GUI, it's not a chess engine.
    • Stockfish is a chess engine, it's not a chess GUI

    You don't need Stockfish for Python Chess, and vice versa. Thus, what you wrote:

    ... If there was an option to select the level it should mention ...

    is incorrect. The documentation for Python Chess shouldn't have anything specific to the Stockfish UCI chess settings.

    2. Where do I find Stockfish UCI settings?

    The official page at:

    has what you want. If you want more details, you may want to look at the source code:

    3. Answer your question

    Depth is one of the most important factor in chess strength. The other possibilities are:

    • Contempt factor
    • Hash size
    • Time for each move
    • Tablebase
    • Opening book
    • Specific positions

    For example, Stockfish with the Cerebellum book library is stronger than without. Syzygy tablebase also improves the playing strength.

    Stockfish is fast, but it's not the best engine in closed positions. There's a recent post about Komodo and Stockfish in closed positions:

    There's a Skill Level parameter in Stockfish (it's in the links above). If you want to understand how it works, check my post: