Spaces:
Sleeping
Sleeping
Shail Choksi commited on
Commit ·
67118fe
1
Parent(s): f8d22d2
Thread support
Browse files- README.md +1 -0
- config.yml +2 -1
- main.py +15 -6
README.md
CHANGED
|
@@ -45,6 +45,7 @@ This is irreversible. [Read more about upgrading to bot account](https://lichess
|
|
| 45 |
- Download the lczero binary from here: https://github.com/glinscott/leela-chess/releases
|
| 46 |
- Copy both the files into the `engines` directory
|
| 47 |
- Change the `engine` and `weights` keys in config.yml to `lczero` and `latest.txt`
|
|
|
|
| 48 |
- To start: `python main.py -g {game_id}`
|
| 49 |
- e.g. `python main.py -g 5ekNlPWn`
|
| 50 |
|
|
|
|
| 45 |
- Download the lczero binary from here: https://github.com/glinscott/leela-chess/releases
|
| 46 |
- Copy both the files into the `engines` directory
|
| 47 |
- Change the `engine` and `weights` keys in config.yml to `lczero` and `latest.txt`
|
| 48 |
+
- You can specify the number of threads in the config.yml file as well
|
| 49 |
- To start: `python main.py -g {game_id}`
|
| 50 |
- e.g. `python main.py -g 5ekNlPWn`
|
| 51 |
|
config.yml
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
token: "someTestKey"
|
| 2 |
url: "https://lichess.org/"
|
| 3 |
engines_dir: "./engines/"
|
| 4 |
-
engine: "
|
| 5 |
weights: "latest.txt"
|
|
|
|
|
|
| 1 |
token: "someTestKey"
|
| 2 |
url: "https://lichess.org/"
|
| 3 |
engines_dir: "./engines/"
|
| 4 |
+
engine: "lczero_2"
|
| 5 |
weights: "latest.txt"
|
| 6 |
+
threads:
|
main.py
CHANGED
|
@@ -21,7 +21,7 @@ def upgrade_account(li):
|
|
| 21 |
return True
|
| 22 |
|
| 23 |
|
| 24 |
-
def start(li, game_id, engine, weights=None):
|
| 25 |
# init
|
| 26 |
user_profile = li.get_profile()
|
| 27 |
username = user_profile.get("username")
|
|
@@ -33,7 +33,7 @@ def start(li, game_id, engine, weights=None):
|
|
| 33 |
#Initial response of stream will be the full game info. Store it
|
| 34 |
game_info = json.loads(next(updates).decode('utf-8'))
|
| 35 |
board = setup_board(game_info)
|
| 36 |
-
engine, info_handler = setup_engine(engine, board, weights)
|
| 37 |
|
| 38 |
# need to do this to check if its playing against SF.
|
| 39 |
# If Lichess Stockfish is playing response will contain:
|
|
@@ -88,12 +88,20 @@ def setup_board(game_info):
|
|
| 88 |
return board
|
| 89 |
|
| 90 |
|
| 91 |
-
def setup_engine(
|
| 92 |
print("Loading Engine!")
|
|
|
|
| 93 |
if weights:
|
| 94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
else:
|
| 96 |
-
engine = chess.uci.popen_engine(
|
| 97 |
|
| 98 |
engine.uci()
|
| 99 |
engine.position(board)
|
|
@@ -125,6 +133,7 @@ def get_engine_stats(handler):
|
|
| 125 |
print("{}".format(handler.info["string"]))
|
| 126 |
print("Depth: {}".format(handler.info["depth"]))
|
| 127 |
print("nps: {}".format(handler.info["nps"]))
|
|
|
|
| 128 |
|
| 129 |
|
| 130 |
def get_time_controls(data):
|
|
@@ -155,7 +164,7 @@ if __name__ == "__main__":
|
|
| 155 |
if args.gameid:
|
| 156 |
engine_path = os.path.join(config["engines_dir"], config["engine"])
|
| 157 |
weights_path = os.path.join(config["engines_dir"], config["weights"]) if config["weights"] is not None else None
|
| 158 |
-
start(li, args.gameid, engine_path, weights_path)
|
| 159 |
else:
|
| 160 |
print("Game id is not specified!")
|
| 161 |
else:
|
|
|
|
| 21 |
return True
|
| 22 |
|
| 23 |
|
| 24 |
+
def start(li, game_id, engine, weights=None, threads=None):
|
| 25 |
# init
|
| 26 |
user_profile = li.get_profile()
|
| 27 |
username = user_profile.get("username")
|
|
|
|
| 33 |
#Initial response of stream will be the full game info. Store it
|
| 34 |
game_info = json.loads(next(updates).decode('utf-8'))
|
| 35 |
board = setup_board(game_info)
|
| 36 |
+
engine, info_handler = setup_engine(engine, board, weights, threads)
|
| 37 |
|
| 38 |
# need to do this to check if its playing against SF.
|
| 39 |
# If Lichess Stockfish is playing response will contain:
|
|
|
|
| 88 |
return board
|
| 89 |
|
| 90 |
|
| 91 |
+
def setup_engine(engine_path, board, weights=None, threads=None):
|
| 92 |
print("Loading Engine!")
|
| 93 |
+
commands = [engine_path]
|
| 94 |
if weights:
|
| 95 |
+
commands.append("-w")
|
| 96 |
+
commands.append(weights)
|
| 97 |
+
if threads:
|
| 98 |
+
commands.append("-t")
|
| 99 |
+
commands.append(threads)
|
| 100 |
+
|
| 101 |
+
if len(commands) > 1:
|
| 102 |
+
engine = chess.uci.popen_engine(commands)
|
| 103 |
else:
|
| 104 |
+
engine = chess.uci.popen_engine(engine_path)
|
| 105 |
|
| 106 |
engine.uci()
|
| 107 |
engine.position(board)
|
|
|
|
| 133 |
print("{}".format(handler.info["string"]))
|
| 134 |
print("Depth: {}".format(handler.info["depth"]))
|
| 135 |
print("nps: {}".format(handler.info["nps"]))
|
| 136 |
+
print("Node: {}".format(handler.info["nodes"]))
|
| 137 |
|
| 138 |
|
| 139 |
def get_time_controls(data):
|
|
|
|
| 164 |
if args.gameid:
|
| 165 |
engine_path = os.path.join(config["engines_dir"], config["engine"])
|
| 166 |
weights_path = os.path.join(config["engines_dir"], config["weights"]) if config["weights"] is not None else None
|
| 167 |
+
start(li, args.gameid, engine_path, weights_path, config["threads"])
|
| 168 |
else:
|
| 169 |
print("Game id is not specified!")
|
| 170 |
else:
|