Skip to content

Commit

Permalink
Merge pull request #6 from i4mz3r0/master
Browse files Browse the repository at this point in the history
fix for pgn.from_game when time control is correspondence
  • Loading branch information
cyanfish committed Oct 11, 2020
2 parents d74a21d + b3c9780 commit 7cb2d0f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lichess/pgn.py
Expand Up @@ -51,7 +51,8 @@ def from_game(game, headers=None):
h.append(('FEN', g['initialFen']))
elif g['variant'] != 'standard':
h.append(('Variant', _cap(g['variant'])))
h.append(('TimeControl', _node(g, 'clock.initial') + '+' + _node(g, 'clock.increment')))
if g['speed'] != 'correspondence':
h.append(('TimeControl', _node(g, 'clock.initial') + '+' + _node(g, 'clock.increment')))
moves = g['moves']
pgn = ''
for i in h:
Expand Down
7 changes: 7 additions & 0 deletions test.py
Expand Up @@ -120,5 +120,12 @@ def test_pychess(self):
fen = game.end().board().fen()
self.assertEqual(fen, '2k1Rbr1/1ppr1Np1/p6p/8/3p4/P2P3P/1PP2PP1/2KR4 b - - 2 19')

def test_pgn_from_game(self):
api_game = lichess.api.game('9PzeRgcM', with_moves=1)
pgn = lichess.pgn.io_from_game(api_game)
game = chess.pgn.read_game(pgn)
fen = game.end().board().fen()
self.assertEqual(fen, '2r5/p2Q1ppp/1p2k3/1Bb1P3/5B2/P7/1P3PPP/R3K2R b KQ - 0 21')

if __name__ == '__main__':
unittest.main()

0 comments on commit 7cb2d0f

Please sign in to comment.