maksimKorzh / wukongJS

JavaScript chess engine with UCI support, own GUI and public API written by Code Monkey King
58 stars 9 forks source link

Avoid time forfeit #3

Closed fsmosca closed 3 years ago

fsmosca commented 3 years ago

Revise the code, From:

if ((nodes & 2047) == 0) checkTime();

To:

if ((nodes & 2047) == 0) {
  checkTime();
  if (timing.stopped) return 0
}
fsmosca commented 3 years ago

Rating estimate

Run a 100 game match against Skiull at TC 60s+1s.

   # PLAYER        :  RATING  ERROR  POINTS  PLAYED   (%)    W    D    L  D(%)  CFS(%)
   1 Wukong 1.1    :       0     25    60.5     100  60.5   38   45   17  45.0     100
   2 Skiull 0.1    :     -75     25    39.5     100  39.5   17   45   38  45.0     ---

White advantage = 3.67 +/- 27.20
Draw rate (equal opponents) = 46.96 % +/- 5.27

Skiull 0.1 is around 1558 CCRL Blitz. This is around TC 120s+1s on my pc where Wukong 1.1 is tested at TC 60s+1s.

So Wukong is around 1558 + 75 or 1633.

There was 1 time forfeit from Wukong.

Games

wukong_v1.1-1.zip

maksimKorzh commented 3 years ago

Thanks for testing, awesome results. Well at least my assumption of "around 1600" was fair))) And thanks for hint regarding timing - what you suggest seems reasonable - I'll make it.

maksimKorzh commented 3 years ago

Just updated the source as you suggested for both negamax and quiescence. Are you sure this would resolve the issue? I think it's more like in inaccurate time allocation, isn't it?

fsmosca commented 3 years ago

The idea of

if ((nodes & 2047) == 0) {
  checkTime();
  if (timing.stopped) return 0
}

is to check the time every 2k nodes or so. Since this is a time check it is logical to check timing.stopped and if so, exit from the search immediately to comply with the move allocation time.

If timing.stopped == 1 and you continue to search, it can happen that move allocation is exceeded. If this happens on 1 or 2 moves you will not see the effect, but if this happens where the engine has low on time and have successive violation of move allocation time, it could exceed its time allocation.

To verify the change, run the old version vs the new version with this change on a fast TC. See which version would forfeit on time.

maksimKorzh commented 3 years ago

Thanks for explanations. Anyway it's already updated according to your suggestion in both negamax and quiescence.