Coder Social home page Coder Social logo

pgn2gif's People

Contributors

dependabot[bot] avatar dn1z avatar jsphwllng avatar karmickoala904 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

pgn2gif's Issues

Error during execution

Traceback (most recent call last):
File "pgn2gif.py", line 311, in
process_file(args.path, args.speed, args.out, args.reverse)
File "pgn2gif.py", line 295, in process_file
create_gif(pgn, name, duration, output_dir, reverse)
File "pgn2gif.py", line 272, in create_gif
update(move, i % 2)
File "pgn2gif.py", line 58, in update
to = point_of_square(move)
File "pgn2gif.py", line 41, in point_of_square
r = 7 - rows.index(move[-1])
ValueError: '0' is not in list

If anyone stumbles on this issue, I noticed that get_moves_from_pgn regex may fail if pgn tags have usernames or other info matching regex

I noticed that my pgn file has this line
[White "bac02"], which when deleted makes the code run fine.
Thanks!

StopIteration error

I get the StopIteration error when running against the following pgn.
See line:

165 return next(sq for sq, pt in pieces.items() if pt == piece and indicator in sq and (check_line(sq, to) or check_diagonal(sq, to)))

pgn file:

1.e4 e5 2.Qh5 { C20: King's Pawn Opening: Wayward Queen Attack } 2...d6 3.Bc4 Nh6 { (-0.42 → +0.42) Inaccuracy. A better move was 3... g6. } 4.Qf3 { (+0.50 → 0.00) Inaccuracy. A better move was 4. h3. } 4...Bg4 5.Qg3 Be7 6.d4 { (+0.66 → +0.14) Inaccuracy. A better move was 6. h3. } 6...Bh4 7.Qb3 { (0.00 → -0.86) Inaccuracy. A better move was 7. Qd3. } 7...exd4 { (-0.67 → +1.04) Mistake. The best move was 7... Nc6. } 8.Bxh6 Qd7 { (+1.12 → +6.87) Blunder. The best move was 8... gxh6. } 9.Bxg7 Rg8 10.Bxd4 { (+7.13 → +4.75) Inaccuracy. A better move was 10. Qxb7. } 10...Rf8 11.Bb5 { (+7.55 → +5.42) Inaccuracy. A better move was 11. Qxb7. } 11...c6 12.Bd3 c5 13.Bg7 { (+5.42 → +4.00) Inaccuracy. A better move was 13. Be3. } 13...Rg8 14.Bb5 Nc6 15.Bh6 Be6 16.Qc3 Ke7 17.Bxc6 Qxc6 18.Nf3 { (+4.10 → +1.55) Blunder. The best move was 18. Qf3. } 18...Bf6 19.Qd2 { (+1.31 → -1.34) Blunder. The best move was 19. e5. } 19...Qxe4+ 20.Be3 { (-0.89 → -3.03) Mistake. The best move was 20. Qe2. } 20...Bxb2 21.O-O { (-2.95 → -11.76) Mistake. The best move was 21. Nc3. } 21...Bxa1 { (-13.00 → -2.40) Blunder. The best move was 21... Rxg2+. } 22.Bg5+ Bf6 23.Bxf6+ Kxf6 24.Re1 { (-2.65 → -8.42) Mistake. The best move was 24. Qc3+. } 24...Qc6 { (-8.49 → -1.26) Blunder. The best move was 24... Rxg2+. } 25.Qf4+ Ke7 26.Qh4+ Ke8 { (-3.07 → -2.08) Inaccuracy. A better move was 26... Kd7. } 27.Qxh7 Kd7 28.Ng5 { (-2.66 → -6.85) Mistake. The best move was 28. Nbd2. } 28...Rxg5 29.Nc3 { (-7.10 → ♚ Mate in 1) Mistake. The best move was 29. g3. } 29...Ke7 { (♚ Mate in 1 → -6.03) Mistake. The best move was 29... Qxg2#. } 30.Ne4 Re5 31.Qh4+ Kd7 32.Nf6+ Kc7 33.Rxe5 dxe5 34.Nh7 Qd5 35.g3 Qxa2 { (-12.71 → -7.27) Mistake. The best move was 35... Qd1+. } 36.Qe7+ Kb6 37.Qd6+ Kb5 38.Qxe5 Qxc2 39.Ng5 Bd7 40.Nxf7 Bh3 41.Nd6+ Kc6 42.Qe4+ Qxe4 43.Nxe4 Re8 44.Ng5 { (-12.48 → ♚ Mate in 1) Mistake. The best move was 44. f3. } 44...Re1# 0-1

Thanks!

Got crash on specific pgn file

[Event "It"]
[Site "San Sebastian (Spain)"]
[Date "1911.??.??"]
[Round "6"]
[White "Tarrasch Siegbert (GER)"]
[Black "Rubinstein Akiba K (POL)"]
[Result "1/2-1/2"]
[WhiteElo "0"]
[BlackElo "0"]
[ECO "C10"]
[Annotator ""]
[Source ""]
[Remark ""]
[CurrentPosition " "]

1.e4 e6 2.d4 d5 3.Nc3 dxe4 4.Nxe4 Nd7 5.Nf3 Ngf6 6.Bd3 Be7 7.O-OO-O 8.Nxf6+ Nxf6 9.Ne5 c5 10.dxc5 Qc7 11.Qe2 Bxc5 12.Bg5 Nd7
13.Nxd7 Bxd7 14.Rad1 Bc6 15.Qh5 g6 16.Qh4 Rfe8 17.Rfe1 Be7 18.Bxe7
Qxe7 19.Qxe7 Rxe7 20.Be4 Rc8 21.c3 e5 22.Rd6 Bxe4 23.Rxe4 f5
24.Ra4 b6 25.g4 e4 26.gxf5 gxf5 27.Kf1 Kf7 28.Rad4 Re6 29.Rd7+
Re7 30.R4d5 Rxd7 31.Rxd7+ Kg6 32.Rxa7 Rd8 33.Ra6 Rd2 34.Rxb6+
Kg5 35.Ke1 Rc2 36.Rb5 Kg4 37.h3+ Kxh3 38.Rxf5 Rxb2 39.Rf4 Rxa2
40.Rxe4 h5 41.c4 Kg2 42.Rf4 Rc2 43.Rh4 Kf3 44.Kd1 Rxf2 45.c5
Ke3 46.Rxh5 Kd4 1/2-1/2

Contains atypical PGN parser, difficult to debug

The following PGN was exported from Lichess.org (line breaks added by me to highlight moves 42 and 54):

1. Nf3 Nc6 2.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Qad5 Qhe4 95. c8=Q f1=Q 96. Qcc1 Qff8 97. Qdc5 Qef4 98. Q5c2 Q4f7 99. Qbd4 Qge5 100. Qdb2 Qeg7 101. Qbd4 Qge5 102. Qdb2 Qeg7 1/2-1/2

When run with this input file, your code outputs no GIF and the exception handler gives the following, rather cryptic message:

Traceback (most recent call last):
  File "C:\path-to-pgn2gif\pgn2gif-script.py", line 33, in <module>
    sys.exit(load_entry_point('pgn2gif==1.2', 'console_scripts', 'pgn2gif')())
  File "C:\path-to-python\python3.8\site-packages\pgn2gif-1.2-py3.8.egg\pgn2gif\pgn2gif.py", line 167, in main
    creator.create_gif(pgn, Path(args.out) / f)
  File "C:\path-to-python\python3.8\site-packages\pgn2gif-1.2-py3.8.egg\pgn2gif\pgn2gif.py", line 127, in create_gif
    game.next()
  File "C:\path-to-python\python3.8\site-packages\pgn2gif-1.2-py3.8.egg\pgn2gif\chess.py", line 228, in next
    origin = self._find_non_pawn(move, dest, pt)
  File "C:\path-to-python\python3.8\site-packages\pgn2gif-1.2-py3.8.egg\pgn2gif\chess.py", line 147, in _find_non_pawn
    return next(
StopIteration

By shortening the file using trial-and error, I determined that the crash happens at Black's move 54. If Qgf8 and all following text is removed, a GIF is generated. However, unlike the output of all online PGN players and converters I tried, it does not end with a black queen in column g (there should have been one at G8). Turns out, your program moved the G8 queen in move 42, "42. .. Qh7". Either queen (G8 or H1) could move there, and it was not specified. This ambiguity is likely a mistake on Lichess' part, and I am not blaming you for handling it wrong. However, it is annoying that your PGN parser behaved differently from all others tested. The game can be fixed by rewriting Move 42 to 42. Qa2 Qhh7 to remove the ambiguity.

For reference, here is the chessboard state after White's move 42 (just before the parsing "mistake") and White's move 54 (just before the crash), respectively:

  a b c d e f g h  |    a b c d e f g h
8     Q       q k  |  8             q k
7   p   p     P    |  7   p     P q   q
6       p          |  6     P          
5   p P            |  5   p P   P      
4           p P    |  4       p   p P  
2         P        |  3           p   
2 Q   P   P   P    |  2 Q   Q p     P  
1 K Q       q   q  |  1 K   Q          

Also, FEN of the above positions for import into a viewer:

2Q3qk/1p1p1p2/3p4/1pP5/5pP1/4P3/Q1P1P1P1/KQ3q1q b - - 1 42
6qk/1p2Pq1q/2P5/1pP1P3/3p1pP1/5p2/Q1Qp2P1/K1Q5 b - - 5 54

So, how could you improve the user experence? In either of two ways:

  • Use a PGN parser that behaves the same as others, such as the Lichess.org Analysis Board Import feature. Thus, your program will behave as expected from the users of Lichess.org and other parsers: the set of accepted PGN files will be the same for you and them, and they might offer hints on error locations in case the file cannot be accepted. You could possibly import someone's open-source pre-converter that completely de-ambiguises the PGN, so that e.g. 1. e4 Nf6 becomes 1. e2e4 Ng8f6 (if such software exists).
  • Add error reporting that aids in identifying the ambiguous move, so that the user can fix the PGN file.

Such error reporting could look like this:

Ambiguous white move 42 "Qa2": Multiple queens can move to A2; resolved as A8→A2
Ambiguous black move 42 "Qh7": Multiple queens can move to H7; resolved as G8→H7
Invalid black move 54 "Qgh7": No queen in column g
Please retry with a valid PGN file. Exiting...

Note that in Move 42, White's ambiguous move was resolved as expected while Black's wasn't.

Optimize gif size

Currently the size of the gifs generated is very large. Ex: pgn having only 10 moves results in gif of size around 2 MB.

Optimizations for the gifs generated must be added.

Use argparse or other command line parser

Currently this tool need pgn's to be present in a same folder in which the script but it would be nice if you can take path to pgn files/folder and then run the tool on them.

I would suggest to use argparse for simplicity.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.