Compare commits
2 Commits
simulation
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 74840d32c1 | |||
| d6ee42b66d |
@@ -17,7 +17,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="simulation-layout">
|
||||
<div class="simulation-layout" tabindex="0" @onkeydown="HandleKeyDown" @ref="layoutDiv">
|
||||
<div class="sim-controls d-flex align-items-center justify-content-between mb-3 flex-wrap gap-2">
|
||||
<div class="d-flex align-items-center gap-2">
|
||||
<button class="btn btn-outline-light btn-sm" @onclick="PrevTurn" disabled="@(SimService.Data.CurrentTurn <= 0)">
|
||||
@@ -99,7 +99,7 @@ else
|
||||
stroke="rgba(255,255,255,0.12)" stroke-width="2" stroke-linecap="round"/>
|
||||
}
|
||||
|
||||
@foreach (var region in currentRegions)
|
||||
@foreach (var region in currentRegions)
|
||||
{
|
||||
var isActivated = activatedRegionNames.Contains(region.Name);
|
||||
var terrainColor = GetTerrainColor(region.Terrain);
|
||||
@@ -109,12 +109,57 @@ else
|
||||
var dr = prev != null ? region.PreyMeeples - prev.PreyMeeples : 0;
|
||||
var df = prev != null ? region.FloraMeeples - prev.FloraMeeples : 0;
|
||||
var hasDelta = dp != 0 || dr != 0 || df != 0;
|
||||
|
||||
// Meeple dot counts (max 3 visible per type)
|
||||
var pdots = Math.Min(region.PredatorMeeples, 3);
|
||||
var rdots = Math.Min(region.PreyMeeples, 3);
|
||||
var fdots = Math.Min(region.FloraMeeples, 3);
|
||||
var dotR = 3;
|
||||
var dotGap = 7;
|
||||
|
||||
<g class="sim-region @(isActivated ? "sim-active" : "")">
|
||||
<circle cx="@region.X" cy="@region.Y" r="34" fill="url(#sg-@region.Terrain)"/>
|
||||
<circle cx="@region.X" cy="@region.Y" r="18"
|
||||
fill="@(terrainColor)cc"
|
||||
stroke="@(isActivated ? "#ffd700" : "rgba(255,255,255,0.5)")"
|
||||
stroke-width="@(isActivated ? 3 : 2)"/>
|
||||
|
||||
@* Predator dots (red, top row) *@
|
||||
@for (int d = 0; d < pdots; d++)
|
||||
{
|
||||
var dx = region.X + (d - (pdots - 1) * 0.5) * dotGap;
|
||||
var dy = region.Y - 7;
|
||||
<circle cx="@dx" cy="@dy" r="@dotR" fill="#e76f51" stroke="rgba(0,0,0,0.4)" stroke-width="0.5"/>
|
||||
}
|
||||
@if (region.PredatorMeeples > 3)
|
||||
{
|
||||
@((MarkupString)$"<text x=\"{region.X + 2 * dotGap + 2}\" y=\"{region.Y - 4}\" fill=\"#e76f51\" font-size=\"7\" font-weight=\"600\">+{region.PredatorMeeples - 3}</text>")
|
||||
}
|
||||
|
||||
@* Prey dots (yellow, middle row) *@
|
||||
@for (int d = 0; d < rdots; d++)
|
||||
{
|
||||
var dx = region.X + (d - (rdots - 1) * 0.5) * dotGap;
|
||||
var dy = region.Y;
|
||||
<circle cx="@dx" cy="@dy" r="@dotR" fill="#e9c46a" stroke="rgba(0,0,0,0.4)" stroke-width="0.5"/>
|
||||
}
|
||||
@if (region.PreyMeeples > 3)
|
||||
{
|
||||
@((MarkupString)$"<text x=\"{region.X + 2 * dotGap + 2}\" y=\"{region.Y + 3}\" fill=\"#e9c46a\" font-size=\"7\" font-weight=\"600\">+{region.PreyMeeples - 3}</text>")
|
||||
}
|
||||
|
||||
@* Flora dots (green, bottom row) *@
|
||||
@for (int d = 0; d < fdots; d++)
|
||||
{
|
||||
var dx = region.X + (d - (fdots - 1) * 0.5) * dotGap;
|
||||
var dy = region.Y + 7;
|
||||
<circle cx="@dx" cy="@dy" r="@dotR" fill="#4caf50" stroke="rgba(0,0,0,0.4)" stroke-width="0.5"/>
|
||||
}
|
||||
@if (region.FloraMeeples > 3)
|
||||
{
|
||||
@((MarkupString)$"<text x=\"{region.X + 2 * dotGap + 2}\" y=\"{region.Y + 10}\" fill=\"#4caf50\" font-size=\"7\" font-weight=\"600\">+{region.FloraMeeples - 3}</text>")
|
||||
}
|
||||
|
||||
<text x="@labelX" y="@(region.Y + 4)" fill="rgba(255,255,255,0.9)"
|
||||
font-family="system-ui,sans-serif" font-size="11" font-weight="600">
|
||||
@region.Name
|
||||
@@ -218,6 +263,7 @@ else
|
||||
|
||||
|
||||
@code {
|
||||
private ElementReference layoutDiv;
|
||||
private TurnEvent? CurrentEvent => SimService.Data.CurrentTurn > 0 && SimService.Data.CurrentTurn <= SimService.Data.Events.Count
|
||||
? SimService.Data.Events[SimService.Data.CurrentTurn - 1]
|
||||
: null;
|
||||
@@ -252,6 +298,18 @@ else
|
||||
SimService.Data.CurrentTurn++;
|
||||
}
|
||||
|
||||
private void HandleKeyDown(KeyboardEventArgs e)
|
||||
{
|
||||
if (e.Key == "ArrowLeft") PrevTurn();
|
||||
else if (e.Key == "ArrowRight") NextTurn();
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (firstRender)
|
||||
await layoutDiv.FocusAsync();
|
||||
}
|
||||
|
||||
private void RandomizeEvents()
|
||||
{
|
||||
SimService.RandomizeEvents();
|
||||
|
||||
@@ -76,12 +76,7 @@ public class GameSimulationService
|
||||
|
||||
public void RandomizeEvents()
|
||||
{
|
||||
var initialRegions = Data.InitialRegions;
|
||||
Data = new SimulationData();
|
||||
Data.Regions = initialRegions.Select(r => r.Clone()).ToList();
|
||||
Data.InitialRegions = initialRegions;
|
||||
GenerateAndApplyEvents();
|
||||
Data.IsInitialized = true;
|
||||
RunSimulation();
|
||||
}
|
||||
|
||||
public List<RegionState> GetCurrentState()
|
||||
@@ -181,22 +176,25 @@ public class GameSimulationService
|
||||
if (region.PredatorMeeples <= 0)
|
||||
return;
|
||||
|
||||
if (region.PreyMeeples > 0)
|
||||
int total = region.PredatorMeeples;
|
||||
int canEat = Math.Min(total, region.PreyMeeples);
|
||||
int mustTravel = total - canEat;
|
||||
|
||||
if (canEat > 0)
|
||||
{
|
||||
int eaten = Math.Min(region.PredatorMeeples, region.PreyMeeples);
|
||||
region.PreyMeeples -= eaten;
|
||||
region.PredatorMeeples += eaten;
|
||||
details.Add($"{region.Name}: Predators ate {eaten} prey, now {region.PredatorMeeples}P / {region.PreyMeeples}R");
|
||||
region.PreyMeeples -= canEat;
|
||||
region.PredatorMeeples += canEat;
|
||||
details.Add($"{region.Name}: {canEat} predators ate prey, +{canEat} new predators");
|
||||
}
|
||||
else
|
||||
|
||||
if (mustTravel > 0)
|
||||
{
|
||||
var target = FindBestTravelTarget(region, r => r.PreyMeeples);
|
||||
if (target != null)
|
||||
{
|
||||
int traveling = region.PredatorMeeples;
|
||||
target.PredatorMeeples += traveling;
|
||||
region.PredatorMeeples = 0;
|
||||
details.Add($"{region.Name}: {traveling} predators traveled to {target.Name}");
|
||||
region.PredatorMeeples -= mustTravel;
|
||||
target.PredatorMeeples += mustTravel;
|
||||
details.Add($"{region.Name}: {mustTravel} predators traveled to {target.Name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -206,22 +204,25 @@ public class GameSimulationService
|
||||
if (region.PreyMeeples <= 0)
|
||||
return;
|
||||
|
||||
if (region.FloraMeeples > 0)
|
||||
int total = region.PreyMeeples;
|
||||
int canEat = Math.Min(total, region.FloraMeeples);
|
||||
int mustTravel = total - canEat;
|
||||
|
||||
if (canEat > 0)
|
||||
{
|
||||
int consumed = Math.Min(region.PreyMeeples, region.FloraMeeples);
|
||||
region.FloraMeeples -= consumed;
|
||||
region.PreyMeeples += consumed;
|
||||
details.Add($"{region.Name}: Prey consumed {consumed} flora, now {region.PreyMeeples}R / {region.FloraMeeples}F");
|
||||
region.FloraMeeples -= canEat;
|
||||
region.PreyMeeples += canEat;
|
||||
details.Add($"{region.Name}: {canEat} prey ate flora, +{canEat} new prey");
|
||||
}
|
||||
else
|
||||
|
||||
if (mustTravel > 0)
|
||||
{
|
||||
var target = FindBestTravelTarget(region, r => r.FloraMeeples);
|
||||
if (target != null)
|
||||
{
|
||||
int traveling = region.PreyMeeples;
|
||||
target.PreyMeeples += traveling;
|
||||
region.PreyMeeples = 0;
|
||||
details.Add($"{region.Name}: {traveling} prey traveled to {target.Name}");
|
||||
region.PreyMeeples -= mustTravel;
|
||||
target.PreyMeeples += mustTravel;
|
||||
details.Add($"{region.Name}: {mustTravel} prey traveled to {target.Name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -315,13 +316,22 @@ public class GameSimulationService
|
||||
}
|
||||
}
|
||||
|
||||
var excluded = new HashSet<string>
|
||||
{
|
||||
"Grass 1", "Grass 2", "Wasteland 1",
|
||||
"Mountain 1", "Mountain 2", "Mountain 3", "Mountain 4", "Mountain 5"
|
||||
};
|
||||
|
||||
var shuffled = combos.OrderBy(_ => _rng.Next()).ToList();
|
||||
for (int i = 0; i < Data.Regions.Count; i++)
|
||||
{
|
||||
var (p, r, f) = shuffled[i % shuffled.Count];
|
||||
Data.Regions[i].PredatorMeeples = p;
|
||||
Data.Regions[i].PreyMeeples = r;
|
||||
Data.Regions[i].FloraMeeples = f;
|
||||
if (!excluded.Contains(Data.Regions[i].Name))
|
||||
{
|
||||
var (p, r, f) = shuffled[i % shuffled.Count];
|
||||
Data.Regions[i].PredatorMeeples = p;
|
||||
Data.Regions[i].PreyMeeples = r;
|
||||
Data.Regions[i].FloraMeeples += f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user