r/ComputerChess • • Feb 16 '21

Open Source Chess Engine in Go

http://weaselchess.club
13 Upvotes

24 comments sorted by

View all comments

Show parent comments

1

u/TreyM2k Feb 16 '21

Hey, time control is something I am still working on, the current solution is a bit jank just divide time remaining by moves to go. Default moves to go is set to 30. During testing so for we have always been giving it a 1 sec inc, but better time control is one of the things next on the list for sure.

1

u/lithander Feb 16 '21 edited Feb 16 '21

I basically do the same thing and it works fine for me.

If your engine loses on time it always does so in move 40. When moves to go is only 1. To prevent that I subtract a 10ms safety-margin from the budget I compute to be safe. (And of course I abort searches as soon as they go on beyond the time budget!)

Here's a PGN where Weasle still spends 1s (at 0.5s increment) per turn even though both engines agree that there's a mate coming.

[Event "Weasle vs MC"]
[Site "?"]
[Date "2021.02.16"]
[Round "5"]
[White "MinimalChess 0.2"]
[Black "Weasel"]
[Result "1-0"]
[ECO "A00"]
[GameDuration "00:00:44"]
[GameEndTime "2021-02-16T19:35:41.251 Mitteleuropäische Zeit"]
[GameStartTime "2021-02-16T19:34:56.720 Mitteleuropäische Zeit"]
[Opening "Benko's Opening"]
[PlyCount "79"]
[Termination "time forfeit"]
[TimeControl "40/5+0.5"]

1. g3 {+1.00/7 0.25s} e5 {+0.32/7 0.49s} 2. Bh3 {+1.00/7 0.41s}
d5 {+0.55/7 0.49s} 3. Bxc8 {0.00/6 0.41s} Qxc8 {+0.45/8 0.50s}
4. Nc3 {-1.00/6 0.22s} d4 {+0.75/7 0.50s} 5. Nb1 {-1.00/6 0.13s}
Nf6 {+0.80/7 0.50s} 6. Nf3 {-1.00/6 0.21s} Bd6 {+0.70/7 0.51s}
7. c4 {-1.00/6 0.35s} O-O {+0.65/7 0.51s} 8. c5 {-1.00/6 0.40s}
Bxc5 {+0.90/8 0.52s} 9. Nxe5 {-2.00/6 0.25s} Qh3 {+0.95/7 0.52s}
10. Qb3 {-1.00/6 0.46s} Qg2 {+0.95/7 0.53s} 11. Qf3 {-1.00/6 0.32s}
Qxf3 {+0.95/9 0.53s} 12. Nxf3 {+1.00/7 0.29s} Nc6 {+0.95/7 0.54s}
13. b3 {-1.00/6 0.15s} Nb4 {+1.45/9 0.54s} 14. Na3 {0.00/7 0.35s}
d3 {+1.45/7 0.55s} 15. e3 {+1.00/7 0.54s} Nfd5 {+1.10/7 0.55s}
16. e4 {-1.00/6 0.81s} Rae8 {+2.15/8 0.56s} 17. h4 {-2.00/6 0.22s}
Rxe4+ {+3.05/7 0.57s} 18. Kf1 {-1.00/7 0.57s} Re2 {+2.75/7 0.57s}
19. Rh2 {-1.00/7 0.58s} Nf6 {+2.90/7 0.58s} 20. Nb5 {-2.00/6 0.25s}
Ng4 {+3.00/7 0.58s} 21. Rg2 {-1.00/7 0.66s} Nc2 {+2.90/7 0.59s}
22. Rb1 {-1.00/7 0.60s} Ne5 {+4.15/7 0.60s} 23. Nc3 {-4.00/6 0.37s}
Nxf3 {+10.25/8 0.61s} 24. Bb2 {-7.00/7 0.70s} Nxd2+ {+12.15/7 0.62s}
25. Kg1 {-9.00/7 0.31s} Nxb1 {+13.40/9 0.63s} 26. Nxb1 {-9.00/7 0.37s}
Ne1 {+13.60/9 0.64s} 27. Bc3 {-10.00/7 0.43s} Nxg2 {+13.85/8 0.65s}
28. Kxg2 {-10.00/7 0.34s} Rxf2+ {+13.95/8 0.66s} 29. Kh3 {-10.00/7 0.22s}
Rc2 {+14.20/9 0.67s} 30. b4 {-10.00/7 0.58s} Bd6 {+14.60/9 0.69s}
31. b5 {-10.00/7 0.69s} Rc1 {+16.10/10 0.70s} 32. Nd2 {-12.00/7 0.52s}
Rxc3 {+17.40/11 0.72s} 33. a4 {-15.00/8 1.1s} Rc2 {+18.75/11 0.74s}
34. Nf1 {-14.00/7 0.39s} Re8 {+20.25/11 0.76s} 35. b6 {-15.00/7 0.45s}
cxb6 {+21.60/10 0.78s} 36. h5 {-17.00/7 0.78s} Re1 {+22.85/11 0.81s}
37. Nd2 {-18.00/7 0.52s} Rxd2 {+M25/10 0.85s} 38. Kg4 {-25.00/8 2.8s}
Rf2 {+M13/9 0.90s} 39. h6 {-99.99/7 0.16s} f5+ {+M9/9 0.97s}
40. Kg5 {-99.99/5 0.004s, Black loses on time} 1-0

1

u/TreyM2k Feb 16 '21

That is a good suggestion thank you, safety margin would defiantly help. And I check every 2048 nodes if the search is stopped, I figured that was sufficient. How often do you check if the search is stopped? Also I add 1 7th of the inc, here is how I currently do it

info.TimeSet = true
timeV /= movesToGo
// Dont use our entire increment  
inc = int(math.Floor(float64(inc) * 0.7))
 info.StopTime = info.StartTime + int64(timeV+inc)

1

u/TreyM2k Feb 16 '21

I just reviewed that game, Weasel was doing so well, thats unfortunate. I need to get that fixed

1

u/lithander Feb 16 '21

I guess if you fix it you get a 100% winrate against my engine.

Btw here's the stuff you're interested in:

https://github.com/lithander/MinimalChessEngine/blob/master/MinimalChessEngine/Engine.cs

The time budget calculation is in lines 90-130 and in line 142 you can see how I pass a little lambda function to the SearchDeeper() method. It's called everytime before I generate the legal moves of a node to search deeper. If it's false I just don't generate any more child-nodes and the search quickly unwinds.

→ More replies (0)