Crafty 23.1 50-Move-Rule Draw Bug

Discussion of chess software programming and technical issues.

Moderator: Ras

jhaglund
Posts: 173
Joined: Sun May 11, 2008 7:43 am

Crafty 23.1 50-Move-Rule Draw Bug

Post by jhaglund »

There seems to be a bug:

Code: Select all

[Event "ICS rated blitz match"]
[Site "80.100.28.169"]
[Date "2009.12.20"]
[Round "-"]
[White "Trace"]
[Black "craftyje"]
[Result "1-0"]
[WhiteElo "1752"]
[BlackElo "1696"]
[TimeControl "600+1"]

1. e4 c5 2. Nf3 d6 3. d4 cxd4 4. Nxd4 Nf6 5. Nc3 g6 6. Be2 Bg7 7. O-O O-O
8. Bg5 Bd7 9. Bc4 Nc6 10. Nxc6 Bxc6 11. Qf3 Rc8 12. Bb3 Nd7 13. Rfe1 Nc5
14. Nd5 Re8 15. c3 h6 16. Bh4 g5 17. Bg3 a5 18. Rad1 Nxb3 19. axb3 b5 20.
Kh1 e6 21. Ne3 f5 22. Bxd6 Bxe4 23. Qe2 Qb6 24. f3 Bc6 25. Rd2 Red8 26.
Red1 Kh7 27. b4 axb4 28. Bxb4 Rxd2 29. Rxd2 Rd8 30. Rd3 Rxd3 31. Qxd3 Kg6
32. Nd1 Qa7 33. Qd2 Qa1 34. Qe2 Bd5 35. Qc2 h5 36. Bc5 h4 37. h3 Be5 38.
Be3 Bc4 39. Kg1 Bc7 40. b3 Bd5 41. Bc1 Be5 42. Kh1 Bf6 43. c4 Bc6 44. c5 b4
45. Ne3 Be7 46. Nd1 Bd5 47. Bb2 Qa2 48. c6 Qa6 49. Ne3 Bxc6 50. Qd2 Qc8 51.
Qd4 Qf8 52. Qb6 Bd7 53. Nc4 Kh5 54. Ne5 Bc8 55. Bd4 Bd6 56. Qc6 Bb8 57. f4
Bxe5 58. Bxe5 Qd8 59. fxg5 Kxg5 60. Bh2 Qd1+ 61. Bg1 Bd7 62. Qb6 Kg6 63.
Qxb4 e5 64. Qb6+ Kf7 65. Qd8 e4 66. Qxh4 Qxb3 67. Qh7+ Ke8 68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Qd4 Qh5+ 151. Kg1 Qh3 152. Qf4#
{craftyje checkmated} 1-0

Move

Code: Select all

102. g3 
was the last pawn move. Since no pawn move was attractive it went for mate instead, but ended up mated to avoid 50-move-rule.

8/8/6bP/5q2/3Q4/5kP1/4p2K/4B3 b - - 0 1

Odd move:

Code: Select all

150. ... Qh5+ 151. Kg1 Qh3 152. Qf4#
Avoiding the 50-Move-Rule with a loss instead.

Should of played...

Code: Select all

150. ... Qxh6 151. Qf2+ Ke4 152. Qxe2+ Qe3 153. Qxe3 Kxe3 =
Joshua D. Haglund
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Crafty 23.1 50-Move-Rule Draw Bug

Post by bob »

jhaglund wrote:There seems to be a bug:

Code: Select all

[Event "ICS rated blitz match"]
[Site "80.100.28.169"]
[Date "2009.12.20"]
[Round "-"]
[White "Trace"]
[Black "craftyje"]
[Result "1-0"]
[WhiteElo "1752"]
[BlackElo "1696"]
[TimeControl "600+1"]

