lengyanyu258 / xiangqi.js

A Javascript Chinese chess/cchess/Xiangqi library for Xiangqi move generation/validation, piece placement/movement, and check/checkmate/draw detection
https://lengyanyu258.github.io/xiangqiboardjs/examples.html#5002
BSD 2-Clause "Simplified" License
25 stars 11 forks source link

Problems reading strings using load_pgn(). #12

Closed GZ-Metal-Cell closed 2 months ago

GZ-Metal-Cell commented 4 months ago

When I use load_pgn() to read the following string, which is a fen not for the initial state of the game:

const pgn =['[Game "Chinese Chess"]',
 '[Event "许银川让九子对聂棋圣"]',
 '[Date "1999.12.09"]',
 '[Red "许银川"]',
 '[Black "聂卫平"]',
 '[Result "1-0"]',
 '[Format "ICCS"]',
 '[FEN "rnbakabnr/9/1c5c1/p1p1p1p1p/9/9/P1P1P1P1P/1C5C1/9/RNBAKABNR w - - 0 1"]',
 '',
 '1. b2e2 h7e7',
 '2. e2e7 g9e7',
 '3. h2e2 h9g7',
 '4. h0g2 i9h9',
 '5. b0c2 b9a7',
 '6. a0d0 a9b9',
 '7. d0d8 b7b0',
 '8. i0i4 b0a0',
 '9. c2b4 a0a4',
 '10. b4c2 a4a0',
 '11. c2b4 b9b7',
 '12. e2b2 a0a4',
 '13. b2b7 a4i4',
 '14. b7g7 h9h7',
 '15. g7g8 h7h5',
 '16. b4d5 i4e4',
 '17. g8i8 f9e8',
 '18. d5f6 h5e5',
 '19. e0d0 e5f5',
 '20. f6g8 e9f9',
 '21. d8d4 e6e5',
 '22. d4d6 e4g4',
 '23. g8h6 e7g5',
 '24. h6g4 e5e4',
 '25. d6g6 e4f4',
 '26. g6g9 f9f8',
 '27. g2h4 e8f7',
 '28. h4g6 f8e8',
 '29. g6h8 e8e7',
 '30. g9d9 f7e8',
 '31. h8g6 f5f6',
 '32. d9d6 f6g6',
 '33. d6g6 f4g4',
 '34. g6e6 e7f7',
 '35. d0e0 f7f8',
 '36. e6e8 f8f9',
 '37. e8e9 f9f8',
 '38. e9c9']

Use game.load_pgn(pgn.join('\n')) will return False. After query, I found that 'load_pgn()' does not recognize [Fen] in the content, that this is an initial game lead to identification failure, is there a way to solve it?

lengyanyu258 commented 4 months ago

I'm very sorry about this issue that it's my lazy fault for load_pgn() is still under development...

However the test cases have all passed, so you can refer to the passed cases to modify your pgn string:

https://github.com/lengyanyu258/xiangqi.js/blob/41a5ecda10ba34a63def3202065a18211f30bf9a/__tests__/xiangqi.test.js#L1133

I'm busy for something else nowadays, maybe I will add this test case and fix it after one or two months later...

Sorry again.

lengyanyu258 commented 2 months ago

Okay, the FEN in header string is wrong for this game:

We have:

https://github.com/lengyanyu258/xiangqi.js/blob/41a5ecda10ba34a63def3202065a18211f30bf9a/__tests__/xiangqi.test.js#L1301

But you've:

 '[FEN "rnbakabnr/9/1c5c1/p1p1p1p1p/9/9/P1P1P1P1P/1C5C1/9/RNBAKABNR w - - 0 1"]',

The FEN should be 9/1C5C1/9/RN2K2NR, but yours is P1P1P1P1P/1C5C1/9/RNBAKABNR.

Fortunately, we both have the same PGN.