Lakin Wecker commited on
Commit
bc0a359
·
1 Parent(s): 4ab541b

Proving a point.

Browse files
Files changed (2) hide show
  1. engine_wrapper.py +22 -25
  2. main.py +3 -1
engine_wrapper.py CHANGED
@@ -3,31 +3,28 @@ import chess
3
  import chess.xboard
4
  import chess.uci
5
 
6
- class EngineFactory:
7
- def __init__(self, config):
8
- self.config = config
9
- def __call__(self, board):
10
- # print("Loading Engine!")
11
- cfg = self.config["engine"]
12
- engine_path = os.path.join(cfg["dir"], cfg["name"])
13
- weights = os.path.join(cfg["dir"], cfg["weights"]) if "weights" in cfg else None
14
- threads = cfg.get("threads")
15
-
16
- # TODO: ucioptions should probably be a part of the engine subconfig
17
- ucioptions = self.config.get("ucioptions")
18
- engine_type = cfg.get("protocol")
19
- commands = [engine_path]
20
- if weights:
21
- commands.append("-w")
22
- commands.append(weights)
23
- if threads:
24
- commands.append("-t")
25
- commands.append(threads)
26
-
27
- if engine_type == "xboard":
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
- start(li, user_profile, max_games, max_queued, engine_wrapper.EngineFactory(CONFIG), CONFIG)
 
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"]))