preventing 3-fold repetition

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

flok

preventing 3-fold repetition

Post by flok »

Hi,

In the tourney of January (http://talkchess.com/forum/viewtopic.ph ... ight=embla), it was mentioned that embla lost by a 3-fold repetition.

To make sure that won't happen again, I experimented a bit with it.
The 3-fold rep. was with "if position occured before, use score 0".
Now I tried with "skip the move" and "score = -min_mate_value". These two experiments both played far worse (-300 elo) than the score=0 version.

What would be the best to do?
User avatar
hgm
Posts: 27789
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: preventing 3-fold repetition

Post by hgm »

I thought 3-fold repetition always was a draw in Chess. Only in Shogi and Xiangqi it can be losing. So how could you lose by 3-fold repetition?
flok

Re: preventing 3-fold repetition

Post by flok »

Ehr right, yes, right :-) What I meant is draw, which is somewhat the same as loosing for me :-)
kbhearn
Posts: 411
Joined: Thu Dec 30, 2010 4:48 am

Re: preventing 3-fold repetition

Post by kbhearn »

score = 0 is correct and should score best of course against similar opposition... score = -contempt would be the draw avoidance option and should provide some edge against opponents weaker than you while hurting you against similar or stronger opponents. setting contempt to mate is a wee bit extreme!

(note that -contempt needs to be from the engine's perspective not the side to move's)
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: preventing 3-fold repetition

Post by Sven »

flok wrote:Ehr right, yes, right :-) What I meant is draw, which is somewhat the same as loosing for me :-)
Are you sure that the repetition detection works correctly?

Another option might be that in the given game (against Skipper?) playing for the repetition was actually the best choice. I don't know the game so I can't judge about it.
flok

Re: preventing 3-fold repetition

Post by flok »

Sven Schüle wrote:
flok wrote:Ehr right, yes, right :-) What I meant is draw, which is somewhat the same as loosing for me :-)
Are you sure that the repetition detection works correctly?
I'm fairly certain. How I've implemented it: after doMove() I generate the TT-hash for the new position. Then I check if that hash is already in an std::unordered_set. If so: then things are repeating. If not: then store the hash and proceed.
Another option might be that in the given game (against Skipper?) playing for the repetition was actually the best choice. I don't know the game so I can't judge about it.
That was against skipper yes. I don't have the png unfortunately either but I thought maybe repetition-handling is the reason for the bad play.
MahmoudUthman
Posts: 234
Joined: Sat Jan 17, 2015 11:54 pm

Re: preventing 3-fold repetition

Post by MahmoudUthman »

Do you remember to remove the hash from the set in unmake ?
brtzsnr
Posts: 433
Joined: Fri Jan 16, 2015 4:02 pm

Re: preventing 3-fold repetition

Post by brtzsnr »

Just a reminder:

- Draw against a weaker opponent is 0.5 points lost.
- Draw against a stronger opponent is 0.5 points won.

Some engines use contempt to avoid or force a draw: https://chessprogramming.wikispaces.com/Contempt+Factor
flok

Re: preventing 3-fold repetition

Post by flok »

@mahmoud: yes I remove the hash.

@alexandru: yes but with a weak program as mine every (half-)point counts :-)
Henk
Posts: 7216
Joined: Mon May 27, 2013 10:31 am

Re: preventing 3-fold repetition

Post by Henk »

flok wrote:
Sven Schüle wrote:
flok wrote:Ehr right, yes, right :-) What I meant is draw, which is somewhat the same as loosing for me :-)
Are you sure that the repetition detection works correctly?
I'm fairly certain. How I've implemented it: after doMove() I generate the TT-hash for the new position. Then I check if that hash is already in an std::unordered_set. If so: then things are repeating. If not: then store the hash and proceed.
Another option might be that in the given game (against Skipper?) playing for the repetition was actually the best choice. I don't know the game so I can't judge about it.
That was against skipper yes. I don't have the png unfortunately either but I thought maybe repetition-handling is the reason for the bad play.
You probably mean this one. See end position. I don't think that playing for the repetition was here the best choice.

[pgn]
[Event "ICS rated blitz match"]
[Site "winboard.nl"]
[Date "2016.01.16"]
[Round "-"]
[White "Skipper"]
[Black "Embla"]
[Result "1/2-1/2"]
[WhiteElo "1120"]
[BlackElo "1051"]
[TimeControl "300+1"]
[Annotator "1. +0.00"]

