Skip to content

Commit a8b2346

Browse files
committed
Fix wrong time control scheme for 0 increments
Fixes #7
1 parent d409f58 commit a8b2346

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

uci/timemanager.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ type UciTimingInfo struct {
2727
func NewTimingInfo(messageParts []string) (timingInfo *UciTimingInfo) {
2828
timingInfo = &UciTimingInfo{
2929
StartTimestamp: time.Now(),
30+
TimeWhite: -1,
31+
TimeBlack: -1,
32+
IncrementWhite: -1,
33+
IncrementBlack: -1,
34+
MovesToGo: -1,
35+
MoveTime: -1,
3036
}
3137
for i, token := range messageParts {
3238
switch token {
@@ -48,7 +54,7 @@ func NewTimingInfo(messageParts []string) (timingInfo *UciTimingInfo) {
4854
}
4955

5056
func (timingInfo *UciTimingInfo) calculateTimeoutContext(ctx context.Context, g *game.Game, options []UciOption) (context.Context, func()) {
51-
if timingInfo.MoveTime > 0 {
57+
if timingInfo.MoveTime >= 0 {
5258
return context.WithDeadline(ctx, timingInfo.StartTimestamp.Add(time.Duration(timingInfo.MoveTime*int(time.Millisecond))))
5359
}
5460

@@ -62,11 +68,11 @@ func (timingInfo *UciTimingInfo) calculateTimeoutContext(ctx context.Context, g
6268
}
6369
}
6470

65-
if timingInfo.MovesToGo > 0 && timingInfo.IncrementWhite <= 0 && timingInfo.IncrementBlack <= 0 && timingInfo.TimeWhite > 0 && timingInfo.TimeBlack > 0 {
71+
if timingInfo.MovesToGo >= 0 && timingInfo.IncrementWhite < 0 && timingInfo.IncrementBlack < 0 && timingInfo.TimeWhite >= 0 && timingInfo.TimeBlack >= 0 {
6672
return timingInfo.calculateTimeoutContextMPSTC(ctx, g, options)
6773
}
6874

69-
if timingInfo.MovesToGo <= 0 && timingInfo.IncrementWhite > 0 && timingInfo.IncrementBlack > 0 && timingInfo.TimeWhite > 0 && timingInfo.TimeBlack > 0 {
75+
if timingInfo.MovesToGo < 0 && timingInfo.IncrementWhite >= 0 && timingInfo.IncrementBlack >= 0 && timingInfo.TimeWhite >= 0 && timingInfo.TimeBlack >= 0 {
7076
return timingInfo.calculateTimeoutContextFisherTC(ctx, g, options)
7177
}
7278

0 commit comments

Comments
 (0)