ngx-chess-board icon indicating copy to clipboard operation
ngx-chess-board copied to clipboard

Possible bug with setPGN

Open thecko opened this issue 1 year ago • 5 comments

Hello, I'm using your board to make a chess game viewer. For that I have a code that splits PGN moves and depending on the turn it concats moves and calls setPGN to show every turn on the game.

I'm having problems with this PGN:

1. e4 e6 2. d4 {[1:29:27]} d5 {[1:25:37]} 3. Nc3 {[1:29:56]} Nf6 4. e5 {[1:30:15]} Nfd7 {[1:26:25]} 5. f4 {[1:30:32]} c5 {[1:27:01]} 6. Nf3 {[1:30:50]} Nc6 {[1:27:24]} 7. Be3 {[1:29:01]} Qb6 {[1:27:35]} 8. Na4 {[1:29:15]} Qa5+ {[1:27:58]} 9. c3 {[1:24:57]} b6 {[1:28:13]} 10. Be2 {[1:21:28]} Ba6 {[1:26:41]} 11. Bxa6 {[1:19:12]} Qxa6 {[1:22:54]} 12. b3 {[1:12:36]} Rc8 {[1:20:01]} 13. Qe2 {[1:07:07]} Qa5 {[1:15:03]} 14. O-O {[1:01:53]} c4 {[1:12:00]} 15. Qc2 {[0:58:27]} b5 {[1:00:18]} 16. Nb2 {[0:50:13]} Ba3 {[0:56:33]} 17. Nd1 {[0:47:52]} Ne7 {[0:54:01]} 18. g4 {[0:41:22]} g6 {[0:52:54]} 19. b4 {[0:38:53]} Qb6 {[0:53:17]} 20. Bc1 {[0:37:25]} Bxc1 {[0:53:33]} 21. Rxc1 {[0:37:17]} a5 {[0:53:09]} 22. a3 {[0:34:11]} h6 {[0:51:01]} 23. Qf2 {[0:32:00]} Ra8 {[0:43:14]} 24. Nh4 {[0:24:51]} Kd8 {[0:42:35]} 25. f5 {[0:20:40]} g5 {[0:41:42]} 26. fxe6 {[0:20:16]} fxe6 {[0:33:04]} 27. Ng2 {[0:15:20]} Rf8 {[0:33:29]} 28. Qxf8+ {[0:15:20]} Nxf8 {[0:33:29]} 29. Rxf8+ {[0:15:44]} Kd7 {[0:33:55]} 30. Rxa8 {[0:11:51]} Nc6 {[0:34:44]} 31. bxa5 {[0:10:54]} Nxa5 {[0:33:58]} 32. Nde3 {[0:10:54]} Nc6 {[0:33:58]} 33. Rh8 {[0:08:25]} Nxd4 {[0:32:38]} 34. cxd4 {[0:06:10]} Qxd4 {[0:32:36]} 35. Rxh6 {[0:06:10]} Qxe5 {[0:31:12]} 36. Rd1 {[0:04:17]} d4 {[0:31:12]} 37. Nc2 {[0:01:07]} d3 {[0:23:44]} 38. Nce3 {[0:01:07]} Qc5 {[0:23:44]} 39. Rh5 {[0:00:38]} Kc6 {[0:23:25]} 40. Kf1 {[0:11:28]} Qxa3 {[0:48:03]} 41. Rh8 {[0:09:59]} Qb2 {[0:34:59]} 42. Rf8 {[0:08:46]} Qe5 {[0:33:34]} 43. Kg1 {[0:07:44]} Qd4 {[0:33:34]} 44. Rc8+ {[0:07:44]} Kb7 {[0:24:35]} 45. Rf8 {[0:03:50]} b4 {[0:23:27]} 46. Rb1 {[0:03:50]} c3 {[0:23:27]} 47. Kh1 {[0:02:09]} c2 {[0:18:48]} 48. Rf7+ {[0:01:49]} Kc6 {[0:17:31]} 49. Rc1 {[0:01:03]} b3 {[0:16:16]} 50. Rff1 {[0:01:03]} Kb5 {[0:14:40]} 51. h3 {[0:00:54]} Qh8 {[0:14:40]} 52. Kh2 {[0:01:06]} Qe5+ {[0:13:29]} 53. Kg1 {[0:00:52]} d2 {[0:12:31]} 54. Rxc2 {[0:01:21]} bxc2 {[0:12:31]} 55. Nxc2 {[0:01:21]} Kc4 {[0:12:31]} 56. Nce3+ {[0:01:21]} Kb3 {[0:08:43]} 57. Rd1 {[0:01:59]} Qd4 {[0:08:30]} 58. Kh2 e5 59. Kg1 {[0:02:08]} e4 {[0:08:30]} 60. Kf1 {[0:02:05]} Kc3 {[0:08:04]} 61. Kf2 {[0:02:39]} Qd3 {[0:07:10]} 62. Ke2 Qd4 {[0:07:12]} 63. Kf2 {[0:03:07]} Qd3 {[0:06:29]}  1/2-1/2

