careless25 commited on
Commit
bb5ccc8
·
2 Parent(s): 89a2b3cb88ef58

Merge pull request #73 from tttony/abort_cfg

Browse files
Files changed (4) hide show
  1. config.py +1 -2
  2. config.yml.default +1 -0
  3. main.py +3 -3
  4. model.py +2 -2
config.py CHANGED
@@ -15,6 +15,7 @@ def load_config():
15
  ["url", str, "Section `url` must be a string wrapped in quotes."],
16
  ["engine", dict, "Section `engine` must be a dictionary with indented keys followed by colons.."],
17
  ["max_concurrent_games", int, "Section `max_concurrent_games` must be an integer number without quotes."],
 
18
  ["supported_tc", list, "Section `supported_tc` must be a list with indented entries starting with dashes.."],
19
  ["supported_modes", list, "Section `supported_modes` must be a list with indented entries starting with dashes.."]]
20
  for section in sections:
@@ -23,7 +24,6 @@ def load_config():
23
  elif not isinstance(CONFIG[section[0]], section[1]):
24
  raise Exception(section[2])
25
 
26
-
27
  engine_sections = [["dir", str, "´dir´ must be a string wrapped in quotes."],
28
  ["name", str, "´name´ must be a string wrapped in quotes."],
29
  ["polyglot", bool, "´polyglot´ must be a boolean type: true or false."],
@@ -31,7 +31,6 @@ def load_config():
31
  ["polyglot_max_depth", int, "`polyglot_max_depth` must be an integer number without quotes."],
32
  ["polyglot_min_weight", int, "`polyglot_min_weight` must be an integer number without quotes."],
33
  ["polyglot_random", bool, "`polyglot_random` must be a boolean type: true or false."]]
34
-
35
  for subsection in engine_sections:
36
  if subsection[0] not in CONFIG["engine"]:
37
  raise Exception("Your config.yml does not have required `engine` subsection `{}`.".format(subsection))
 
15
  ["url", str, "Section `url` must be a string wrapped in quotes."],
16
  ["engine", dict, "Section `engine` must be a dictionary with indented keys followed by colons.."],
17
  ["max_concurrent_games", int, "Section `max_concurrent_games` must be an integer number without quotes."],
18
+ ["abort_time", int, "Section `abort_time` must be an integer number without quotes."],
19
  ["supported_tc", list, "Section `supported_tc` must be a list with indented entries starting with dashes.."],
20
  ["supported_modes", list, "Section `supported_modes` must be a list with indented entries starting with dashes.."]]
21
  for section in sections:
 
24
  elif not isinstance(CONFIG[section[0]], section[1]):
25
  raise Exception(section[2])
26
 
 
27
  engine_sections = [["dir", str, "´dir´ must be a string wrapped in quotes."],
28
  ["name", str, "´name´ must be a string wrapped in quotes."],
29
  ["polyglot", bool, "´polyglot´ must be a boolean type: true or false."],
 
31
  ["polyglot_max_depth", int, "`polyglot_max_depth` must be an integer number without quotes."],
32
  ["polyglot_min_weight", int, "`polyglot_min_weight` must be an integer number without quotes."],
33
  ["polyglot_random", bool, "`polyglot_random` must be a boolean type: true or false."]]
 
34
  for subsection in engine_sections:
35
  if subsection[0] not in CONFIG["engine"]:
36
  raise Exception("Your config.yml does not have required `engine` subsection `{}`.".format(subsection))
config.yml.default CHANGED
@@ -22,6 +22,7 @@ ucioptions: # arbitrary UCI options passed to the engine
22
 
23
  max_concurrent_games: 1 # number of games to play simultaneously
24
  sort_challenges_by: "best" # possible values: "best", "first"
 
25
 
26
  supported_variants: # chess variants to accept (http://lichess.org/variant)
27
  - standard
 
22
 
23
  max_concurrent_games: 1 # number of games to play simultaneously
24
  sort_challenges_by: "best" # possible values: "best", "first"
25
+ abort_time: 20 # time to abort a game in seconds when there is no activity
26
 
27
  supported_variants: # chess variants to accept (http://lichess.org/variant)
28
  - standard
main.py CHANGED
@@ -100,7 +100,7 @@ def play_game(li, game_id, control_queue, engine_factory, user_profile, config):
100
  updates = li.get_game_stream(game_id).iter_lines()
101
 
102
  #Initial response of stream will be the full game info. Store it
103
- game = model.Game(json.loads(next(updates).decode('utf-8')), user_profile["username"], li.baseUrl)
104
  board = setup_board(game)
105
  engine = engine_factory(board)
106
  conversation = Conversation(game, engine, li, __version__)
@@ -133,9 +133,9 @@ def play_game(li, game_id, control_queue, engine_factory, user_profile, config):
133
  if best_move == None:
134
  best_move = engine.search(board, upd["wtime"], upd["btime"], upd["winc"], upd["binc"])
135
  li.make_move(game.id, best_move)
136
- game.abort_in(20)
137
  elif u_type == "ping":
138
- if game.should_abort_now() and len(game.state["moves"]) < 6:
139
  print(" Aborting {} by lack of activity".format(game.url()))
140
  li.abort(game.id)
141
  except (RemoteDisconnected, ConnectionError, ProtocolError, HTTPError) as exception:
 
100
  updates = li.get_game_stream(game_id).iter_lines()
101
 
102
  #Initial response of stream will be the full game info. Store it
103
+ game = model.Game(json.loads(next(updates).decode('utf-8')), user_profile["username"], li.baseUrl, config["abort_time"])
104
  board = setup_board(game)
105
  engine = engine_factory(board)
106
  conversation = Conversation(game, engine, li, __version__)
 
133
  if best_move == None:
134
  best_move = engine.search(board, upd["wtime"], upd["btime"], upd["winc"], upd["binc"])
135
  li.make_move(game.id, best_move)
136
+ game.abort_in(config["abort_time"])
137
  elif u_type == "ping":
138
+ if game.should_abort_now():
139
  print(" Aborting {} by lack of activity".format(game.url()))
140
  li.abort(game.id)
141
  except (RemoteDisconnected, ConnectionError, ProtocolError, HTTPError) as exception:
model.py CHANGED
@@ -49,7 +49,7 @@ class Challenge():
49
  return self.__str__()
50
 
51
  class Game():
52
- def __init__(self, json, username, base_url):
53
  self.username = username
54
  self.id = json.get("id")
55
  self.speed = json.get("speed")
@@ -69,7 +69,7 @@ class Game():
69
  self.opponent = self.black if self.is_white else self.white
70
  self.base_url = base_url
71
  self.white_starts = self.initial_fen == "startpos" or self.initial_fen.split()[1] == "w"
72
- self.abort_at = time.time() + 20
73
 
74
  def url(self):
75
  return urljoin(self.base_url, "{}/{}".format(self.id, self.my_color))
 
49
  return self.__str__()
50
 
51
  class Game():
52
+ def __init__(self, json, username, base_url, abort_time):
53
  self.username = username
54
  self.id = json.get("id")
55
  self.speed = json.get("speed")
 
69
  self.opponent = self.black if self.is_white else self.white
70
  self.base_url = base_url
71
  self.white_starts = self.initial_fen == "startpos" or self.initial_fen.split()[1] == "w"
72
+ self.abort_at = time.time() + abort_time
73
 
74
  def url(self):
75
  return urljoin(self.base_url, "{}/{}".format(self.id, self.my_color))