1. e4 c5 2. Nf3 d6 3. d4 cxd4 4. Nxd4 Nf6 5. Nc3 g6 6. Be2 Bg7 7. O-O O-O
8. Bg5 Bd7 9. Bc4 Nc6 10. Nxc6 Bxc6 11. Qf3 Rc8 12. Bb3 Nd7 13. Rfe1 Nc5
14. Nd5 Re8 15. c3 h6 16. Bh4 g5 17. Bg3 a5 18. Rad1 Nxb3 19. axb3 b5 20.
Kh1 e6 21. Ne3 f5 22. Bxd6 Bxe4 23. Qe2 Qb6 24. f3 Bc6 25. Rd2 Red8 26.
Red1 Kh7 27. b4 axb4 28. Bxb4 Rxd2 29. Rxd2 Rd8 30. Rd3 Rxd3 31. Qxd3 Kg6
32. Nd1 Qa7 33. Qd2 Qa1 34. Qe2 Bd5 35. Qc2 h5 36. Bc5 h4 37. h3 Be5 38.
Be3 Bc4 39. Kg1 Bc7 40. b3 Bd5 41. Bc1 Be5 42. Kh1 Bf6 43. c4 Bc6 44. c5 b4
45. Ne3 Be7 46. Nd1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2 Kf6 130. Bc3+ Kf7 131. Qa7+ Ke6
132. Be1 Qe4 133. Qb6+ Kf5 134. Qd6 Kg5 135. Bd2+ Kg4 136. Qd7+ Kf3 137.
Be1 Qe5 138. Qf7+ Qf5 139. Qb7+ Ke3 140. Qa7+ Kd3 141. Qa3+ Ke4 142. Qb3
Bg6 143. Qb7+ Ke3 144. Qb6+ Ke4 145. Qc6+ Ke3 146. Qc3+ Ke4 147. Qb4+ Ke3
148. Qa3+ Ke4 149. Qa4+ Kf3 150. Qd4 Qh5+ 151. Kg1 Qh3 152. Qf4#
{craftyje checkmated} 1-0

Move

Code: Select all

102. g3 
was the last pawn move. Since no pawn move was attractive it went for mate instead, but ended up mated to avoid 50-move-rule.

8/8/6bP/5q2/3Q4/5kP1/4p2K/4B3 b - - 0 1

Odd move:

Code: Select all

150. ... Qh5+ 151. Kg1 Qh3 152. Qf4#
Avoiding the 50-Move-Rule with a loss instead.

Should of played...

Code: Select all

150. ... Qxh6 151. Qf2+ Ke4 152. Qxe2+ Qe3 153. Qxe3 Kxe3 =
Joshua D. Haglund
Thanks, will investigate. There is an exception to the 50 move rule, in that the position is not drawn if one side is mated, regardless of how many reversible moves have been made. This is probably not handled correctly based on this game...
User avatar
hgm
Posts: 28387
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Crafty 23.1 50-Move-Rule Draw Bug

Post by hgm »

Indeed; one should first test for checkmate, and only then for 50-move draws. That would solve the problem.

While you are at it: there also are rumors hat Crafty makes false draw claims (i.e. in violation of FIDE rules) in KBKN end-games.
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: Crafty 23.1 50-Move-Rule Draw Bug

Post by Sven »

hgm wrote:Indeed; one should first test for checkmate, and only then for 50-move draws. That would solve the problem.
My solution for this problem looks like this:

Code: Select all

int fullSearch(...) {
    if (isInCheck()) setCheckFlag();
    // ...
    if (fifty() >= 100 && !isCheckFlagSet()) {
        // draw by 50 moves rule detected when not in check
        return 0;
    }
    // ...
    for (ALL LEGAL MOVES) {
        // regular search ...
    }
    if (NO LEGAL MOVES WERE FOUND) {
        bestValue = (isCheckFlagSet() ? -MATE_VALUE(...) : 0);
    } else
    if (fifty() >= 100) {
        ASSERT(isCheckFlagSet());
        // in check but not mated => draw by 50 moves rule
        bestValue = 0;
    }
    // ...
    return bestValue;
}
It is possible that checking for 50 moves draw also before searching all moves is redundant and skipping this is slightly faster, I have not tested whether this makes any difference. But at least doing it twice looks "logical" for me.

Sven
User avatar
hgm
Posts: 28387
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Crafty 23.1 50-Move-Rule Draw Bug

Post by hgm »

Well, my solution is actually to never check for the 50-move rule, in order not to weaken the engine by having it pay attention to it... :lol:
jhaglund
Posts: 173
Joined: Sun May 11, 2008 7:43 am

Re: Crafty 23.1 50-Move-Rule Draw Bug

Post by jhaglund »


Indeed; one should first test for checkmate, and only then for 50-move draws. That would solve the problem.
I would just check 50 move rule if eval is +/- 5.

I would also offer a draw if it appears no progress will be made:

Code: Select all

active = counter + depth_of_search;
while (active != 50) {
else 
  if(active)
{
check_to_see_if_move_was_an_exchange_or_pawn_move();
if(progress)
{
reset_counter;
}
else
offer_draw();
}
}
While you are at it: there also are rumors hat Crafty makes false draw claims (i.e. in violation of FIDE rules) in KBKN end-games.
I don't think it matters. Player or computer, I'd still offer a draw playing a game.

