Draw Evaluation solution

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

jhaglund2
Posts: 65
Joined: Mon Jan 16, 2017 6:28 pm

Draw Evaluation solution

Post by jhaglund2 »

Here is a way to correctly evaluate a position as a draw.

A simple trick is utilizing, the 50-move rule counter (while your searching), you count the variation line moves in your evaluation before your final output or display.

Stepping through the PV moves:

1) if it's a pawn move, reset counter at pv move.
2) If it's an a capture, reset counter at pv move.
3) Otherwise, count up to 50 (100). If you reach 50 (100), position is draw.
4) Return 0.00 with a +/- depending on if you are ahead in material or behind.
5) You can decrease the score if you want on the ratio of 50 (100) per ply.

E.g.,

6k1/8/6PP/3B1K2/8/2b5/8/8 b

90-> 7:04/18.00 3.19 1. ... Kf8 2. Bb3 Ba1 3. Be6 Bc3 4. Bd5
Bb2 5. Kg5 Bc3 6. Bc4 Bb2 7. Kf5 Ba1
8. Bf7 Bb2 9. Ba2 Bc3 10. Ke6 Ba1 11. Bb1
Bc3 12. Kf5 Kg8 13. Be4 Ba1 14. Bd5+ Kf8
15. Bc4 Bb2 16. Kg5 Ba1 17. Be6 Bb2
18. Bb3 Ba1 19. Bf7 Bd4 20. Kh5 Bb2
21. Bb3 Bc3 22. Ba2 Ba1 23. Bd5 Bb2
24. Be6 Bc3 25. Bb3 Bb2 26. Bd5 Bd4
27. Be4 Kg8 28. Bc6 Ba1 29. Bd5+ Kf8
30. Kg4 Bb2 31. Be6 Ba1 32. Bb3 Bc3
33. Bc2 Ba1 34. Kh5 Bc3 35. Be4 Kg8
36. Bd5+ Kf8 37. Bc4 Bd4 38. Ba2 Bb2
39. Kg4 Bc3 40. Kf3 Ba1 41. Ke4 Bc3
42. Kf5 Ba1 43. Ke6 Bc3 44. Bd5 Ba1
45. Bc4 Bc3 46. Kf5 Ba1 47. Bf7 Bb2
48. Ba2 Bc3 49. Ke6 Ba1 50. Bb1 Bc3
51. Kf5 Kg8 52. Be4 Ba1 53. Bd5+ Kf8
54. Bc4 Bb2 55. Kg5 Ba1 56. Be6 Bb2
57. Bb3 Ba1 58. Bd5 Bb2 59. Kh5 Bd4
60. Ba2 Bb2 61. Kg4 Bc3 62. Kf3 Ba1
63. Ke4 Bc3 64. Kf5 Ba1 ...

No pawn moves, no captures. This should evaluate as 0.00- long before reaching ply 90.
You could easily identify the moves as just 2 types: e.g., pawn=0, capture=0, regular=1 ...

This will solve all drawn positions if you count the variation moves and add them too your 50-move-rule counter on the go!

You maybe already have endgame knowledge. I think the preferred line is:

Crafty 25.2 JE
124-> 3:02/18.00 0.00 1. ... Kf8 2. Ke4 Ba1 3. Kd3 Bb2 4. Kc2
Be5 5. Bc6 Bd4 6. Kd3 Bf6 7. Kc2 Bd4
<3-fold>

Winner, right from the get go.

:wink:
Robert Pope
Posts: 558
Joined: Sat Mar 25, 2006 8:27 pm

Re: Draw Evaluation solution

Post by Robert Pope »

I'm trying to see if I'm missing something, but isn't this the only way to do it? Doesn't every engine that implements the 50-move rule do pretty much exactly this?
User avatar
Evert
Posts: 2929
Joined: Sat Jan 22, 2011 12:42 am
Location: NL

Re: Draw Evaluation solution

Post by Evert »

Stepping through the PV is insufficient, you need to include the entire game history in that consideration. I think most just keep track of a half-move counter that gets reset when capturing or moving a pawn. When that reaches 100 half-moves, the search is terminated immediately.
Robert Pope
Posts: 558
Joined: Sat Mar 25, 2006 8:27 pm

Re: Draw Evaluation solution

Post by Robert Pope »

I assume the 50-move counter is appropriately set at the start of the PV, which amounts to the same thing.
AlvaroBegue
Posts: 931
Joined: Tue Mar 09, 2010 3:46 pm
Location: New York
Full name: Álvaro Begué (RuyDos)

Re: Draw Evaluation solution

Post by AlvaroBegue »

I've always implemented the counter inside the structure that describes the board, similarly to how castling rights and en-passant possibility are handled. I assumed that's how everyone else did it too.
jhaglund2
Posts: 65
Joined: Mon Jan 16, 2017 6:28 pm

Re: Draw Evaluation solution

Post by jhaglund2 »

It would describe the board at the end of the PV, not the beginning.
AlvaroBegue (Álvaro Begué) I've always implemented the counter inside the structure that describes the board, similarly to how castling rights and en-passant possibility are handled. I assumed that's how everyone else did it too.

It would be like going to the end of the PV and checking what the 50-move counter would be.