If you take a look to moves 60 and beyond you'll see this:

61. Kf2 {[0:02:39]} Qd3 {[0:07:10]} 
62. Ke2 Qd4 {[0:07:12]} 
63. Kf2 {[0:03:07]} Qd3 {[0:06:29]}
64.

If you load the game you'll be able to see that in turn 61 black player moves the queen to d3 and then white player moves king to e2. This is dumb because it'll be a check mate, but this PGN it's from a real game so I'm assuming black player did not noticed and moved back queen to d4.

If I do a setPGN with the moves from 1 to 61 works well. When I add turn 62 the king does not move.

So I assumed it's not a "valid" movement (technically, it is I think) and then I tried to use the freemode option to true and then something stranger happened.

13. Qe2 {[1:07:07]} Qa5 {[1:15:03]} 
14. O-O {[1:01:53]} c4 {[1:12:00]} 
16. Qc2 {[0:58:27]} b5 {[1:00:18]} 

If you take a look to move 14th there's a kingside castling. When freemode is false it works correctly, but with freemode to true king moves to the correct place but rook remains in the original spot.

image Freemode = false

image Freemode = true

It's a bug or am I doing something wrong?

thecko avatar Oct 18 '22 10:10 thecko

Hi thank you for this issue I checked the PNG you wrote and after 61 move the Ke2 move isn't correct as you mentioned and the board doesnt load it as it loads only valid moves. Enabling free mode wont help in this case - this mode lets you to drag pieces without any constraints. It is more for position analysis where you may want to move pieces freely to any square (CTRL + LMB on piece deletes it btw :) ). Castling isnt performed with free mode on. I think you need to put only valid PGNs and it should work fine

grzegorz103 avatar Oct 19 '22 17:10 grzegorz103

But why it is not correct? Because it'll be check mate? AFAIK technically in a real play you'll be able to do this move (and then loose to the queen). Am I wrong?

Those PGN are from real games and I think they're the real moves executed.

Why castling are not performed in free mode?

thecko avatar Oct 19 '22 18:10 thecko

e2 square is covered by queen. Thats not checkmate but you cant make move with king to a square which is covered by queen (or any other pieces). In real play you cant make this move.

Castling isnt performed in free mode because it moves pieces freely, lets say you may want to move king by two squares to set some position and dont want to make castle. If you wanted to make castle then you would have to move rook manually in 2nd move

grzegorz103 avatar Oct 19 '22 19:10 grzegorz103

I'm sorry to insist, why it's a non valid move? In a real play will not be able to move there the king and then lose the game by the queen killing it? It's an stupid move, but not invalid or am I wrong?

thecko avatar Oct 19 '22 19:10 thecko

Thats illegal move and cannot be maken. Thats against chess rules that you cant move the king to a square which enemys piece has covered. Lets say we got this simple PGN for example

  1. d4 e5 2. e4 Qg5 you can see you cant move the king from e1 to d2 because queen is covering it. Thats the same situation with your given PGN

grzegorz103 avatar Oct 19 '22 19:10 grzegorz103