Closed sshivaji closed 7 years ago
Can you please use something like:
def find(self, fen, max_offsets=10):
'''Find all games with positions equal to fen'''
if not self.db or not self.p:
raise NameError("Unknown DB, first open a PGN file")
cmd = "find {} max_game_offsets {} {}".format(self.db, max_offsets, fen)
self.p.sendline(cmd)
result = ''
while True:
self.p.expect(FIND_OUTPUT_REGEX)
result += self.p.before + "}"
self.p.before = ''
if result.count('{') == result.count('}'):
break
return json.loads(result)
It seems less hacky to me, moreover we stick to output regular JSON in the C++ tool.
I think it would be more elegant to follow the scoutfish way to solve this issue using UCI "isready" and "readyok".
@gbtami yes, I agree. This is by far the best way. But it requires to add UCI command loop to chess_db, as is in scoutfih. Anyhow this is the way to go.
Will test out the solution above until uci command loop is available
@mcostalba, tried that solution. Unfortunately, its not that simple. I am running into eof issues and more. I agree that uci readyok is the right solution.
However, for now, another solution that works is to simply put in 2 new lines at the end of the JSON ie (\n,\n,\n). That works well in the regex and in chessui as well. Would that be acceptable?
One idea is that I will try out the best solution (maybe tabs before and after the last closing brace) that should pass the following tests:
Will see if I can improve over 2 \n and post back.
It should be fixed now. Closing this.
…of find output for easy tracing
Solution was to put a ctrl-a character at the end of the find command output. chess_db.py and test.py have all been updated to make it work.