Skip to content

Commit

Permalink
Refactor Engine.recv_line()
Browse files Browse the repository at this point in the history
* Fix saving of engine id name and author.
* Check bestmove first before other engine replies.
* Remove unnecessary parsing of an initial word "warn". Engine or human sending messages should start with "info string [message]".
Example:
info string Warning position is illegal.

Tested to work on win7 OS and python v3.7.3.
  • Loading branch information
fsmosca committed Oct 22, 2019
1 parent a686b6b commit debba71
Showing 1 changed file with 24 additions and 36 deletions.
60 changes: 24 additions & 36 deletions ataxx/uai.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,42 +21,30 @@ def send_line(self, line):
def recv_line(self, line):
words = line.split(' ')

# FIXME:
if words[0] == "id" and words[1] == "name" and len(words) > 2:
self.name = words[3:]

if len(words) > 1 and words[0] == "warn":
print(line)

if len(words) == 1:
if words[0] == "uaiok":
with self.uaiok_received:
self.uaiok_received.notify_all()
elif words[0] == "readyok":
with self.readyok_received:
self.readyok_received.notify_all()

elif len(words) == 2:
if words[0] == "bestmove":
with self.bestmove_received:
self.bestmove = words[1]
self.bestmove_received.notify_all()

elif len(words) == 3:
if words[0] == "id" and words[1] == "name":
self.name = words[2]
elif words[0] == "id" and words[1] == "author":
self.author = words[2]

elif len(words) == 4:
if words[0] == "bestmove" and words[2] == "ponder":
with self.bestmove_received:
self.bestmove = words[1]
self.ponder = words[3]
self.bestmove_received.notify_all()

else:
pass
if 'bestmove ' in line and 'ponder ' in line:
with self.bestmove_received:
self.bestmove = words[1]
self.ponder = words[3]
self.bestmove_received.notify_all()

elif 'bestmove ' in line:
with self.bestmove_received:
self.bestmove = words[1]
self.bestmove_received.notify_all()

elif 'readyok' in line:
with self.readyok_received:
self.readyok_received.notify_all()

elif 'id name ' in line:
self.name = ' '.join(words[2:])

elif 'id author ' in line:
self.author = ' '.join(words[2:])

elif 'uaiok' in line:
with self.uaiok_received:
self.uaiok_received.notify_all()

def uai(self):
with self.uaiok_received:
Expand Down

0 comments on commit debba71

Please sign in to comment.