Adam-Kulju / Patricia

Super aggressive chess engine
MIT License
74 stars 9 forks source link

time function #90

Open caissist opened 1 month ago

caissist commented 1 month ago

Hello Adam, thank you for such an original engine - I love this idea! Patricia was running on a chess server for me and I noticed a time management issue?! A basic idea is: do not start a new iteration without first checking whether there is still enough time available to complete the new iteration. And from my observation, Patricia doesn't do that?! Example game:

[Event "Engine matches"] [Site "?"] [Date "2024.9.13"] [Time "16:21:20"] [White "?"] [Black "Patricia 3.1"] [Result "0-1"] [WhiteElo "2213"] [BlackElo "2214"] [Opening "A09 Reti Opening: Advance Variation, 3.g3"]

{Time control = 5 1 Book(s): Cerebellum 3Merge 2020-09-16.bk ICCF GM 2500+ 2019+_20240909.bk playchess + infinitechess games 2500+_2020+.bk}

  1. Nf3 d5 {0,00/0 0.0 } 2. c4 d4 {0,00/0 0.5 } 3. g3 Nf6 {0,00/0 0.0 } 4. d3 c5 {0,00/0 0.5 } 5. Bf4 Nc6 {-0,45/17 8.4 } 6. Nbd2 Nh5 {-0,82/16 7.3 } 7. Bg2 g6 {-0,92/15 7.6 } 8. Bg5 h6 {-1,21/15 6.8 } 9. Bf4 Bg7 {-1,37/15 7.2 } 10. Nb3 Nxf4 {-1,42/15 8.7 } 11. gxf4 O-O {0,00/1 8.2 } 12. Nfd2 e5 {-1,87/14 8.8 } 13. fxe5 Nxe5 {-1,63/14 6.0 } 14. Nxc5 Re8 {-1,77/13 7.6 } 15. Ndb3 Qh4 {-2,45/13 5.7 } 16. O-O Ng4 {-3,06/13 5.5 } 17. h3 Nf6 {-3,23/14 5.7 } 18. Kh2 Bxh3 {-7,86/14 6.2 } 19. Bxh3 Re3 {-7,44/13 5.0 } 20. f3 Rae8 {-7,89/13 5.0 } 21. Rg1 Nh5 {-9,04/14 5.8 } 22. Qf1 Rxe2+ {-10,03/14 5.5 } 23. Rg2 Nf4 {-10,86/14 4.8 } 24. Rxe2 Rxe2+ {-11,49/14 4.5 } 25. Kh1 Qg3 {-M 07/14 5.5 } 26. Qxe2 Nxe2 {opponent resigns} 0-1

for move 11:

move statistics in game notation: 0,00/1 8.2 (PV is missing because of unfinished iteration)

Thank you!

Adam-Kulju commented 1 month ago

Hi, thank you for the feedback!

Patricia's time management works as such: if she completes an iteration and time is above some number A, she stops searching. If she hasn't completed an iteration, and time gets above A, she keeps searching to try and finish the iteration, but if it reaches some number B, she immediately stops searching so as to not run out of time.

This is a standard time management method that many engines use, and it gains a lot of Elo.

Here it seems that she searched for a little bit less than A time, then the next iteration took a very long time and it reached B time before it completed. This does happen occasionally, but there's no good way to predict if it is likely to happen, and it doesn't happen often enough to offset the benefits of the time management scheme.

If she doesn't print out the iteration while other engines do, it's because other engines print when they hit B, while Patricia only prints the best move and returns.

caissist commented 1 month ago

Hi, thank you for feedback!

and it doesn't happen often enough to offset the benefits of the time management scheme.

Well, it happens in almost all games, and also several times in same game. Here another examples, please note my annotations:

[Event "Engine matches"] [Site "?"] [Date "2024.9.18"] [Round "?"] [White "Patricia 3.1 ver Aug 7, 2024"] [Black "?"] [Result "1-0"] [BlackElo "2197"] [Opening "C65 Spanish: Berlin, Beverwijk Variation"] [Time "18:48:36"] [WhiteElo "2214"]

{Time control = 5 0 Book(s): Cerebellum 3Merge 2020-09-16.bk ICCF GM 2500+ 2019+_20240909.bk playchess + infinitechess games 2500+_2020+.bk} 1. e4 {0,00/0 0.0 } 1... e5 2. Nf3 {0,00/0 0.0 } 2... Nc6 3. Bb5 {0,00/0 0.0 } 3... Nf6 4. O-O {0,00/0 0.0 } 4... Bc5 5. Bxc6 {0,00/0 0.6 } 5... dxc6 6. d3 {0,00/0 0.0 } 6... Qe7 7. Nbd2 {0,00/0 0.0 } 7... Ng4 8. h3 {0,00/0 0.0 } 8... h5 9. Nb3 {0,00/0 0.0 } 9... Bb6 10. d4 {0,31/14 7.8 } 10... Be6 11. a4 {0,21/16 6.9 } 11... O-O-O 12. a5 {0,38/15 6.0 } 12... Bxd4 13. Nbxd4 {0,38/16 7.2 } 13... exd4 14. Re1 {0,32/16 6.0 } 14... Nf6 15. Bg5 {1,48/15 6.0 } 15... Qc5 16. e5 {2,03/14 5.2 } 16... Nh7 17. Bxd8 {2,03/15 6.5 } 17... Rxd8 18. a6 {1,90/15 6.7 } 18... b5 19. Qd2 {2,10/15 5.5 } 19... g6

  1. Rad1 {2,50/15 5.1 } 20... Qb6 21. Qf4 {0,00/1 5.0 -- unfinished iteration} 21... c5 22. b4 {2,52/15 5.3 } 22... cxb4 23. Nxd4 {2,90/16 5.3 } 23... Nf8 24. Nxe6 {3,16/16 5.4 } 24... Qxe6 25. Qxb4 {6,04/19 5.8 } 25... c6 26. Rxd8+ {11,55/18 5.1 } 26... Kxd8 27. Qxf8+ {opponent resigns} 1-0

