Shail Choksi commited on
Commit
f4ffe2d
·
1 Parent(s): 5cb356d

Added eval command to all bots. Added resign endpoint

Browse files
Files changed (3) hide show
  1. conversation.py +3 -0
  2. engine_wrapper.py +14 -0
  3. lichess.py +5 -1
conversation.py CHANGED
@@ -23,6 +23,9 @@ class Conversation():
23
  self.send_reply(line, "{} (lichess-bot v{})".format(self.engine.name(), self.version))
24
  elif cmd == "howto":
25
  self.send_reply(line, "How to run your own bot: lichess.org/api#tag/Chess-Bot")
 
 
 
26
 
27
  def send_reply(self, line, reply):
28
  self.xhr.chat(self.game.id, line.room, reply)
 
23
  self.send_reply(line, "{} (lichess-bot v{})".format(self.engine.name(), self.version))
24
  elif cmd == "howto":
25
  self.send_reply(line, "How to run your own bot: lichess.org/api#tag/Chess-Bot")
26
+ elif cmd == "eval":
27
+ stats = self.engine.get_stats()
28
+ self.send_reply(line, ", ".join(stats))
29
 
30
  def send_reply(self, line, reply):
31
  self.xhr.chat(self.game.id, line.room, reply)
engine_wrapper.py CHANGED
@@ -60,6 +60,14 @@ class EngineWrapper:
60
  if stat in info:
61
  print(" {}: {}".format(stat, info[stat]))
62
 
 
 
 
 
 
 
 
 
63
 
64
  class UCIEngine(EngineWrapper):
65
 
@@ -99,6 +107,8 @@ class UCIEngine(EngineWrapper):
99
  def print_stats(self):
100
  self.print_handler_stats(self.engine.info_handlers[0].info, ["string", "depth", "nps", "nodes", "score"])
101
 
 
 
102
 
103
  class XBoardEngine(EngineWrapper):
104
 
@@ -165,6 +175,10 @@ class XBoardEngine(EngineWrapper):
165
  def print_stats(self):
166
  self.print_handler_stats(self.engine.post_handlers[0].post, ["depth", "nodes", "score"])
167
 
 
 
 
 
168
  def name(self):
169
  try:
170
  return self.engine.features.get("myname")
 
60
  if stat in info:
61
  print(" {}: {}".format(stat, info[stat]))
62
 
63
+ def get_handler_stats(self, info, stats):
64
+ stats_str = []
65
+ for stat in stats:
66
+ if stat in info:
67
+ stats_str.append("{}: {}".format(stat, info[stat]))
68
+
69
+ return stats_str
70
+
71
 
72
  class UCIEngine(EngineWrapper):
73
 
 
107
  def print_stats(self):
108
  self.print_handler_stats(self.engine.info_handlers[0].info, ["string", "depth", "nps", "nodes", "score"])
109
 
110
+ def get_stats(self):
111
+ return self.get_handler_stats(self.engine.info_handlers[0].info, ["depth", "nps", "nodes", "score"])
112
 
113
  class XBoardEngine(EngineWrapper):
114
 
 
175
  def print_stats(self):
176
  self.print_handler_stats(self.engine.post_handlers[0].post, ["depth", "nodes", "score"])
177
 
178
+ def get_stats(self):
179
+ return self.get_handler_stats(self.engine.post_handlers[0].post, ["depth", "nodes", "score"])
180
+
181
+
182
  def name(self):
183
  try:
184
  return self.engine.features.get("myname")
lichess.py CHANGED
@@ -23,7 +23,8 @@ ENDPOINTS = {
23
  "abort": "/api/bot/game/{}/abort",
24
  "accept": "/api/challenge/{}/accept",
25
  "decline": "/api/challenge/{}/decline",
26
- "upgrade": "/api/bot/account/upgrade"
 
27
  }
28
 
29
  # docs: https://lichess.org/api
@@ -97,6 +98,9 @@ class Lichess():
97
  self.set_user_agent(profile["username"])
98
  return profile
99
 
 
 
 
100
  def set_user_agent(self, username):
101
  self.header.update({"User-Agent": "lichess-bot/{} user:{}".format(self.version, username)})
102
  self.session.headers.update(self.header)
 
23
  "abort": "/api/bot/game/{}/abort",
24
  "accept": "/api/challenge/{}/accept",
25
  "decline": "/api/challenge/{}/decline",
26
+ "upgrade": "/api/bot/account/upgrade",
27
+ "resign": "/api/bot/game/{}/resign"
28
  }
29
 
30
  # docs: https://lichess.org/api
 
98
  self.set_user_agent(profile["username"])
99
  return profile
100
 
101
+ def resign(self, game_id):
102
+ self.api_post(ENDPOINTS["resign"].format(game_id))
103
+
104
  def set_user_agent(self, username):
105
  self.header.update({"User-Agent": "lichess-bot/{} user:{}".format(self.version, username)})
106
  self.session.headers.update(self.header)