Open ChaoticNeutralCzech opened 3 years ago
Hi, firstly thanks for the detailed issue description. I had a look at the game and in 42nd move, as you mentioned, while queens on both g8 and h1 can move to h7, due to the fact that queen on the g8 is pinned by white queen in c8, Qh7
is apparently the right way to show the move. However, there is no problem with PGN parser itself. The parser only parses the list of moves using regex and feeds the ChessGame
object with these moves which creates the board state by applying the move by finding the original square where the piece in the move came from. To find the square where the piece came from (e.g. in the beginning, in the move Nf3, knight comes from g1 square), the algorithm checks pieces one by one (starting from 8th row and ending in 1st row which explains why it finds original square of the move Qh7
as g8
) and when it finds a valid movement, it returns the square without further check in which your issue lies. In order to solve this issue, i should modify the original-square-finding algorithm to check for all pieces even it already found a match and when the program encounters with ambiguous move, it should try to invalidate all but one move (like Qgh7
is not possible as the queen is pinned). The ChessGame
object does not implement all of the chess features, it only tries to get board state, and understands nothing else like king checks, checkmates, etc., so I may try to implement some of these features or use existing chess library for python. I will have look into this issue deeper and make necessary changes soon.
Thank you for looking into the issue! Sadly, I won't be of much help anymore: I have read none of the repo's code and I'm helpless at OOP anyway, and as you may have guessed from the game, my (White's) strategic intelligence is at the level of a 9-year-old who just learnt how promotion works and what the word "harem" means. (Still better than Black though, who is just a dumb copycat.) So I didn't even realize that the queen was pinned - I only know chess rules, no strategy.
Due to lacking programming experience and English being my second language, I may have misused the word "parser" in place of "interpreter" or another more suitable denomination (perhaps the appropriate function has a name in the code but I haven't read it, sorry).
By the way, this project is awesome for its purpose, and though the quality could have been better than 480p, I won't complain. For this reason, I looked no further than here for the export of my games, though the option for the duration of individual frames seems like a missing basic feature (fortunately, GIF editors make up for it). What I find best about this SW is its good use of the redefinable 256-color palette (unlike Chess.com's GIF creator, which even dithers colors of the board!) (Well, this should not be a surprise when you compare someone's love project on Github to a corporation's proprietary code they wanted to get done ASAP.)
Cheers!
The following PGN was exported from Lichess.org (line breaks added by me to highlight moves 42 and 54):
When run with this input file, your code outputs no GIF and the exception handler gives the following, rather cryptic message:
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 columng
(there should have been one atG8
). Turns out, your program moved theG8
queen in move 42, "42. .. Qh7
". Either queen (G8
orH1
) 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 to42. 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:
Also, FEN of the above positions for import into a viewer:
So, how could you improve the user experence? In either of two ways:
1. e4 Nf6
becomes1. e2e4 Ng8f6
(if such software exists).Such error reporting could look like this:
Note that in Move 42, White's ambiguous move was resolved as expected while Black's wasn't.