[Event "Engine matches"] [Site "?"] [Date "2024.9.18"] [Round "?"] [White "?"] [Black "Patricia 3.1 ver Aug 7, 2024"] [Result "0-1"] [BlackElo "2222"] [Opening "C50 Giuoco Pianissimo: Italian Four Knights"] [Time "19:03:32"] [WhiteElo "2181"]

{Time control = 5 0 Book(s): Cerebellum 3Merge 2020-09-16.bk ICCF GM 2500+ 2019+_20240909.bk playchess + infinitechess games 2500+_2020+.bk} 1. e4 e5 {0,00/0 0.0 } 2. Nf3 Nc6 {0,00/0 0.6 } 3. Bc4 Bc5 {0,00/0 0.0 } 4. d3 Nf6 {0,00/0 0.6 } 5. Nc3 O-O {0,00/0 0.0 } 6. Ng5 d6 {0,00/0 0.0 } 7. a3 Bg4 {0,00/0 0.0 } 8. f3 Bc8 {0,00/0 0.0 } 9. h4 a5 {0,00/0 0.0 } 10. g4 Nd4 {0,00/0 0.6 } 11. Kf1 h6 {0,00/0 0.5 } 12. Kg2 c6 {0,00/0 0.0 } 13. Ba2 d5 {0,00/0 0.5 } 14. Rh2 b5 {-2,21/13 6.4 } 15. Bd2 Qd6 {0,00/0 0.6 } 16. Rc1 Rb8 {0,00/1 7.1 -- unfinished iteration} 17. Nh3 b4 {-3,91/14 6.7 } 18. Na4 dxe4 {-3,83/15 9.4 } 19. Nxc5 exf3+ {-4,44/16 6.8 } 20. Kh1 Qxc5 {-4,35/16 6.5 } 21. c3 bxc3 {-5,13/15 5.4 } 22. bxc3 Ne2 {-6,13/15 5.9 } 23. g5 Ng3# {opponent checkmated} 0-1

Maybe another look on your boundaries "A" and "B"?

Thank you.

caissist commented 1 month ago

I've watched quite a few games now, and I now know that iterations are aborted in almost every game, and several times in a single game. So these are not occasional situations! You surely know “HGM” Harm-Geert Muller, a pope in computer chess? I quote: " H.G. Muller (NOV 21, 2008 on talkchess.com): In uMax, where the search time is extremely variable, because it always finishes an iteration, once its starts it, the target time (after which I do not start a new iteration) must be at most 10% of the remaining time on the clock, or there is a significant probability that it will forfeit on time with the current move. On average it uses about 1.5 times as much time as this target time, but the distribution has a very long tail towards long thinking times. For the long-run target, you can assume that the game will last 40 more moves, so that you have timeLeft + 40 timeInc, and that you want on the average to spend 4% of that remaining time on the next move. So you get targetTime = 0.04 (timeLeft + 40 * timeInc) / 1.5. This works for any incremental time control, whether the increment is zero (sudden death), or most of the time must come from the increment."

Just another suggestion...

caissist commented 1 month ago

Adam, a new run - I did some statistics...

This does happen occasionally, but there's no good way to predict if it is likely to happen, and it doesn't happen often enough to offset the benefits of the time management scheme.

Patricia has played so far: 213 games Fischer clocks 5 1 total number of unfinished iterations: 380 rate of unfinished iterations: 1.784 per game

To me this is not "occasionally". It means in every game almost 2 unfinished iterations, which means

See HGM's statement above based on a very large knowledge and experience...

caissist commented 1 month ago

This is a standard time management method that many engines use

Are you sure? I watched many debates regarding time function on talkchess.com over the last about 15 years and I learnt: no, there is no standard. Rather, there are many different solutions, and people only agree on very basic things, such as: do not start a new iteration x+1 if it is unlikely that it can be completed regularly. Here is another example of a final move, without finishing the iteration: The move 28...Ra2 was finally played - out of the blue - based on an incomplete iteration, and it wasn't even examined in the last 5 search depths?! Would you trust a move like that? Attached is the game and Patricia's iterations on this move alone.

Patricia games - unfinished iterations #02 - 28...Ra2.txt Patricia games - unfinished iterations #02 - 28...Ra2 - engine statistics.txt