#passing game clock times into homemade.py bot

2 messages · Page 1 of 1 (latest)

analog pewter
#

hello! i've been having a blast programming a homemade bot using lichess-bot.
everything works great, except i've set a hard-coded computation time limit per move. instead i'd like to dynamically adjust this time limit based on the times left on the clocks. i see some things in the engine wrapper about this, having read through it, but i'm not sure how to implement it into my bot.

mighty meadow
#

You can find an example of how to get the time here. It's just that the other homemade engines hide it under *args. If you don't use the other values (ponder, draw_offered, root_moves) you can also change the function signature to def search(self, board: chess.Board, time_limit: Limit, *args: HOMEMADE_ARGS_TYPE). Then to get the time you have to do:

if board.turn == chess.WHITE:
            my_time = time_limit.white_clock if isinstance(time_limit.white_clock, int) else 0  # Time for the whole game.
            my_inc = time_limit.white_inc if isinstance(time_limit.white_inc, int) else 0
        else:
            my_time = time_limit.black_clock if isinstance(time_limit.black_clock, int) else 0  # Time for the whole game.
            my_inc = time_limit.black_inc if isinstance(time_limit.black_inc, int) else 0

but on the first move you have a set time limit (10 seconds), so you can use the code provided in the example with

if isinstance(time_limit.time, int):
            my_time = time_limit.time  # Exact time. Can spend 10 seconds on this move.
            my_inc = 0