atw1020/sente

generated sgf File did not perfectly match SGF format

Closed this issue · 4 comments

tested on colab and jupyter (localhost)

def random_player(game):
    move = random.choice(list(game.get_legal_moves() ) )
    return move

def play_game(player1, player2):
    game = sente.Game(9, sente.rules.JAPANESE)
    try:
        while not game.is_over():
            move = random_player(game)
            game.play(move)
            clear_output(wait = True)
            print(game)
    except KeyboardInterrupt:
        msg = "Game interrupted!"
        return (None, msg, game)
    file_sgf = "sgf/sente-random_player.sgf"
    sgf.dump(game, file_sgf)
    print('Winner :', game.get_winner() )

def play_sgf(file_sgf):
    game = sgf.load(file_sgf)
    try:
        for move in game.get_default_sequence():
            game.play(move)
            clear_output(wait = True)
            print(game)
    except KeyboardInterrupt:
        msg = "Game interrupted!"
        return (None, msg, game)
    print('File :', file_sgf)
    print(sgf.get_metadata(file_sgf) )

then run to record the game into *.sgf

play_game(random_player, random_player)

and to replay previous game recorded

play_sgf("sgf/sente-random_player.sgf")

error traceback when execute play_sgf("sgf/sente-random_player.sgf")

---------------------------------------------------------------------------
InvalidSGFException                       Traceback (most recent call last)
<ipython-input-27-1d5c168b0a27> in <module>
----> 1 play_sgf("sgf/sente-random_player.sgf")

<ipython-input-26-da610c86d202> in play_sgf(file_sgf)
      1 def play_sgf(file_sgf):
----> 2     game = sgf.load(file_sgf)
      3     try:
      4         for move in game.get_default_sequence():
      5             game.play(move)

InvalidSGFException: File did not perfectly match SGF format

temporary solution is to edit "sgf/sente-random_player.sgf"
e.g.
;B[df];W[ba];B[fh];W[ch];B[ef];W[cb];B[ad];W[hb];B[ed];W[bg];B[da];W[af];B[be];W[ie];B[ab];W[gi];B[bb];W[bh];B[eg];W[eb];B[hc];W[];B[ei];W[fe];B[dh];W[cg];B[ee];W[cf];B[ic];W[ha];B[bd];W[dd];B[hg];W[fc];B[he];W[hh];B[di];W[ff];B[bf];W[ii];B[gf];W[gg];B)

into
;B[df];W[ba];B[fh];W[ch];B[ef];W[cb];B[ad];W[hb];B[ed];W[bg];B[da];W[af];B[be];W[ie];B[ab];W[gi];B[bb];W[bh];B[eg];W[eb];B[hc];W[];B[ei];W[fe];B[dh];W[cg];B[ee];W[cf];B[ic];W[ha];B[bd];W[dd];B[hg];W[fc];B[he];W[hh];B[di];W[ff];B[bf];W[ii];B[gf];W[gg];)

notice on example above, remove the "B" on the last before ")"

best regards

Thank you reporting this, this is certainly a bug. You can fix the issue temporarily by putting empty brackets after the black pass move, "B[]" instead of "B". If you could upload the offending SGF file it would be greatly appreciated!

Here the generated file (problem)
sgf/sente-random_player.sgf

(;FF[4]GM[1]CA[UTF-8]
RE[B+R]
SZ[9]
RU[Japanese]
;B[hb];W[cd];B[bg];W[ec];B[ci];W[ha];B[aa];W[ih];B[gi];W)

yes, you right another temporary solution is to add empty brackets [] before the last ")"

You appear to be using sente 0.2.0, a highly outdated version of Sente. Please update to 0.4.1+.

Closing due to the issue being fixed in sense 0.3.0