Spaces:
Sleeping
Sleeping
Thibault Duplessis commited on
Commit ·
a06e693
1
Parent(s): 7f87957
add fake_think_time
Browse files- config.yml.default +1 -0
- lichess-bot.py +6 -0
- model.py +3 -0
config.yml.default
CHANGED
|
@@ -37,6 +37,7 @@ engine: # engine settings
|
|
| 37 |
silence_stderr: false # some engines (yes you, leela) are very noisy
|
| 38 |
|
| 39 |
abort_time: 20 # time to abort a game in seconds when there is no activity
|
|
|
|
| 40 |
|
| 41 |
challenge: # incoming challenges
|
| 42 |
concurrency: 1 # number of games to play simultaneously
|
|
|
|
| 37 |
silence_stderr: false # some engines (yes you, leela) are very noisy
|
| 38 |
|
| 39 |
abort_time: 20 # time to abort a game in seconds when there is no activity
|
| 40 |
+
fake_think_time: false # artificially slow down the bot to pretend like it's thinking
|
| 41 |
|
| 42 |
challenge: # incoming challenges
|
| 43 |
concurrency: 1 # number of games to play simultaneously
|
lichess-bot.py
CHANGED
|
@@ -10,6 +10,7 @@ import logging
|
|
| 10 |
import multiprocessing
|
| 11 |
import traceback
|
| 12 |
import logging_pool
|
|
|
|
| 13 |
import backoff
|
| 14 |
from config import load_config
|
| 15 |
from conversation import Conversation, ChatLine
|
|
@@ -128,6 +129,11 @@ def play_game(li, game_id, control_queue, engine_factory, user_profile, config):
|
|
| 128 |
moves = upd["moves"].split()
|
| 129 |
board = update_board(board, moves[-1])
|
| 130 |
if is_engine_move(game, moves):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
best_move = None
|
| 132 |
if polyglot_cfg.get("enabled") and len(moves) <= polyglot_cfg.get("max_depth", 8) * 2 - 1:
|
| 133 |
best_move = get_book_move(board, polyglot_cfg)
|
|
|
|
| 10 |
import multiprocessing
|
| 11 |
import traceback
|
| 12 |
import logging_pool
|
| 13 |
+
import time
|
| 14 |
import backoff
|
| 15 |
from config import load_config
|
| 16 |
from conversation import Conversation, ChatLine
|
|
|
|
| 129 |
moves = upd["moves"].split()
|
| 130 |
board = update_board(board, moves[-1])
|
| 131 |
if is_engine_move(game, moves):
|
| 132 |
+
if config.get("fake_think_time") and len(moves) > 9:
|
| 133 |
+
delay = min(game.clock_initial, game.my_remaining_seconds()) * 0.015
|
| 134 |
+
accel = 1 - max(0, min(100, len(moves) - 20)) / 150
|
| 135 |
+
sleep = min(5, delay * accel)
|
| 136 |
+
time.sleep(sleep)
|
| 137 |
best_move = None
|
| 138 |
if polyglot_cfg.get("enabled") and len(moves) <= polyglot_cfg.get("max_depth", 8) * 2 - 1:
|
| 139 |
best_move = get_book_move(board, polyglot_cfg)
|
model.py
CHANGED
|
@@ -87,6 +87,9 @@ class Game():
|
|
| 87 |
def should_abort_now(self):
|
| 88 |
return self.is_abortable() and time.time() > self.abort_at
|
| 89 |
|
|
|
|
|
|
|
|
|
|
| 90 |
def __str__(self):
|
| 91 |
return "{} {} vs {}".format(self.url(), self.perf_name, self.opponent.__str__())
|
| 92 |
|
|
|
|
| 87 |
def should_abort_now(self):
|
| 88 |
return self.is_abortable() and time.time() > self.abort_at
|
| 89 |
|
| 90 |
+
def my_remaining_seconds(self):
|
| 91 |
+
return (self.state["wtime"] if self.is_white else self.state["btime"]) / 1000
|
| 92 |
+
|
| 93 |
def __str__(self):
|
| 94 |
return "{} {} vs {}".format(self.url(), self.perf_name, self.opponent.__str__())
|
| 95 |
|