Spaces:
Sleeping

Shail Choksi commited on
Commit
039909f
·
1 Parent(s): 105f208

Fix 'logger' not defined errors causing lichess-bot to not run

Browse files
Files changed (4) hide show
  1. config.yml.default +3 -0
  2. conversation.py +2 -0
  3. engine_wrapper.py +4 -19
  4. lichess-bot.py +9 -4
config.yml.default CHANGED
@@ -19,6 +19,9 @@ engine: # engine settings
19
  max_depth: 8 # half move max depth
20
  min_weight: 1 # selects move with highest weight but not below this value
21
  selection: "weighted_random" # move slection is one of "weighted_random", "uniform_random" or "best_move" (but not below the min_weight in 2. and 3. case)
 
 
 
22
  uci_options: # arbitrary UCI options passed to the engine
23
  Move Overhead: 100 # increase if your bot flags games too often
24
  Threads: 2 # max CPU threads the engine can use
 
19
  max_depth: 8 # half move max depth
20
  min_weight: 1 # selects move with highest weight but not below this value
21
  selection: "weighted_random" # move slection is one of "weighted_random", "uniform_random" or "best_move" (but not below the min_weight in 2. and 3. case)
22
+ # engine_options: # any custom command line params to pass to the engine
23
+ # cpuct: 3.1
24
+ # uci_ponder: false # Pondering (this does `go infinite` rather than follow the ponder protocol
25
  uci_options: # arbitrary UCI options passed to the engine
26
  Move Overhead: 100 # increase if your bot flags games too often
27
  Threads: 2 # max CPU threads the engine can use
conversation.py CHANGED
@@ -16,6 +16,8 @@ class Conversation():
16
  pass
17
 
18
  def command(self, line, game, cmd):
 
 
19
  if cmd == "wait" and game.is_abortable():
20
  game.abort_in(60)
21
  self.send_reply(line, "Waiting 60 seconds...")
 
16
  pass
17
 
18
  def command(self, line, game, cmd):
19
+ if cmd == "commands" or cmd == "help":
20
+ self.send_reply(line, "Supported commands: !name, !howto, and !eval")
21
  if cmd == "wait" and game.is_abortable():
22
  game.abort_in(60)
23
  self.send_reply(line, "Waiting 60 seconds...")
engine_wrapper.py CHANGED
@@ -10,26 +10,11 @@ def create_engine(config, board):
10
  cfg = config["engine"]
11
  engine_path = os.path.join(cfg["dir"], cfg["name"])
12
  engine_type = cfg.get("protocol")
13
- lczero_options = cfg.get("lczero")
14
  commands = [engine_path]
15
- if lczero_options:
16
- if "weights" in lczero_options:
17
- commands.append("-w")
18
- commands.append(lczero_options["weights"])
19
- if "threads" in lczero_options:
20
- commands.append("-t")
21
- commands.append(str(lczero_options["threads"]))
22
- if "gpu" in lczero_options:
23
- commands.append("--gpu")
24
- commands.append(str(lczero_options["gpu"]))
25
- if "tempdecay" in lczero_options:
26
- commands.append("--tempdecay")
27
- commands.append(str(lczero_options["tempdecay"]))
28
- if lczero_options.get("noise"):
29
- commands.append("--noise")
30
- if "log" in lczero_options:
31
- commands.append("--logfile")
32
- commands.append(lczero_options["log"])
33
 
34
  silence_stderr = cfg.get("silence_stderr", False)
35
 
 
10
  cfg = config["engine"]
11
  engine_path = os.path.join(cfg["dir"], cfg["name"])
12
  engine_type = cfg.get("protocol")
13
+ engine_options = cfg.get("engine_options")
14
  commands = [engine_path]
15
+ if engine_options:
16
+ for k, v in engine_options.items():
17
+ commands.append("--{}={}".format(k, v))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
  silence_stderr = cfg.get("silence_stderr", False)
20
 
lichess-bot.py CHANGED
@@ -21,13 +21,15 @@ from requests.exceptions import ChunkedEncodingError, ConnectionError, HTTPError
21
  from urllib3.exceptions import ProtocolError
22
  from ColorLogger import enable_color_logging
23
 
 
 
24
  try:
25
  from http.client import RemoteDisconnected
26
  # New in version 3.5: Previously, BadStatusLine('') was raised.
27
  except ImportError:
28
  from http.client import BadStatusLine as RemoteDisconnected
29
 
30
- __version__ = "1.1.1"
31
 
32
  terminated = False
33
 
@@ -163,9 +165,13 @@ def play_game(li, game_id, control_queue, engine_factory, user_profile, config):
163
  if polyglot_cfg.get("enabled") and len(moves) <= polyglot_cfg.get("max_depth", 8) * 2 - 1:
164
  best_move = get_book_move(board, book_cfg)
165
  if best_move == None:
 
166
  best_move = engine.search(board, upd["wtime"], upd["btime"], upd["winc"], upd["binc"])
167
  li.make_move(game.id, best_move)
168
  game.abort_in(config.get("abort_time", 20))
 
 
 
169
  elif u_type == "ping":
170
  if game.should_abort_now():
171
  logger.info(" Aborting {} by lack of activity".format(game.url()))
@@ -286,10 +292,9 @@ if __name__ == "__main__":
286
  parser.add_argument('-l', '--logfile', help="Log file to append logs to.", default=None)
287
  args = parser.parse_args()
288
 
289
- logging.basicConfig(level=logging.DEBUG if args.v else logging.INFO, filename=args.logfile, format="%(asctime)-15s: %(message)s")
290
- logger = logging.getLogger(__name__)
291
  logger.info(intro())
292
-
293
  CONFIG = load_config(args.config or "./config.yml")
294
  li = lichess.Lichess(CONFIG["token"], CONFIG["url"], __version__)
295
 
 
21
  from urllib3.exceptions import ProtocolError
22
  from ColorLogger import enable_color_logging
23
 
24
+ logger = logging.getLogger(__name__)
25
+
26
  try:
27
  from http.client import RemoteDisconnected
28
  # New in version 3.5: Previously, BadStatusLine('') was raised.
29
  except ImportError:
30
  from http.client import BadStatusLine as RemoteDisconnected
31
 
32
+ __version__ = "1.1.2"
33
 
34
  terminated = False
35
 
 
165
  if polyglot_cfg.get("enabled") and len(moves) <= polyglot_cfg.get("max_depth", 8) * 2 - 1:
166
  best_move = get_book_move(board, book_cfg)
167
  if best_move == None:
168
+ engine.stop()
169
  best_move = engine.search(board, upd["wtime"], upd["btime"], upd["winc"], upd["binc"])
170
  li.make_move(game.id, best_move)
171
  game.abort_in(config.get("abort_time", 20))
172
+ elif engine_cfg.get("uci_ponder", False) and engine_cfg.get("protocol") == "uci":
173
+ engine.stop()
174
+ engine.ponder(board)
175
  elif u_type == "ping":
176
  if game.should_abort_now():
177
  logger.info(" Aborting {} by lack of activity".format(game.url()))
 
292
  parser.add_argument('-l', '--logfile', help="Log file to append logs to.", default=None)
293
  args = parser.parse_args()
294
 
295
+ logging.basicConfig(level=logging.DEBUG if args.v else logging.INFO, filename=args.logfile,
296
+ format="%(asctime)-15s: %(message)s")
297
  logger.info(intro())
 
298
  CONFIG = load_config(args.config or "./config.yml")
299
  li = lichess.Lichess(CONFIG["token"], CONFIG["url"], __version__)
300