Robert Pope (Robert Pope)
PostPosted: Fri Mar 03, 2017 7:51 pm Post subject: Re: Draw Evaluation solution
I assume the 50-move counter is appropriately set at the start of the PV, which amounts to the same thing.
It sure is. It was easier to explain. I know, in Crafty, the counter is not added after each ply based on the type of move.
Evert (Evert Glebbeek)
PostPosted: Fri Mar 03, 2017 7:40 pm Post subject: Re: Draw Evaluation solution
Stepping through the PV is insufficient, you need to include the entire game history in that consideration. I think most just keep track of a half-move counter that gets reset when capturing or moving a pawn. When that reaches 100 half-moves, the search is terminated immediately.

What's missing is that you check the last move in the PV variation to see what the counter would be at.
Robert Pope (Robert Pope)
PostPosted: Fri Mar 03, 2017 6:31 pm Post subject: Re: Draw Evaluation solution
I'm trying to see if I'm missing something, but isn't this the only way to do it? Doesn't every engine that implements the 50-move rule do pretty much exactly this?
E.g.,
6k1/8/6PP/3B1K2/8/2b5/8/8 b

90-> 7:04/18.00 3.19 1. ... Kf8 2. Bb3 Ba1 3. Be6 Bc3 4. Bd5
Bb2 5. Kg5 Bc3 6. Bc4 Bb2 7. Kf5 Ba1
8. Bf7 Bb2 9. Ba2 Bc3 10. Ke6 Ba1 11. Bb1
Bc3 12. Kf5 Kg8 13. Be4 Ba1 14. Bd5+ Kf8
15. Bc4 Bb2 16. Kg5 Ba1 17. Be6 Bb2
18. Bb3 Ba1 19. Bf7 Bd4 20. Kh5 Bb2
21. Bb3 Bc3 22. Ba2 Ba1 23. Bd5 Bb2
24. Be6 Bc3 25. Bb3 Bb2 26. Bd5 Bd4
27. Be4 Kg8 28. Bc6 Ba1 29. Bd5+ Kf8
30. Kg4 Bb2 31. Be6 Ba1 32. Bb3 Bc3
33. Bc2 Ba1 34. Kh5 Bc3 35. Be4 Kg8
36. Bd5+ Kf8 37. Bc4 Bd4 38. Ba2 Bb2
39. Kg4 Bc3 40. Kf3 Ba1 41. Ke4 Bc3
42. Kf5 Ba1 43. Ke6 Bc3 44. Bd5 Ba1
45. Bc4 Bc3 46. Kf5 Ba1 47. Bf7 Bb2
48. Ba2 Bc3 49. Ke6 Ba1 50. Bb1 Bc3
51. Kf5 Kg8 52. Be4 Ba1 53. Bd5+ Kf8
54. Bc4 Bb2 55. Kg5 Ba1 56. Be6 Bb2
57. Bb3 Ba1 58. Bd5 Bb2 59. Kh5 Bd4
60. Ba2 Bb2 61. Kg4 Bc3 62. Kf3 Ba1
63. Ke4 Bc3 64. Kf5 Ba1 ..

Jump to last move, 64. ... Ba1, what is your 50 move counter at ply 1; return DrawScore(); else go to next ply.
Ras
Posts: 2487
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: Draw Evaluation solution

Post by Ras »

jhaglund2 wrote:Stepping through the PV moves:
Why only the PV? It makes more sense to include this already in the search, and then for all variants. Especially in defence, this is what easily can make a variant the PV because it may be second class, but leads to a 50-move-draw. To save thinking time, this should only activate if such a draw is likely to appear, i.e. if the root position already has seen a lot of "no action" moves.

In the CT800, I have included another trick that kicks in after 40 "no action" plies: the absolute of the eval is gradually reduced from 100% (regular eval) in move 20 to 40% target at move 50. This way, the draw doesn't suddenly pop up out of nowhere when it enters the horizon.

In attack, this allows the CT800 to make a draw resetting move when it is somewhat logical. In defence, it will more actively head for a draw by avoiding action moves.
jhaglund2
Posts: 65
Joined: Mon Jan 16, 2017 6:28 pm

Re: Draw Evaluation solution

Post by jhaglund2 »

It doesn't have to be just the PV like you mentioned. The main purpose is to return a score that reflects a draw 0.00 +/-, not like the e.g., +3.19... This is the solution for that; check the PV for 50-move-counter at the tips, not just the root.


Ras wrote:
jhaglund2 wrote:Stepping through the PV moves:
Why only the PV? It makes more sense to include this already in the search, and then for all variants. Especially in defence, this is what easily can make a variant the PV because it may be second class, but leads to a 50-move-draw. To save thinking time, this should only activate if such a draw is likely to appear, i.e. if the root position already has seen a lot of "no action" moves.

In the CT800, I have included another trick that kicks in after 40 "no action" plies: the absolute of the eval is gradually reduced from 100% (regular eval) in move 20 to 40% target at move 50. This way, the draw doesn't suddenly pop up out of nowhere when it enters the horizon.

In attack, this allows the CT800 to make a draw resetting move when it is somewhat logical. In defence, it will more actively head for a draw by avoiding action moves.