Spaces:
Sleeping
Sleeping
Lakin Wecker commited on
Commit ·
bc0a359
1
Parent(s): 4ab541b
Proving a point.
Browse files- engine_wrapper.py +22 -25
- main.py +3 -1
engine_wrapper.py
CHANGED
|
@@ -3,31 +3,28 @@ import chess
|
|
| 3 |
import chess.xboard
|
| 4 |
import chess.uci
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
commands
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
return XBoardEngine(board, commands)
|
| 29 |
-
|
| 30 |
-
return UCIEngine(board, commands, ucioptions)
|
| 31 |
|
| 32 |
|
| 33 |
class EngineWrapper:
|
|
|
|
| 3 |
import chess.xboard
|
| 4 |
import chess.uci
|
| 5 |
|
| 6 |
+
def create_engine(config, board):
|
| 7 |
+
# print("Loading Engine!")
|
| 8 |
+
cfg = config["engine"]
|
| 9 |
+
engine_path = os.path.join(cfg["dir"], cfg["name"])
|
| 10 |
+
weights = os.path.join(cfg["dir"], cfg["weights"]) if "weights" in cfg else None
|
| 11 |
+
threads = cfg.get("threads")
|
| 12 |
+
|
| 13 |
+
# TODO: ucioptions should probably be a part of the engine subconfig
|
| 14 |
+
ucioptions = config.get("ucioptions")
|
| 15 |
+
engine_type = cfg.get("protocol")
|
| 16 |
+
commands = [engine_path]
|
| 17 |
+
if weights:
|
| 18 |
+
commands.append("-w")
|
| 19 |
+
commands.append(weights)
|
| 20 |
+
if threads:
|
| 21 |
+
commands.append("-t")
|
| 22 |
+
commands.append(threads)
|
| 23 |
+
|
| 24 |
+
if engine_type == "xboard":
|
| 25 |
+
return XBoardEngine(board, commands)
|
| 26 |
+
|
| 27 |
+
return UCIEngine(board, commands, ucioptions)
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
|
| 30 |
class EngineWrapper:
|
main.py
CHANGED
|
@@ -13,6 +13,7 @@ import traceback
|
|
| 13 |
import logging_pool
|
| 14 |
from config import load_config
|
| 15 |
from conversation import Conversation, ChatLine
|
|
|
|
| 16 |
|
| 17 |
|
| 18 |
def upgrade_account(li):
|
|
@@ -173,6 +174,7 @@ if __name__ == "__main__":
|
|
| 173 |
if is_bot:
|
| 174 |
max_games = CONFIG["max_concurrent_games"]
|
| 175 |
max_queued = CONFIG["max_queued_challenges"]
|
| 176 |
-
|
|
|
|
| 177 |
else:
|
| 178 |
print("{} is not a bot account. Please upgrade your it to a bot account!".format(user_profile["username"]))
|
|
|
|
| 13 |
import logging_pool
|
| 14 |
from config import load_config
|
| 15 |
from conversation import Conversation, ChatLine
|
| 16 |
+
from functools import partial
|
| 17 |
|
| 18 |
|
| 19 |
def upgrade_account(li):
|
|
|
|
| 174 |
if is_bot:
|
| 175 |
max_games = CONFIG["max_concurrent_games"]
|
| 176 |
max_queued = CONFIG["max_queued_challenges"]
|
| 177 |
+
engine_factory = partial(engine_wrapper.create_engine, CONFIG)
|
| 178 |
+
start(li, user_profile, max_games, max_queued, engine_factory, CONFIG)
|
| 179 |
else:
|
| 180 |
print("{} is not a bot account. Please upgrade your it to a bot account!".format(user_profile["username"]))
|