Spaces:
Sleeping
Sleeping
Merge pull request #97 from gbtami/master
Browse filesFix #96 No time control command sent to xboard engine
- engine_wrapper.py +8 -4
- lichess-bot.py +2 -2
engine_wrapper.py
CHANGED
|
@@ -40,7 +40,10 @@ class EngineWrapper:
|
|
| 40 |
def __init__(self, board, commands, options=None, silence_stderr=False):
|
| 41 |
pass
|
| 42 |
|
| 43 |
-
def
|
|
|
|
|
|
|
|
|
|
| 44 |
pass
|
| 45 |
|
| 46 |
def search(self, board, wtime, btime, winc, binc):
|
|
@@ -89,7 +92,7 @@ class UCIEngine(EngineWrapper):
|
|
| 89 |
info_handler = chess.uci.InfoHandler()
|
| 90 |
self.engine.info_handlers.append(info_handler)
|
| 91 |
|
| 92 |
-
def first_search(self,
|
| 93 |
self.engine.position(board)
|
| 94 |
best_move, _ = self.engine.go(movetime=movetime)
|
| 95 |
return best_move
|
|
@@ -150,16 +153,17 @@ class XBoardEngine(EngineWrapper):
|
|
| 150 |
except EngineStateException:
|
| 151 |
pass
|
| 152 |
|
| 153 |
-
def
|
| 154 |
minutes = game.clock_initial / 1000 / 60
|
| 155 |
seconds = game.clock_initial / 1000 % 60
|
| 156 |
inc = game.clock_increment / 1000
|
|
|
|
| 157 |
|
|
|
|
| 158 |
self.engine.setboard(board)
|
| 159 |
self.engine.level(0, 0, movetime / 1000, 0)
|
| 160 |
bestmove = self.engine.go()
|
| 161 |
|
| 162 |
-
self.engine.level(0, minutes, seconds, inc)
|
| 163 |
return bestmove
|
| 164 |
|
| 165 |
def search(self, board, wtime, btime, winc, binc):
|
|
|
|
| 40 |
def __init__(self, board, commands, options=None, silence_stderr=False):
|
| 41 |
pass
|
| 42 |
|
| 43 |
+
def set_time_control(self, game):
|
| 44 |
+
pass
|
| 45 |
+
|
| 46 |
+
def first_search(self, board, movetime):
|
| 47 |
pass
|
| 48 |
|
| 49 |
def search(self, board, wtime, btime, winc, binc):
|
|
|
|
| 92 |
info_handler = chess.uci.InfoHandler()
|
| 93 |
self.engine.info_handlers.append(info_handler)
|
| 94 |
|
| 95 |
+
def first_search(self, board, movetime):
|
| 96 |
self.engine.position(board)
|
| 97 |
best_move, _ = self.engine.go(movetime=movetime)
|
| 98 |
return best_move
|
|
|
|
| 153 |
except EngineStateException:
|
| 154 |
pass
|
| 155 |
|
| 156 |
+
def set_time_control(self, game):
|
| 157 |
minutes = game.clock_initial / 1000 / 60
|
| 158 |
seconds = game.clock_initial / 1000 % 60
|
| 159 |
inc = game.clock_increment / 1000
|
| 160 |
+
self.engine.level(0, minutes, seconds, inc)
|
| 161 |
|
| 162 |
+
def first_search(self, board, movetime):
|
| 163 |
self.engine.setboard(board)
|
| 164 |
self.engine.level(0, 0, movetime / 1000, 0)
|
| 165 |
bestmove = self.engine.go()
|
| 166 |
|
|
|
|
| 167 |
return bestmove
|
| 168 |
|
| 169 |
def search(self, board, wtime, btime, winc, binc):
|
lichess-bot.py
CHANGED
|
@@ -115,6 +115,7 @@ def play_game(li, game_id, control_queue, engine_factory, user_profile, config):
|
|
| 115 |
board = play_first_book_move(game, engine, board, li, engine_cfg)
|
| 116 |
else:
|
| 117 |
board = play_first_move(game, engine, board, li)
|
|
|
|
| 118 |
|
| 119 |
try:
|
| 120 |
for binary_chunk in updates:
|
|
@@ -153,9 +154,8 @@ def play_first_move(game, engine, board, li):
|
|
| 153 |
moves = game.state["moves"].split()
|
| 154 |
if is_engine_move(game, moves):
|
| 155 |
# need to hardcode first movetime since Lichess has 30 sec limit.
|
| 156 |
-
best_move = engine.first_search(
|
| 157 |
li.make_move(game.id, best_move)
|
| 158 |
-
|
| 159 |
return board
|
| 160 |
|
| 161 |
|
|
|
|
| 115 |
board = play_first_book_move(game, engine, board, li, engine_cfg)
|
| 116 |
else:
|
| 117 |
board = play_first_move(game, engine, board, li)
|
| 118 |
+
engine.set_time_control(game)
|
| 119 |
|
| 120 |
try:
|
| 121 |
for binary_chunk in updates:
|
|
|
|
| 154 |
moves = game.state["moves"].split()
|
| 155 |
if is_engine_move(game, moves):
|
| 156 |
# need to hardcode first movetime since Lichess has 30 sec limit.
|
| 157 |
+
best_move = engine.first_search(board, 10000)
|
| 158 |
li.make_move(game.id, best_move)
|
|
|
|
| 159 |
return board
|
| 160 |
|
| 161 |
|