Can't make Python Stockfish weaker

229 views Asked by At

I’ve written a chess software in Python which use Stockfish via this library: https://pypi.org/project/stockfish/

The software works and plays well. Too well actually…

Mi idea was the app can offer a level / ELO choice, but I just can’t scale it down. It doesn’t matter if I use Stockfish or Fairy Stockfish seemingly none of the parameters has any effect, especially not the “Skill Level” or “Elo Parameter”.

I tried multiple combination it’s only an example:

params = {
        "Debug Log File": "",
        "Contempt": 0,
        "Min Split Depth": 0,
        "Threads": 2, # More threads will make the engine stronger, but should be kept at less than the number of logical processors on your computer.
        "Ponder": False,
        "Hash": 512, # Default size is 16 MB. It's recommended that you increase this value, but keep it as some power of 2. E.g., if you're fine using 2 GB of RAM, set Hash to 2048 (11th power of 2).
        "MultiPV": 1,
        "Skill Level": 1,
        "Move Overhead": 10,
        "Minimum Thinking Time": 20,
        "Slow Mover": 100,
        "UCI_Chess960": False,
        "UCI_LimitStrength": True,
        "UCI_Elo": 1000
    }

    #stockfish = Stockfish(path="/usr/games/stockfish", parameters = params)
    stockfish = Stockfish(path="/home/python/chess/fairy-stockfish_x86-64", parameters = params)
3

There are 3 answers

2
user23571113 On

Documentation(https://pypi.org/project/stockfish/) says:

You can change them, as well as the default search depth, during your Stockfish class initialization:

stockfish = Stockfish(path="/Users/zhelyabuzhsky/Work/stockfish/stockfish-9-64", depth=18, parameters={"Threads": 2, "Minimum Thinking Time": 30})

i think what controlls the difficulty might be the depth=18 parameter.

0
Achbiter On

i have played both stockfish 15.1 and 16 at very low skill levels and have beaten it or found a way to beat it. the program blunders material when the evaluation is very bad for the engine and also it makes objectively weaker moves like useless pawn moves .it is more likely to play another move altogether after it finishes analysing the correct one. its kind of fun to play an engine that makes positional errors that you must prove are errors! often you will find tactical ideas to advance your play that stock will never let you imagine at high strength.i played 15.1 on 3 and 16 on two. 15 is more human like in my opinion but will still challenge you because it usually creates good structures and is still aggressive often never connecting rooks so as to use the g file with a bishop on the long diagnal cooperating. and a wild a or h pawn terrorizing you.if that is a common scenario for you its great practice!if it crushes you even on 2 you can go back to where you started to lose your way and try something else.usually there is some recourse available to you if the evaluation is in your favor.

0
igoemon On

It started to work and it can play significantly weaker. I tried multiple things (like boolean variables are string), but I think key factors are:

  • depth = 1
  • "MultiPV": 5 (as it gives options to the Engine and on weaker levels it has a tendency to choose a weaker move)
params = {
        "Debug Log File": "",
        "Contempt": 0,
        "Min Split Depth": 0,
        "Threads": 2, # More threads will make the engine stronger, but should be kept at less than the number of logical processors on your computer.
        "Ponder": "false",
        "Hash": 512, # Default size is 16 MB. It's recommended that you increase this value, but keep it as some power of 2. E.g., if you're fine using 2 GB of RAM, set Hash to 2048 (11th power of 2).
        "MultiPV": 5,
        "Skill Level": 0,
        "Move Overhead": 10,
        "Minimum Thinking Time": 20,
        "Slow Mover": 100,
        "UCI_Chess960": "false",
        "UCI_LimitStrength": "false",
    }
    
    stockfish = Stockfish(path="/home/python/chess/fairy-stockfish_x86-64", depth=1, parameters = params)