Skip to content

Commit 4fc7b2f

Browse files
feat: always include played continuation in staged deepening
1 parent e5167c1 commit 4fc7b2f

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

src/hooks/useAnalysisController/useEngineAnalysis.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ export const useEngineAnalysis = (
209209
)
210210
const maiaPolicy = currentNode.analysis.maia?.[currentMaiaModel]?.policy
211211
const maiaCandidateMoves: string[] = []
212+
const playedMove = currentNode.mainChild?.move
213+
const forcedCandidateMoves =
214+
playedMove && legalMoves.has(playedMove) ? [playedMove] : []
212215

213216
if (maiaPolicy) {
214217
let cumulative = 0
@@ -232,6 +235,7 @@ export const useEngineAnalysis = (
232235
targetDepth,
233236
{
234237
maiaCandidateMoves,
238+
forcedCandidateMoves,
235239
maiaPolicy,
236240
},
237241
)
@@ -276,5 +280,6 @@ export const useEngineAnalysis = (
276280
targetDepth,
277281
stockfishDebugRerunToken,
278282
currentNode?.analysis.maia?.[currentMaiaModel]?.policy,
283+
currentNode?.mainChild?.move,
279284
])
280285
}

src/lib/engine/stockfish.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type AnalysisRunContext = {
4848
legalMoves: string[]
4949
legalMoveCount: number
5050
maiaCandidateMoves: string[]
51+
forcedCandidateMoves: string[]
5152
maiaPolicy: Record<string, number>
5253
kSf: number
5354
targetDepth: number
@@ -186,6 +187,9 @@ class Engine {
186187
const maiaCandidateMoves = Array.from(
187188
new Set(options?.maiaCandidateMoves || []),
188189
).filter((move) => this.moves.includes(move))
190+
const forcedCandidateMoves = Array.from(
191+
new Set(options?.forcedCandidateMoves || []),
192+
).filter((move) => this.moves.includes(move))
189193
const maiaPolicy = Object.fromEntries(
190194
Object.entries(options?.maiaPolicy || {}).filter(
191195
([move, prob]) => this.moves.includes(move) && Number.isFinite(prob),
@@ -200,6 +204,7 @@ class Engine {
200204
legalMoves: [...this.moves],
201205
legalMoveCount: this.legalMoveCount,
202206
maiaCandidateMoves,
207+
forcedCandidateMoves,
203208
maiaPolicy,
204209
kSf: kSfFromOptions || 0,
205210
targetDepth,
@@ -761,10 +766,13 @@ class Engine {
761766
0,
762767
MAX_MAIA_DEEPEN_MOVES,
763768
)
769+
const targetDeepeningMoves = Array.from(
770+
new Set([...maiaTopMoves, ...runContext.forcedCandidateMoves]),
771+
)
764772
const maiaMidDepth = Math.min(MAIA_MID_DEPTH, targetDepth)
765773

766774
if (maiaMidDepth > plan.screeningDepth) {
767-
for (const move of maiaTopMoves) {
775+
for (const move of targetDeepeningMoves) {
768776
if (!this.isActiveRun(runContext.positionId)) {
769777
return
770778
}
@@ -881,7 +889,7 @@ class Engine {
881889
yield streamingEval
882890
}
883891

884-
for (const move of maiaTopMoves) {
892+
for (const move of targetDeepeningMoves) {
885893
if (!this.isActiveRun(runContext.positionId)) {
886894
return
887895
}
@@ -1665,6 +1673,7 @@ class Engine {
16651673
legalMoves: [...this.moves],
16661674
legalMoveCount: this.legalMoveCount,
16671675
maiaCandidateMoves: [],
1676+
forcedCandidateMoves: [],
16681677
maiaPolicy: {},
16691678
kSf: 0,
16701679
targetDepth: this.currentTargetDepth,

src/types/engine.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export type StockfishMoveMapStrategy =
1717
export interface StockfishStreamOptions {
1818
moveMapStrategy?: StockfishMoveMapStrategy
1919
maiaCandidateMoves?: string[]
20+
forcedCandidateMoves?: string[]
2021
maiaPolicy?: { [move: string]: number }
2122
kSf?: number
2223
}

0 commit comments

Comments
 (0)