1. Na3 {+0.00/26 6} e5 2. Nc4 {+0.00/19 6} e4 3. Rb1 {+0.00/18 6} d5 4. Na3
{+0.00/18 6} Nc6 5. f4 {+0.00/15 6} d4 6. g3 {+0.00/17 6} Qd5 7. Ra1
{+0.00/18 5} Bxa3 8. bxa3 {+0.20/19 5} Nf6 9. e3 {+0.20/17 5} dxe3 10. dxe3
{+0.20/16 5} Qc5 11. Ne2 {+0.20/14 5} Be6 12. Qd2 {+0.20/16 5} Rd8 13. Qc3
{+0.20/17 5} Rd5 14. Qxc5 {+0.20/18 5} Rxc5 15. c3 {+0.20/18 5} O-O 16. Bd2
{+0.20/17 5} Ra5 17. Bc1 {+0.20/18 5} Rc5 18. Bd2 {+0.00/18 5} Ra5 19. Bc1
{+0.00/20 4} Rd8 20. Rb1 {+0.20/16 4} b6 21. Ra1 {-0.40/16 4} Rc5 22. h3
{+0.20/16 5} h6 23. Bd2 {+0.20/17 5} Ra5 24. Bc1 {+0.20/17 5} Rc5 25. Bg2
{+0.20/18 5} g6 26. Kf2 {+0.20/17 5} g5 27. fxg5 {+0.20/15 5} Rf5+ 28. Nf4
{+0.20/17 5} hxg5 29. g4 {+0.20/17 5} Rc5 30. Ne2 {+0.20/16 4} Ne5 31. Kg3
{+0.00/13 4} Nd3 32. Rd1 {-0.50/14 4} Kg7 33. Nd4 {-0.60/14 4} Bd7 34. Bd2
{-0.60/14 4} Ra5 35. Rdb1 {-0.60/15 4} Rxa3 36. Nb5 {-0.60/15 4} Bxb5 37.
Rxb5 {-0.60/12 4} Nc5 38. Rb2 {-0.60/16 4} Nd3 39. Rb5 {+0.00/20 4} Nc5 40.
Rb2 {+0.00/21 4} Ra5 41. Rab1 {-0.40/16 4} Nd3 42. Rc2 {-0.40/15 2.3} Ne5
43. Be1 {-0.40/14 2.3} Nc4 44. Re2 {-0.40/14 2.3} Rd3 45. Kf2
{-0.40/14 2.2} b5 46. Ra1 {-0.40/15 2.3} Ra6 47. Rb1 {-0.40/15 2.3} Rb6 48.
Bh1 {-0.40/14 2.2} a6 49. Rc1 {-1.20/14 2.2} Re6 50. Kg1 {-1.20/15 2.2} Nd5
51. Rh2 {-1.40/13 2.1} Ndxe3 52. Bf2 {-1.20/14 2.2} c5 53. Be1
{-1.20/16 2.1} Nd5 54. h4 {-1.40/14 2.0} gxh4 55. Rxh4 {-1.40/13 2.2} Nf4
56. Kh2 {-2.00/13 2.0} Ne3 57. Rb1 {-2.00/13 2.0} f6 58. c4 {-2.00/12 2.0}
Nxc4 59. Rc1 {-2.00/13 2.1} Re8 60. Rc2 {-2.20/13 2.0} Ng6 61. Rh5
{-2.20/14 1.9} Rd1 62. Bg3 {-2.20/13 1.9} Ne3 63. Rcxc5 {-2.80/13 1.9}
Nxg4+ 64. Kh3 {-2.80/13 1.9} Rxh1+ 65. Kxg4 {-2.20/15 1.9} Rxh5 66. Rxh5
{-2.20/16 1.8} Rd8 67. Rh1 {-2.20/16 1.8} Rd2 68. Rh2 {-2.20/17 1.8} Rxh2
69. Bxh2 {-2.20/19 1.9} Ne7 70. a3 {-2.20/22 1.7} Kf7 71. Kh3
{-2.20/23 1.8} Nd5 72. Kg4 {-2.20/21 1.8} Ke6 73. Bg1 {-2.20/21 1.8} f5+
74. Kh3 {-2.20/22 1.8} e3 75. Kg2 {-2.20/17 1.7} f4 76. Bh2 {-2.20/18 1.7}
Ke5 77. Bg1 {-2.20/17 1.7} Ke4 78. Bf2 {-5.20/20 1.7} exf2 79. Kxf2
{-5.20/23 1.8} f3 80. Kg1 {-5.20/17 1.6} Ke3 81. Kh2 {-10.80/15 1.6} Nf4
82. a4 {-11.60/12 1.5} f2 83. Kg3 {-104856.40/12 1.6} bxa4 84. Kg4
{-11.60/10 1.7} f1=Q 85. Kf5 {-11.60/9 1.5} a3 86. Kf6 {-104856.40/9 1.5}
a2 87. Ke7 {-104856.80/12 1.5} a1=Q 88. Kd8 {-104857.00/14 1.6} Ne2 89. Kc7
{-104856.80/10 1.5} Qf5 90. Kb7 {-104857.00/14 1.5} Qaf6 91. Kc7
{-104857.20/19 1.5} Qd5 92. Kb8 {-104857.20/18 1.5} Ng3 93. Ka7
{-104857.20/18 1.5} Ne2 94. Kb8 {+0.00/200 0.7} Ng3 95. Ka7 {+0.00/200 1.1}
Ne2 96. Kb8 {+0.00/200 0.2}
{Game drawn by repetition} 1/2-1/2
[/pgn]