Question about Time Management

Programming Topics (Computer Chess) and technical aspects as test techniques, book building, program tuning etc

Moderator: Andres Valverde

Question about Time Management

Postby ambrooks1 » 06 Feb 2014, 00:30

I have been lurking for quite some time and just registered. ( My first post.)

Anyhow, I just put my java chess project online, but realized that
there must be problems with my time management. I notice that the opponent engines
are always taking more time to search a move than my engine, so I want my engine to take more
time - but I can't think of an intelligent way to do this.

At the start of the routine to calculate the next move I am doing :

timeForThisMove = TimeControl.getTimeForThisMove(timeLeft, movesPerSession- ( movesMade % movesPerSession ), increment);

where we are just basically dividing timeLeft by the secondParameter. Of course, I don't want to blindly add a constant value
to the timeForThisMove.

Any ideas are appreciated.
Posts: 16
Joined: 05 Feb 2014, 18:02

Re: Question about Time Management

Postby H.G.Muller » 06 Feb 2014, 10:18

Note your expression for moves-left would become invalid when you are more than a full session ahead of schedule. E.g. when the TC had 20 moves per session, but the first 25 moves were book moves, you would estimate to have 15 moves left, while in fact the remaining time was for 35 moves.

Otherwise dividing the two to get a 'target time' for a move (possibly adding the incrrement afterwards) seems a reasonable thing to do. In general it is true, however, that early moves are more important than later moves. Once you are lost, no amount of long thinking will be able to cure that situation. So there always is the trade-off between thinking longer now, in the hope to get a decisive advantage or avoid a decisive disadvantage, for the price of playing later moves more quickly. This is why human GMs get into time trouble so often. So you could allocate systematically more time than the equal share.

OTOH it is also important how flexible you implemented limiting of the search time to the target time. Just instantly aborting the search when the target time expires is very wasteful; allowing a little overrun to finish an iteration, is usually a good deal. (But of course this has to be payed for, e.g. by not starting iterations that you almost certainly would not be able to finish, even if your target time wasn't all used up yet.) Allowing extra time when you are facing a disastrous fail low, to see how much you can salvage, is a very good investment of time, much better than distributing that time over all subsequent moves in a badly lost position (which typically doesnt do any good at all!). To allow you to do that on the last move in the session would require you to keep some spare time. E.g. if I want to allow a factor 3 overrun of the target time in case of a fail low, I could take

targetTime = timeLeft/(movesLeft+2);

Then even 3*targetTime would never be more than timeLeft. It would give early moves even less than their fair share, however. Say you want to bias time usage towards the beginning by allowing moves 20% more than their fair share, you could use

targetTime = 1.3*timeLeft/(movesLeft+2.9);

Then at the start of a session, with (say) 40 moves left, you would assign 1/33 of the time to the move rather than 1/40. While with 1 move left the target time would be 1/3 of the time left, so you could afford a factor 3 overrun.
User avatar
Posts: 3119
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: Question about Time Management

Postby ambrooks1 » 06 Feb 2014, 13:53

Hello H.G,

I am honored to get a reply from you, whom I respect as one of the
top experts in computer chess. ( I consider Micro-Max as the quintessential tour de force
of computer programming.)

BTW, I used your Fairy Max tutorial as the basis for my engine, and also use Fairy Max
as my engine's main sparring partner, and have a huge collection of fascinating games
between the two.

Your comments on time management appear to be more useful than I had even hoped, and I will try out your
ideas today.
Posts: 16
Joined: 05 Feb 2014, 18:02

Re: Question about Time Management

Postby ambrooks1 » 06 Feb 2014, 14:57

I tried your example :

public static void main ( String[]args) {

long timeLeft = 900000; //milisecs
long movesLeft=40;

for (int i=0; i < 40; i ++) {

long targetTime = (long) (1.3*timeLeft/(movesLeft+2.9));
System.out.println("target Time " + targetTime + " timeLeft " + timeLeft + " movesLeft " + movesLeft);
timeLeft= timeLeft - targetTime;


target Time 27272 timeLeft 900000 movesLeft 40
target Time 27077 timeLeft 872728 movesLeft 39
target Time 26878 timeLeft 845651 movesLeft 38
target Time 26676 timeLeft 818773 movesLeft 37
target Time 26471 timeLeft 792097 movesLeft 36
target Time 26261 timeLeft 765626 movesLeft 35
target Time 26048 timeLeft 739365 movesLeft 34
target Time 25830 timeLeft 713317 movesLeft 33
target Time 25608 timeLeft 687487 movesLeft 32
target Time 25381 timeLeft 661879 movesLeft 31
target Time 25150 timeLeft 636498 movesLeft 30
target Time 24913 timeLeft 611348 movesLeft 29
target Time 24672 timeLeft 586435 movesLeft 28
target Time 24424 timeLeft 561763 movesLeft 27
target Time 24170 timeLeft 537339 movesLeft 26
target Time 23911 timeLeft 513169 movesLeft 25
target Time 23644 timeLeft 489258 movesLeft 24
target Time 23370 timeLeft 465614 movesLeft 23
target Time 23089 timeLeft 442244 movesLeft 22
target Time 22799 timeLeft 419155 movesLeft 21
target Time 22500 timeLeft 396356 movesLeft 20
target Time 22192 timeLeft 373856 movesLeft 19
target Time 21873 timeLeft 351664 movesLeft 18
target Time 21544 timeLeft 329791 movesLeft 17
target Time 21202 timeLeft 308247 movesLeft 16
target Time 20846 timeLeft 287045 movesLeft 15
target Time 20476 timeLeft 266199 movesLeft 14
target Time 20090 timeLeft 245723 movesLeft 13
target Time 19686 timeLeft 225633 movesLeft 12
target Time 19261 timeLeft 205947 movesLeft 11
target Time 18813 timeLeft 186686 movesLeft 10
target Time 18339 timeLeft 167873 movesLeft 9
target Time 17834 timeLeft 149534 movesLeft 8
target Time 17293 timeLeft 131700 movesLeft 7
target Time 16711 timeLeft 114407 movesLeft 6
target Time 16076 timeLeft 97696 movesLeft 5
target Time 15377 timeLeft 81620 movesLeft 4
target Time 14595 timeLeft 66243 movesLeft 3
target Time 13702 timeLeft 51648 movesLeft 2
target Time 12648 timeLeft 37946 movesLeft 1

So the idea looks pretty good. Maybe some adjustment for less bias?
Posts: 16
Joined: 05 Feb 2014, 18:02

Re: Question about Time Management

Postby H.G.Muller » 07 Feb 2014, 08:53

You can lower the bias factor B from 1.3 to 1.2. In general, when you want to allow a factor F overrun in the last move, to solve a possible fail low, the term you have to add to movesLeft in the denominator will be (B*F-1). (So in my example it was 1.3*3 - 1 = 2.9.) What value of B works best can only be determined by testing.
User avatar
Posts: 3119
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: Question about Time Management

Postby ambrooks1 » 07 Feb 2014, 18:21

Thanks so much HG.
Posts: 16
Joined: 05 Feb 2014, 18:02

Return to Programming and Technical Discussions

Who is online

Users browsing this forum: No registered users and 3 guests