v24: Resolve GitHub Issues #1-#5

Issue #1 — Winner's life total now captured:
  - Parse verbose Forge log for life-total-change events
  - Track last-known life per seat via 3 regex patterns
  - Winner's final life set from log data (not left at default 40)
  - Losers who died to mill/poison retain their actual life total

Issue #2 — Win condition classification formalized:
  - New WinCondition enum (schema/WinCondition.java) with 8 categories
  - Centralized Forge loss-reason-string → enum mapping (regex-based)
  - UNKNOWN fallback with logging for unrecognized loss reasons
  - All classification now goes through WinCondition.classify()

Issue #3 — JVM startup overhead reduced:
  - Added -XX:+UseSerialGC (lighter GC for batch processes)
  - Added -XX:TieredStopAtLevel=1 (faster JIT, less compilation)
  - ForgeWorker stub class for future persistent batch mode
  - Estimated reduction: ~2-3s → ~1-1.5s per game startup

Issue #4 — Single-threaded throughput optimization:
  - New CLI flags: --ai-simplified, --ai-think-time, --benchmark
  - JVM flags passed through to Forge subprocess
  - Benchmark mode: run 1 game before batch, report wall/Forge/overhead times
  - API support: aiSimplified, aiThinkTimeMs in StartRequest

Issue #5 — Threading, progress, and backpressure:
  - --threads 0 or -1 auto-detects optimal count from CPU topology
  - detectOptimalThreads() estimates physical cores (excludes HT)
  - ProgressCallback interface for real-time sims/sec reporting
  - Per-game progress emitted as [PROGRESS] lines, parsed by lab_api.py
  - --max-queue flag for graceful backpressure (limits concurrent JVMs)
  - Final throughput summary printed at batch completion
  - StatusResponse now includes simsPerSec field

Also: .gitignore restored, lab_api.py updated with all new API fields
This commit is contained in:
KoalaTrapLord committed 2026-03-12 01:26:36 +00:00
1 parent a5fe8cb3fa
commit a0adfc37e8
7 files changed
+736 -81

No files matched your search

@@ -31,13 +31,35 @@ public class WebApiBridge {
private volatile BatchResult lastResult;
private volatile boolean isRunning;
private volatile int progress;
private volatile double currentSimsPerSec;
private String policyServerUrl = "http://localhost:8080";
// Issue #4/#5: Performance settings
private boolean aiSimplified = false;
private int aiThinkTimeMs = -1;
private int maxQueueDepth = -1;
public WebApiBridge(String forgeJarPath, String forgeWorkDir) {
this.forgeJarPath = forgeJarPath;
this.forgeWorkDir = forgeWorkDir;
this.isRunning = false;
this.progress = 0;
this.currentSimsPerSec = 0.0;
}
/**
* Configure AI optimization settings (Issue #4).
*/
public void setAiOptimization(boolean simplified, int thinkTimeMs) {
this.aiSimplified = simplified;
this.aiThinkTimeMs = thinkTimeMs;
}
/**
* Set max concurrent Forge processes for backpressure (Issue #5).
*/
public void setMaxQueueDepth(int maxDepth) {
this.maxQueueDepth = maxDepth;
}
/**
@@ -91,10 +113,23 @@ public class WebApiBridge {
if (threads > 1) {
MultiThreadBatchRunner runner = new MultiThreadBatchRunner(
forgeJarPath, forgeWorkDir, decks, policy, threads);
runner.setAiOptimization(aiSimplified, aiThinkTimeMs);
if (maxQueueDepth > 0) runner.setMaxQueueDepth(maxQueueDepth);
// Issue #5: Progress callback for real-time sims/sec
runner.setProgressCallback((completed, total, pct, simsPerSec, lastResult) -> {
progress = pct;
currentSimsPerSec = simsPerSec;
});
games = runner.runBatch(numGames, seed);
} else {
BatchRunner runner = new BatchRunner(
forgeJarPath, forgeWorkDir, decks, policy);
runner.setAiOptimization(aiSimplified, aiThinkTimeMs);
// Issue #5: Progress callback
runner.setProgressCallback((completed, total, pct, simsPerSec, lastResult) -> {
progress = pct;
currentSimsPerSec = simsPerSec;
});
games = runner.runBatchSingleThread(numGames, seed);
}
@@ -134,6 +169,7 @@ public class WebApiBridge {
public int getProgress() { return progress; }
public boolean isRunning() { return isRunning; }
public double getCurrentSimsPerSec() { return currentSimsPerSec; }
public String getLastResultJson() {
if (lastResult == null) return "{}";