Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generated sgf File did not perfectly match SGF format #26

Closed
sugizo opened this issue May 20, 2022 · 4 comments
Closed

generated sgf File did not perfectly match SGF format #26

sugizo opened this issue May 20, 2022 · 4 comments

Comments

@sugizo
Copy link

sugizo commented May 20, 2022

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

@atw1020
Copy link
Owner

atw1020 commented May 20, 2022

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!

@sugizo
Copy link
Author

sugizo commented May 20, 2022

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 ")"

@atw1020
Copy link
Owner

atw1020 commented May 23, 2022

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

@atw1020 atw1020 closed this as completed May 24, 2022
@atw1020
Copy link
Owner

atw1020 commented May 24, 2022

Closing due to the issue being fixed in sense 0.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants