Skip to content

Commit

Permalink
use movetime for external engine
Browse files Browse the repository at this point in the history
  • Loading branch information
schlawg committed Nov 17, 2023
1 parent 4d8b704 commit 1cdbc0d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions ui/ceval/src/engines/externalEngine.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Work, ExternalEngineInfo, CevalEngine, CevalState } from '../types';
import { randomToken } from 'common/random';
import { readNdJson } from 'common/ndjson';
import throttle from 'common/throttle';

interface ExternalEngineOutput {
time: number;
Expand Down Expand Up @@ -35,10 +36,13 @@ export class ExternalEngine implements CevalEngine {
start(work: Work) {
this.stop();
this.state = CevalState.Loading;
this.process(work);
}

process = throttle(700, work => {
this.req = new AbortController();
this.analyse(work, this.req.signal);
}
});

private async analyse(work: Work, signal: AbortSignal): Promise<void> {
try {
Expand All @@ -57,15 +61,14 @@ export class ExternalEngine implements CevalEngine {
sessionId: this.sessionId,
threads: work.threads,
hash: work.hashSize || 16,
infinite: true, // TODO WTF
movetime: work.searchMs === Number.POSITIVE_INFINITY ? 24 * 3600 * 1000 : work.searchMs,
multiPv: work.multiPv,
variant: work.variant,
initialFen: work.initialFen,
moves: work.moves,
},
}),
});

await readNdJson<ExternalEngineOutput>(res, line => {
this.state = CevalState.Computing;
work.emit({
Expand Down

0 comments on commit 1cdbc0d

Please sign in to comment.