Skip to content

Commit 0e7f17b

Browse files
committed
Reintroduce walking radius slider
1 parent c41c005 commit 0e7f17b

3 files changed

Lines changed: 47 additions & 12 deletions

File tree

index.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ <h2>OPTIMIZATION PARAMS</h2>
9797
</div>
9898
</div>
9999

100+
<div class="control-row">
101+
<div class="control-item">
102+
<label for="param-sigma">Walking Radius: <span id="param-sigma-value">200m</span></label>
103+
<input id="param-sigma" type="range" min="50" max="1000" step="50" value="200" />
104+
</div>
105+
</div>
106+
100107
<div class="control-row">
101108
<div class="control-item">
102109
<label

src/app.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ let PRESETS = {};
1010
let PRESETS_RAW = [];
1111
let buildableLandPolygon = [];
1212

13+
const PRESET_SIGMAS = {
14+
phase1: 200,
15+
phase2: 300,
16+
phase3: 400,
17+
phase4: 600,
18+
phase5: 800,
19+
collectibles: 1000,
20+
};
21+
1322
// Resource Registry and Stylings
1423
const RESOURCES = [
1524
// Core Resources
@@ -49,7 +58,7 @@ const RESOURCES = [
4958
const state = {
5059
rawNodes: [],
5160
config: {
52-
sigma: 700,
61+
sigma: 200,
5362
utilityFunc: "cobb_douglas",
5463
decayFunc: "gaussian",
5564
purityOverride: "default",
@@ -81,6 +90,8 @@ const els = {
8190
paramDecay: document.getElementById("param-decay"),
8291
paramPurity: document.getElementById("param-purity"),
8392
paramStrategy: document.getElementById("param-strategy"),
93+
paramSigma: document.getElementById("param-sigma"),
94+
paramSigmaValue: document.getElementById("param-sigma-value"),
8495
paramIgnoreSpawns: document.getElementById("param-ignore-spawns"),
8596
btnCompute: document.getElementById("btn-compute"),
8697
};
@@ -322,6 +333,7 @@ async function runGlobalOptimization() {
322333
purity_override: config.purityOverride,
323334
strategy: config.strategy,
324335
game_phase: config.gamePhase,
336+
sigma: config.sigma,
325337
ignore_spawns: config.ignoreSpawns,
326338
weights: Object.fromEntries(Object.entries(config.weights).filter(([_, v]) => v !== 0)),
327339
};
@@ -770,6 +782,13 @@ function clearComputation() {
770782
renderResultsPanel();
771783
}
772784

785+
function setWalkingRadius(value) {
786+
const sigma = Math.max(50, Math.min(1000, Math.round(Number(value) / 50) * 50));
787+
state.config.sigma = sigma;
788+
els.paramSigma.value = String(sigma);
789+
els.paramSigmaValue.textContent = `${sigma}m`;
790+
}
791+
773792
// Preset loader for Game Phase
774793
function applyPhasePreset(phaseId) {
775794
state.config.gamePhase = phaseId;
@@ -787,7 +806,7 @@ function applyPhasePreset(phaseId) {
787806
}
788807
}
789808

790-
// Apply preset spawn behavior dynamically; walking radius stays fixed at 700m.
809+
// Apply preset spawn behavior and walking radius dynamically.
791810
const rawPreset = PRESETS_RAW.find((p) => p.id === phaseId);
792811
if (rawPreset) {
793812
state.config.ignoreSpawns = rawPreset.ignore_spawns;
@@ -797,7 +816,7 @@ function applyPhasePreset(phaseId) {
797816
state.config.ignoreSpawns = false;
798817
els.paramIgnoreSpawns.value = "false";
799818
}
800-
state.config.sigma = 700;
819+
setWalkingRadius(PRESET_SIGMAS[phaseId] ?? rawPreset?.sigma ?? 200);
801820

802821
// Redraw weight sliders UI
803822
renderWeightSliders();
@@ -854,6 +873,13 @@ function setupEvents() {
854873
clearComputation();
855874
});
856875

876+
const onSigmaInput = (e) => {
877+
setWalkingRadius(e.target.value);
878+
clearComputation();
879+
};
880+
els.paramSigma.addEventListener("input", onSigmaInput);
881+
els.paramSigma.addEventListener("change", onSigmaInput);
882+
857883
els.paramIgnoreSpawns.addEventListener("change", (e) => {
858884
state.config.ignoreSpawns = e.target.value === "true";
859885
clearComputation();

src/server.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub struct OptimizeRequest {
2929
pub purity_override: String,
3030
pub strategy: String,
3131
pub game_phase: String,
32+
pub sigma: f64,
3233
pub ignore_spawns: bool,
3334
/// Resource weights as a map of resource_id → weight.
3435
/// Values of 0.0 are ignored in the calculation.
@@ -118,22 +119,23 @@ fn apply_collectibles_weights(weights: &mut HashMap<String, f64>) {
118119
// ---------------------------------------------------------------------------
119120

120121
fn build_presets() -> Vec<PresetResponse> {
121-
let phases: &[(&str, &str, bool)] = &[
122-
("phase1", "Phase 1 — Early Game (Tiers 1-2)", false),
123-
("phase2", "Phase 2 — Steel & Coal (Tiers 3-4)", false),
124-
("phase3", "Phase 3 — Oil & Quartz (Tiers 5-6)", false),
125-
("phase4", "Phase 4 — Aluminum & Nuclear (Tiers 7-8)", true),
126-
("phase5", "Phase 5 — Quantum (Tier 9)", true),
122+
let phases: &[(&str, &str, bool, f64)] = &[
123+
("phase1", "Phase 1 — Early Game (Tiers 1-2)", false, 200.0),
124+
("phase2", "Phase 2 — Steel & Coal (Tiers 3-4)", false, 300.0),
125+
("phase3", "Phase 3 — Oil & Quartz (Tiers 5-6)", false, 400.0),
126+
("phase4", "Phase 4 — Aluminum & Nuclear (Tiers 7-8)", true, 600.0),
127+
("phase5", "Phase 5 — Quantum (Tier 9)", true, 800.0),
127128
(
128129
"collectibles",
129130
"Collectibles — Slugs, Artifacts & Hard Drives",
130131
true,
132+
1000.0,
131133
),
132134
];
133135

134136
phases
135137
.iter()
136-
.map(|(id, name, ignore_spawns)| {
138+
.map(|(id, name, ignore_spawns, sigma)| {
137139
let mut weights = HashMap::<String, f64>::new();
138140

139141
if *id == "collectibles" {
@@ -152,7 +154,7 @@ fn build_presets() -> Vec<PresetResponse> {
152154
PresetResponse {
153155
id: id.to_string(),
154156
name: name.to_string(),
155-
sigma: 700.0,
157+
sigma: *sigma,
156158
ignore_spawns: *ignore_spawns,
157159
weights,
158160
}
@@ -181,7 +183,7 @@ async fn post_optimize(
181183

182184
// Build OptimizerConfig from request
183185
let mut config = OptimizerConfig {
184-
sigma: 700.0,
186+
sigma: req.sigma.clamp(50.0, 1000.0),
185187
weights: req.weights.clone(),
186188
purity_override: parse_purity(&req.purity_override),
187189
strategy: parse_strategy(&req.strategy),

0 commit comments

Comments
 (0)