lichess.org
Donate

Tricks to improve bot performance

First, I'm using lichess's official Python driver, for a UCI engine I use Stockfish 9, so everything is relative to this ( github.com/careless25/lichess%2dbot , stockfishchess.org/download/ ).

I don't know if the driver has any support for setting UCI options, nevertheless you can set any option in main.py, in the setup_engine function like this ( after the engine.uci() command ):

engine.send_line("setoption name [option name] value [option value]")

You should naturally make use of all cores, so something like

engine.send_line("setoption name Threads value 8")

is helpful.

I have also found that against a strong opponent a low contempt factor may help, because the engine will look at every opportunity to secure a draw. I have used this strategy with success against a 200 points higher rated opponent and scored many quick draws:

engine.send_line("setoption name Contempt value -100")

I have also implemented a strategy so that when time falls below 15 secs, I send an understated clock time for my own engine ( currently I use 60% factor for this ). This makes the engine move quicker and it is less likely to time out.
#1 I'm confused, why write code instead of increasing parameter Move Overhead?
@lichapibot

"I don't know if the driver has any support for setting UCI options,"

It has, you may open and revise your config.yml, mine looks like this.

ucioptions:
Hash: "128"
NetworkLag: "10"
MaterialWeight: "90"
PassedPawnWeight: "180"
MobilityWeight: "250"
ThreatWeight: "300"
KingAttackWeight: "30"
KingShelterWeight: "150"
RepeatScore: "-50"

The api would send to the engine:

setoption name Hash value 128
setoption name NetworkLag value 10
etc.
@lichapibot, should it be typed here?

return engine_wrapper.XBoardEngine(board, commands)

return engine_wrapper.UCIEngine(board, commands, ucioptions)
engine.send_line("setoption name Move Overhead value 5000")
@Ingot For your convenience, there is a UCI options section of the config.yml file, for example:

ucioptions:
# Threads: 4
# Hash: "4096"
# Book File: "engines/book.bin"
# Move Overhead: 1000
@Toadofsky, yes, I tried that, and it doesn't do anything. I tried to set those values to maximum and to minimum, and speed stays the same in both cases. I tried to apply these setting in config.yml, engine_wrapper.py, main.py, and no effect.
@Ingot Sorry, other than editing config.yml (using the most recent lichess bot version) I don't know what to suggest. :-(

Certainly I'd also expect your solution to work.
Thanks for all the suggestions and feedback.

I was using an earlier version of the driver, many problems I have solved by modifying the code are now part of the official code, so the best solution is just use the official code.

Still it seems that the official code has no support for using an opening book.

My solution is the following.

Open a console window, cd to the _parent_ folder of lichess bot and type:

git clone github.com/michaeldv/donna_opening_books

Rename the resulting folder "obooks" for convenience ( I don't like typing in long names when using the console window, so as a habit I rename cloned repo folders to some simple name ).

In main.py add this below the imports:

import chess.polyglot

BOOK_READER = chess.polyglot.open_reader("../obooks/komodo.bin")

In the play_game function make this change:

if is_engine_move(game.is_white, moves):
try:
entry = BOOK_READER.find(board)
book_best_move = entry.move()
print("book move found {0}".format(book_best_move))
li.make_move(game.id, book_best_move)
except IndexError:
best_move = engine.search(board, upd.get("wtime"), upd.get("btime"), upd.get("winc"), upd.get("binc"))
engine.print_stats()
li.make_move(game.id, best_move)

Now the program will play the best move in the komodo book if there is one, otherwise it will play an engine move.

This topic has been archived and can no longer be replied to.