Add game-simulation package with multi-run balance testing, fix stalled-pipeline trap
Adds a full simulation harness (game-simulation package) with greedy/random strategies, 36-metric diagnostics, multi-run orchestration via child processes, and a statistical interpreter. Includes 2.3x engine performance optimizations (research bonus caching, per-DC dirty tracking, reduced allocations in tick pipeline, single-pass loops). Fixes a critical balance bug where training pipelines stalled on insufficient VRAM would permanently block training slots — the engine never re-checked stalled pipelines, and the greedy strategy didn't pre-check VRAM requirements. This caused 20-25% of seeds to get stuck in Scale-up era. All three fixes (engine un-stalling, strategy VRAM pre-check, stalled pipeline cancellation) bring pass rate from 75% to 100% across 20 random seeds. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -92,13 +92,6 @@ function computeAttractiveness(
|
||||
return Math.max(0.01, score);
|
||||
}
|
||||
|
||||
function softmaxShares(scores: number[]): number[] {
|
||||
const maxScore = Math.max(...scores);
|
||||
const exps = scores.map(s => Math.exp((s - maxScore) * SHARE_TEMPERATURE));
|
||||
const sumExp = exps.reduce((a, b) => a + b, 0);
|
||||
return exps.map(e => e / sumExp);
|
||||
}
|
||||
|
||||
export function computeMarketShares(
|
||||
tam: TotalAddressableMarket,
|
||||
participants: ParticipantProfile[],
|
||||
@@ -106,30 +99,48 @@ export function computeMarketShares(
|
||||
): TotalAddressableMarket {
|
||||
const segments = { ...tam.segments };
|
||||
const segmentIds: TAMSegmentId[] = ['consumer', 'developer', 'enterprise', 'government'];
|
||||
const n = participants.length;
|
||||
const scores = new Array<number>(n);
|
||||
const targetShares = new Array<number>(n);
|
||||
|
||||
for (const segId of segmentIds) {
|
||||
const seg = segments[segId];
|
||||
const scores = participants.map(p => computeAttractiveness(p, segId, qualityBaseline));
|
||||
const targetShares = softmaxShares(scores);
|
||||
|
||||
for (let i = 0; i < n; i++) {
|
||||
scores[i] = computeAttractiveness(participants[i], segId, qualityBaseline);
|
||||
}
|
||||
|
||||
// Inline softmax
|
||||
let maxScore = scores[0];
|
||||
for (let i = 1; i < n; i++) { if (scores[i] > maxScore) maxScore = scores[i]; }
|
||||
let sumExp = 0;
|
||||
for (let i = 0; i < n; i++) {
|
||||
targetShares[i] = Math.exp((scores[i] - maxScore) * SHARE_TEMPERATURE);
|
||||
sumExp += targetShares[i];
|
||||
}
|
||||
for (let i = 0; i < n; i++) { targetShares[i] /= sumExp; }
|
||||
|
||||
const oldShareMap = new Map<string, MarketShareEntry>();
|
||||
for (const entry of seg.shares) {
|
||||
oldShareMap.set(entry.playerId, entry);
|
||||
}
|
||||
|
||||
const newShares: MarketShareEntry[] = participants.map((p, i) => {
|
||||
const newShares: MarketShareEntry[] = new Array(n);
|
||||
let totalShare = 0;
|
||||
for (let i = 0; i < n; i++) {
|
||||
const p = participants[i];
|
||||
const old = oldShareMap.get(p.id);
|
||||
const oldShare = old?.sharePercent ?? 0;
|
||||
const migratedShare = oldShare + (targetShares[i] - oldShare) * SHARE_MIGRATION_SPEED;
|
||||
return {
|
||||
totalShare += migratedShare;
|
||||
newShares[i] = {
|
||||
playerId: p.id,
|
||||
sharePercent: migratedShare,
|
||||
customers: Math.floor(migratedShare * seg.totalSize),
|
||||
customers: 0,
|
||||
attractivenessScore: scores[i],
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
const totalShare = newShares.reduce((s, e) => s + e.sharePercent, 0);
|
||||
if (totalShare > 0) {
|
||||
for (const entry of newShares) {
|
||||
entry.sharePercent /= totalShare;
|
||||
@@ -152,10 +163,7 @@ export function updateTAMGrowth(tam: TotalAddressableMarket, era: Era): TotalAdd
|
||||
const seg = segments[segId];
|
||||
const base = baseSizes[segId];
|
||||
const grown = seg.totalSize + seg.totalSize * TAM_GROWTH_PER_TICK;
|
||||
segments[segId] = {
|
||||
...seg,
|
||||
totalSize: Math.max(base, grown),
|
||||
};
|
||||
segments[segId] = { ...seg, totalSize: Math.max(base, grown) };
|
||||
}
|
||||
|
||||
return { segments };
|
||||
|
||||
Reference in New Issue
Block a user