mcostalba / chess_db

GNU General Public License v3.0
22 stars 5 forks source link

Fixed output regex and modified C++ code to output ctrl-a at the end … #38

Closed sshivaji closed 7 years ago

sshivaji commented 7 years ago

…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.

mcostalba commented 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.
gbtami commented 7 years ago

I think it would be more elegant to follow the scoutfish way to solve this issue using UCI "isready" and "readyok".

mcostalba commented 7 years ago

@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.

sshivaji commented 7 years ago

Will test out the solution above until uci command loop is available

sshivaji commented 7 years ago

@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?

sshivaji commented 7 years ago

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:

  1. A "naked" command line JSON parse call from python (or other languages).
  2. Works well with chess_db.
  3. Works well for long UI sequences with chessui.

Will see if I can improve over 2 \n and post back.

mcostalba commented 7 years ago

It should be fixed now. Closing this.