Skip to content

Commit 32ff8f1

Browse files
domino14claude
andcommitted
fix: call SetKnownOppRack after PrepareSim to prevent clearing
PrepareSim() was clearing knownOppRack to nil, so we need to call SetKnownOppRack AFTER PrepareSim, not before. This fixes the bug where the analyzer was not actually using the known opponent rack even though it logged that it was. Verified that the PEG solver does not have this issue - it does not clear knownOppRack in its Init or Solve methods. Also cleaned up excessive debug logging. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent bf73ff0 commit 32ff8f1

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

gameanalysis/analyzer.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ func (a *Analyzer) AnalyzeSingleTurn(ctx context.Context, history *pb.GameHistor
173173
if int(phonyPlayEvent.PlayerIndex) != playerIndex {
174174
// Opponent's phony was challenged off, we know their rack
175175
knownOppRack = extractExposedTiles(prevEvent.PlayedTiles, g.Alphabet())
176+
log.Info().
177+
Str("exposedTiles", prevEvent.PlayedTiles).
178+
Msg("extracted known opponent rack from challenged phony")
176179
}
177180
}
178181
}
@@ -578,7 +581,13 @@ func (a *Analyzer) analyzeWithSim(ctx context.Context, g *game.Game, analysis *T
578581
simmer.SetThreads(a.analysisCfg.Threads)
579582
}
580583

581-
// Set known opponent rack if available
584+
// Prepare simulation
585+
err = simmer.PrepareSim(plies, plays)
586+
if err != nil {
587+
return fmt.Errorf("failed to prepare simulation: %w", err)
588+
}
589+
590+
// Set known opponent rack if available (MUST be after PrepareSim which clears it)
582591
if len(knownOppRack) > 0 {
583592
simmer.SetKnownOppRack(knownOppRack)
584593
analysis.KnownOppRack = tilemapping.MachineWord(knownOppRack).UserVisible(g.Alphabet())
@@ -587,12 +596,6 @@ func (a *Analyzer) analyzeWithSim(ctx context.Context, g *game.Game, analysis *T
587596
Msg("analyzing with known opponent rack from challenged phony")
588597
}
589598

590-
// Prepare simulation
591-
err = simmer.PrepareSim(plies, plays)
592-
if err != nil {
593-
return fmt.Errorf("failed to prepare simulation: %w", err)
594-
}
595-
596599
// Ensure the played move is simmed (avoid pruning it)
597600
simmer.AvoidPruningMoves([]*move.Move{analysis.PlayedMove})
598601

0 commit comments

Comments
 (0)