SebLague / Chess-Challenge

Create your own tiny chess bot!
https://www.youtube.com/watch?v=Ne40a5LkK6A
MIT License
1.78k stars 1.06k forks source link

[BUG] Halfmove counter is broken #183

Closed Disservin closed 1 year ago

Disservin commented 1 year ago
position fen rn1q1rk1/p1p2ppp/bp1ppn2/8/2PP4/P1N1P3/1P2BPPP/R1BQK2R w KQ - 0 1 moves e2f3 c7c6 d1b3 a6b7 c3e4 d8c7 e4f6 g7f6 e3e4 c6c5 c1h6 f8c8 h6e3 c5d4 e3d4 c7c4 b3c4 c8c4 d4f6 b8d7 b2b3 c4c5 f6d4 c5b5 a1b1 b5a5 b1a1 d7c5 b3b4 a5a4 d4c5 b6c5 f3d1 a4a6 d1e2 a6b6 b4c5 d6c5 e4e5 f7f6 e5f6 a8f8 e2f3 f8f6 h1g1 e6e5 a1d1 b7f3 g2f3 g8f8 g1g5 f6f3 g5e5 f3a3 d1c1 a3f3 c1c5 b6f6 c5c8 f8f7 c8c2 f7g6 c2a2 f3f4 e5e3 f4f3 e3f3 f6f3 a2a7 f3f5 a7e7 f5f4 e1e2 f4f5 e2f1 f5f4 f1e1 f4f5 e1e2 f5f4 e2e3 f4f5 f2f3 g6h6 e3e4 h6g6 e7e6 f5f6 e6e5 h7h6 e4e3 g6f7 e3d2 f6f3 d2e2 f3h3 e2d1 h3h2 d1c1 f7f6 c1b1 f6e5 b1a1 e5d4 a1b1 d4c3 b1a1 c3c2 a1a2 h2h1 a2a3 c2c3 a3a2

8/8/7p/8/8/2k5/K7/7r b - - 113 57 This is the fen that you will get, as you can see the half moves are incorrect. A rather big bug because isDraw() wont return the correct result. It should be 8/8/7p/8/8/2k5/K7/7r b - - 11 57

Here is the pgn in case you need it

[Event "?"]
[Site "?"]
[Date "2023.07.22"]
[Round "5"]
[Result "1/2-1/2"]
[FEN "rn1q1rk1/p1p2ppp/bp1ppn2/8/2PP4/P1N1P3/1P2BPPP/R1BQK2R w KQ - 0 1"]
[GameDuration "00:00:20"]
[PlyCount "118"]
[Set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.04/5 0.13s} 40. Ke2 Rf4 {-0.04/5 0.13s} 41. Ke3
Rf5 {-0.04/5 0.12s} 42. f3 Kh6 {-0.02/5 0.12s} 43. Ke4 Kg6 {-0.94/5 0.12s}
44. Re6+ Rf6 {-1.00/6 0.12s} 45. Re5 h6 {-0.02/5 0.12s} 46. Ke3
Kf7 {-0.02/5 0.11s} 47. Kd2 Rxf3 {0.00/5 0.11s} 48. Ke2 Rh3 {+0.84/5 0.11s}
49. Kd1 Rxh2 {+0.86/5 0.11s} 50. Kc1 Kf6 {+0.88/5 0.11s} 51. Kb1
Kxe5 {+5.91/6 0.11s} 52. Ka1 Kd4 {+5.91/6 0.10s} 53. Kb1 Kc3 {+500.00/7 0.10s}
54. Ka1 Kc2 {+500.00/7 0.10s} 55. Ka2 Rh1 {+500.00/6 0.10s} 56. Ka3
Kc3 {+500.00/6 0.10s} 57. Ka2
Disservin commented 1 year ago

To reproduce

        Board b = Board.CreateBoardFromFEN("rn1q1rk1/p1p2ppp/bp1ppn2/8/2PP4/P1N1P3/1P2BPPP/R1BQK2R w KQ - 0 1");

        string moves = "e2f3 c7c6 d1b3 a6b7 c3e4 d8c7 e4f6 g7f6 e3e4 c6c5 c1h6 f8c8 h6e3 c5d4 e3d4 c7c4 b3c4 c8c4 d4f6 b8d7 b2b3 c4c5 f6d4 c5b5 a1b1 b5a5 b1a1 d7c5 b3b4 a5a4 d4c5 b6c5 f3d1 a4a6 d1e2 a6b6 b4c5 d6c5 e4e5 f7f6 e5f6 a8f8 e2f3 f8f6 h1g1 e6e5 a1d1 b7f3 g2f3 g8f8 g1g5 f6f3 g5e5 f3a3 d1c1 a3f3 c1c5 b6f6 c5c8 f8f7 c8c2 f7g6 c2a2 f3f4 e5e3 f4f3 e3f3 f6f3 a2a7 f3f5 a7e7 f5f4 e1e2 f4f5 e2f1 f5f4 f1e1 f4f5 e1e2 f5f4 e2e3 f4f5 f2f3 g6h6 e3e4 h6g6 e7e6 f5f6 e6e5 h7h6 e4e3 g6f7 e3d2 f6f3 d2e2 f3h3 e2d1 h3h2 d1c1 f7f6 c1b1 f6e5 b1a1 e5d4 a1b1 d4c3 b1a1 c3c2 a1a2 h2h1 a2a3 c2c3 a3a2";

      string[] moves_split = moves.Split(' ');

      foreach (string move_str in moves_split)
      {
          b.MakeMove(new Move(move_str, b));
      }

      Console.WriteLine(b.GetFenString());
mcthouacbb commented 1 year ago

154 Already mentioned here.

Disservin commented 1 year ago

Ah yes, I'll leave this open because it's easier for @SebLague to test.

SebLague commented 1 year ago

Hi, thanks for the heads-up! It's not quite as serious as it seems because the fifty move counter is reset correctly with actual game moves (so would only cause problems for super deep searches). Still a weird behaviour though of course, and I will patch it.

SebLague commented 1 year ago

Fixed in latest patch, thanks again!