Closed Huub62 closed 2 months ago
I downloaded the zip, extracted the PGN (and the image that showed the error). I suspect you did the following:
I think that the reason is, that the loaded game does not correctly set the initial position. The configuration of the viewer does not have an initial position (this has to come from the games themselves, correctly set here), and because the initial position is the standard setup, the error message: No legal move: Rxf3#
is shown, because that move is not possible in the initial position.
I will check, and perhaps I can come up with a fix on this weekend (hope that, don't know).
Thank you a lot for the excellent issue report, that should make fixing it easy.
It seems to be a problem in the pgn-reader, so I will create a ticket there, create some test cases to reproduce the error, hopefully will find an easy fix, do a new release there, and then have it fixed in the pgn-viewer as well. See pgn-reader#ticket48 for that.
Digging deeper and deeper ... the library chess.js is picky in interpreting the FEN string. See what Lichess does with the following: https://lichess.org/analysis/fromPosition/8/1p6/p3pR2/4R3/4b3/2B1kp1P/PP2r1P1/6K1_w_-_-_0_0
That is an analysis board, where the FEN ends with '0 0', but lichess shows '0 1'. If I change that, the chess.js library is able to read the FEN. Don't know if that everything is working, though.
Checked that now, the position is not shown correctly, so there is another fault in it. But coming closed ... I have to find a solution to make the library chess.js
much more robust here. Perhaps I will repeat, in cutting off unnecessary information (for the reader in using chess.js).
Found the bug, fixed pgn-reader first, new release, then pgn-viewer. I have created the ticket example https://github.com/mliebelt/pgn-viewer/blob/main/examples/tickets/ticket565.html
I will file a separate bug/improvement to be more robust if the FEN is not valid (last number must be 1 or bigger). But that is a separate topic ...
Could you check the new release 1.6.10, and fix some of your examples, so that FEN is valid? I hope this works then as expected.
Thank you for your amazingly quick responses. I was busy most of the day and unable to respond sooner. But now I did quickly install the new version 1.6.10 and ran a test. With the pgn-file with the "0 0" at the end of the FEN code it indeed goes wrong and causes errors. If I replace them with "0 1" all goes well as far as I can see now.
One minor thing i noticed was that "$11" in the pgn-file is ignored while it should be replaced by "=".
I will try to do some more testing in the next few days, but so far I am really impressed. Thank you so much for solving this issue, that prevented me from using the pgn-viewer the way I had hoped.
One caveat on $11 and $12. If you look at the original resources, the PGN Spec does not define the symbols, only the numbers. Symbols were taken all from Wikipedia NAGs. There you will find that $10 has a symbol, but $11 and $12 don't have one. It is reasonable to use for them the same symbol, but it is not part of the standard, then.
Yes, i have read the wikipedia nags. But wouldnt it be a good idea to implement them anyway since they are used by some of the most used programs and websites? It would make it so much easier for users to use existing pgn's and not having to do a lot of search and replace actions first.
If you want to see the '=', use the $10. If you want to have that different meaning of $11 or $12, you have to use the NAGs anyway. The only difference is, that the reader / viewer will show '=' instead of '$11' or '$12'. So the PGN remains the same, only the showing of PGN in the viewer changes.
This problem is related to multigame pgn's with comments, variants etc. in it.
If i upload a simple pgn with only complete games and nothing special in it, for instance the twic-01-232games.pgn then all works just fine. But if i try a more complicated pgn, with positions, variations, comments etc. then it crashes. The pgn's I tried it with I have tested on chessbase, chess.com and lichess and never cause any problems, so I must assume they are correct.
Here is what happens ... If i upload the file it correctly fills the dropdownlist and the startposition from the first game is shown. If however I start to pick other games/positions from the list two things can happen .....the board no longer updates and/or the error "Uncaught Error: No legal move" appears.
Once the error has occured nothing works anymore. No boards updates and every click on every move causes another error. The error even mentions moves that aren't related to the position on the board. issue.zip