It's only polite to offer a draw in this endgame. Who wants to move 50 more times? Any FIDE player will accept a draw or just blunder 1 of the pieces too force a draw from lack of mating material...
Vinvin
Posts: 5298
Joined: Thu Mar 09, 2006 9:40 am
Full name: Vincent Lejeune

Re: Crafty 23.1 50-Move-Rule Draw Bug

Post by Vinvin »

Strange, even Rybka have a problem with the eval here :

8/8/6bP/8/3Q4/5kPq/4p3/4B1K1 w - - 0 1

Analysis by Rybka 3 32-bit :

1. = (0.00): 152.Df4#
2. = (0.00): 152.Df2+ Re4
3. = (0.00): 152.Dd5+ Rg4
4. = (0.00): 152.Dc3+ Re4

jhaglund wrote:There seems to be a bug:

Code: Select all

[Event "ICS rated blitz match"]
[Site "80.100.28.169"]
[Date "2009.12.20"]
[Round "-"]
[White "Trace"]
[Black "craftyje"]
[Result "1-0"]
[WhiteElo "1752"]
[BlackElo "1696"]
[TimeControl "600+1"]

1. e4 c5 ...

Move

Code: Select all

102. g3 
was the last pawn move. Since no pawn move was attractive it went for mate instead, but ended up mated to avoid 50-move-rule.

8/8/6bP/5q2/3Q4/5kP1/4p2K/4B3 b - - 0 1

Odd move:

Code: Select all

150. ... Qh5+ 151. Kg1 Qh3 152. Qf4#
Avoiding the 50-Move-Rule with a loss instead.

Should of played...

Code: Select all

150. ... Qxh6 151. Qf2+ Ke4 152. Qxe2+ Qe3 153. Qxe3 Kxe3 =
Joshua D. Haglund
User avatar
hgm
Posts: 28387
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Crafty 23.1 50-Move-Rule Draw Bug

Post by hgm »

jhaglund wrote:I don't think it matters. Player or computer, I'd still offer a draw playing a game.

It's only polite to offer a draw in this endgame. Who wants to move 50 more times? Any FIDE player will accept a draw or just blunder 1 of the pieces too force a draw from lack of mating material...
Offering is not the same as claiming. As it is, Crafty forfeits games by this, and I would say that does matter. If it wants to offer a draw, it should offer it, not one-sidedly terminate the game.

On top of this, there are situations where there is a forced mate that ends in KBKN, because the opponent has to recapture a piece (converting to KBKN) after which he is mated. I have not tested if Crafty makes an exception for this case, but engines that unconditionally declare draw as soon as the material is KBKN will declare draw in some won or lost positions.
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: Crafty 23.1 50-Move-Rule Draw Bug

Post by Sven »

jhaglund wrote:Move

Code: Select all

102. g3 
was the last pawn move.
[...]

8/8/6bP/5q2/3Q4/5kP1/4p2K/4B3 b - - 0 1

Odd move:

Code: Select all

150. ... Qh5+ 151. Kg1 Qh3 152. Qf4#
Avoiding the 50-Move-Rule with a loss instead.

Should of played...

Code: Select all

150. ... Qxh6 151. Qf2+ Ke4 152. Qxe2+ Qe3 153. Qxe3 Kxe3 =
Just for the records: the FEN for the position before 150...Qh5+ should be

8/8/6bP/5q2/3Q4/5kP1/4p2K/4B3 b - - 96 1

to correctly reflect the current state of the 50 moves counter.

Also the preferred move Qxh6 instead of Qh3?? has full move number 151, not 150 :-)

Sven
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: Crafty 23.1 50-Move-Rule Draw Bug

Post by Sven »

bob wrote:Thanks, will investigate. There is an exception to the 50 move rule, in that the position is not drawn if one side is mated, regardless of how many reversible moves have been made. This is probably not handled correctly based on this game...
I can't see such an exception in the 23.1 code. In Search(), line 68, you return with a draw score if the function RepetitionCheck() has returned non-zero. This happens before searching all moves. RepetitionCheck() also handles the 50 moves draw and returns 1 if the 50 moves counter is >= 100. Since mate detection occurs later within Search(), this implementation can't detect the case shown here IMO. Please correct me if I have misunderstood your code.

I propose to separate repetition detection from 50 moves detection by moving the 50-moves related code from RepetitionCheck() into a new function which is then called right below the mate detection code at the bottom of Search(). There should be almost zero performance impact.

Sven