Update rewrite docs and cleanup

This commit is contained in:
2026-05-10 18:09:43 +02:00
parent 7ffaa140a8
commit d22c4a7528
51 changed files with 129 additions and 141 deletions

View File

@@ -46,6 +46,13 @@
- Added tests for network-band rules, reactor-ready rules, inventory rules, removal effects, electricity leak access, and invalid rule targets.
- Verified `dotnet test tests/ReactorMaintenance.Simulation.Tests/ReactorMaintenance.Simulation.Tests.csproj` passes after the rule slice: 21 passed.
- Ran `jb cleanupcode --build=False ...` and `python D:\Code\crlf.py ...` for touched C# files after the rule slice.
- Split serializable simulation records and enums from the monolithic `Models.cs` file into individual files under `Models`.
- Moved level creation, grid mutation helpers, surface clamping, grid geometry, and inventory operations out of serializable model records.
- Replaced separate T-junction and cross-junction props/tools with one topology-inferred `Junction` prop and one editor tool.
- Moved junction ratio presets into balancing data.
- Replaced hardcoded `EPairEffect` variants with parameterized surface interaction verbs and balance-owned magnitudes.
- Introduced a small public `SimulationEngine` facade over an internal simulation system implementation.
- Updated design documentation for generic junctions and parameterized surface interactions.
## Current Work
@@ -53,7 +60,7 @@
## Future Work
1. Expand simulation fidelity where the first slice is intentionally simplified: complete pair table coverage and stronger forecast proof cases.
1. Continue splitting the internal simulation system into smaller action, network, consumer, leak, surface interaction, robot safety, reactor, rule, and forecast systems.
2. Add advanced editor workflows for explicit reactor binding selection, explicit door edge selection, electricity wall leak face selection, and rule event authoring.
3. Verify and polish the Win2D app on Windows where the XAML compiler can run.
4. Update README and any affected docs to reflect the new schema, .NET target, editor controls, and deterministic defaults.

View File

@@ -1,4 +1,4 @@
# Reactor Maintenance Design
# Reactor Maintenance Design
## Concept
@@ -114,8 +114,7 @@ Surface prop categories:
- flow prop
- consumer prop
- T-junction prop
- cross-junction prop
- junction prop
- door prop
- all-seeing-eye terminal prop
- remedy supply prop
@@ -155,24 +154,9 @@ The level is invalid if any binding is missing, out of bounds, or points to the
A junction prop must be on a floor cell whose coordinate has exactly one underground carrier. That carrier is the regulated network.
T-junction modes:
The engine infers incoming and outgoing branch directions from valid network topology and enabled source paths. A valid junction has one incoming branch and either two or three outgoing branches. Ambiguous junction flow is invalid. Ratio numbers are balance-defined weights that divide carrier amount and pressure or voltage. A zero-weight branch receives no intentional outflow.
- `0/4`
- `1/3`
- `2/2`
- `3/1`
- `4/0`
Cross-junction modes:
- `0/3/3`
- `3/0/3`
- `3/3/0`
- `2/2/2`
The engine infers incoming and outgoing branch directions from valid network topology and enabled source paths. Ambiguous junction flow is invalid. Ratio numbers are weights that divide carrier amount and pressure or voltage by balance-defined math. A zero-weight branch receives no intentional outflow.
The gameplay UI exposes ratio modes.
The gameplay UI exposes a single junction tool and cycles through balance-defined ratio presets for the inferred outgoing branch count.
### Doors
@@ -284,33 +268,28 @@ Balance thresholds project numeric values into safe, caution, and critical bands
The pair table maps projected bands to deterministic effects:
- `Hold`: no direct change.
- `FuelFlow`: equalize leaked fuel.
- `CoolFlow`: equalize leaked coolant.
- `ChargeFlow`: equalize leaked electricity.
- `HeatFlow`: transfer heat.
- `HeatFlow2`: stronger heat transfer.
- `Warm1`: small heat increase from fuel exposure.
- `Warm2`: larger heat increase from fuel exposure.
- `Quench1`: small heat reduction from coolant exposure.
- `Quench2`: larger heat reduction from coolant exposure.
- `Short1`: electricity and coolant interaction causing heat and discharge.
- `Short2`: stronger short.
- `Ignite1`: fuel interaction with electricity or high heat.
- `Ignite2`: stronger ignition.
The pair table maps projected bands to parameterized verbs:
- `Hold`: no direct change.
- `Flow(amount)`: equalize a surface quantity by a balance-defined transfer amount.
- `Warm(amount)`: increase heat by a balance-defined amount.
- `Quench(amount)`: reduce heat by a balance-defined amount.
- `Short(heat, discharge)`: add heat and discharge electricity by balance-defined amounts.
- `Ignite(heat, fuel)`: add heat and consume fuel by balance-defined amounts.
| Row\Col | FuelSafe | FuelCaution | FuelCritical | CoolantSafe | CoolantCaution | CoolantCritical | ElectricitySafe | ElectricityCaution | ElectricityCritical | HeatSafe | HeatCaution | HeatCritical |
| ------- | -------- | ----------- | ------------ | ----------- | -------------- | --------------- | --------------- | ------------------ | ------------------- | -------- | ----------- | ------------ |
| FuelSafe | Hold | FuelFlow | FuelFlow | Hold | Hold | Hold | Hold | Warm1 | Warm2 | Hold | Warm1 | Warm2 |
| FuelCaution | | Hold | FuelFlow | Hold | Hold | Hold | Warm1 | Ignite1 | Ignite2 | Warm1 | Ignite1 | Ignite2 |
| FuelCritical | | | Hold | Hold | Hold | Hold | Warm2 | Ignite2 | Ignite2 | Warm2 | Ignite2 | Ignite2 |
| CoolantSafe | | | | Hold | CoolFlow | CoolFlow | Hold | Short1 | Short2 | Hold | Quench1 | Quench1 |
| CoolantCaution | | | | | Hold | CoolFlow | Short1 | Short1 | Short2 | Hold | Quench1 | Quench2 |
| CoolantCritical | | | | | | Hold | Short2 | Short2 | Short2 | Hold | Quench2 | Quench2 |
| ElectricitySafe | | | | | | | Hold | ChargeFlow | ChargeFlow | Hold | Hold | Hold |
| ElectricityCaution | | | | | | | | Hold | ChargeFlow | Hold | Hold | Hold |
| FuelSafe | Hold | Flow | Flow | Hold | Hold | Hold | Hold | Warm | Ignite | Hold | Warm | Ignite |
| FuelCaution | | Hold | Flow | Hold | Hold | Hold | Warm | Ignite | Ignite | Warm | Ignite | Ignite |
| FuelCritical | | | Hold | Hold | Hold | Hold | Ignite | Ignite | Ignite | Ignite | Ignite | Ignite |
| CoolantSafe | | | | Hold | Flow | Flow | Hold | Short | Short | Hold | Quench | Quench |
| CoolantCaution | | | | | Hold | Flow | Short | Short | Short | Hold | Quench | Quench |
| CoolantCritical | | | | | | Hold | Short | Short | Short | Hold | Quench | Quench |
| ElectricitySafe | | | | | | | Hold | Flow | Flow | Hold | Hold | Hold |
| ElectricityCaution | | | | | | | | Hold | Flow | Hold | Hold | Hold |
| ElectricityCritical | | | | | | | | | Hold | Hold | Hold | Hold |
| HeatSafe | | | | | | | | | | Hold | HeatFlow | HeatFlow2 |
| HeatCaution | | | | | | | | | | | Hold | HeatFlow |
| HeatSafe | | | | | | | | | | Hold | Flow | Flow |
| HeatCaution | | | | | | | | | | | Hold | Flow |
| HeatCritical | | | | | | | | | | | | Hold |
Design rules:
@@ -422,7 +401,7 @@ The editor authors:
- underground fuel, coolant, and electricity cells
- flow props and consumer props
- reactor controls and reactor consumer bindings
- junction props and ratio modes
- junction props and balance-defined ratio mode index
- door props and door edges
- all-seeing-eye terminals
- remedy supplies

View File

@@ -1,4 +1,4 @@
using ReactorMaintenance.Simulation.Difficulties;
using ReactorMaintenance.Simulation.Difficulties;
namespace ReactorMaintenance.Simulation;
@@ -158,4 +158,4 @@ public abstract class Balancing
public abstract int RemedyBlockTurns { get; }
public abstract int HeatShieldSteps { get; }
public abstract int InventoryCapacityPerRemedy { get; }
}
}

View File

@@ -1,4 +1,4 @@
namespace ReactorMaintenance.Simulation.Difficulties;
namespace ReactorMaintenance.Simulation.Difficulties;
public class NormalBalancing : Balancing
{
@@ -30,6 +30,7 @@ public class NormalBalancing : Balancing
public override float SourceIntensity => 8;
public override float DistanceAmountFalloff => 0.5f;
public override float DistanceIntensityFalloff => 0.4f;
public override IReadOnlyList<JunctionRatioPreset> TwoOutflowJunctionRatios { get; } = [
new("0/4", [0, 1]),
new("1/3", [0.25f, 0.75f]),
@@ -37,12 +38,14 @@ public class NormalBalancing : Balancing
new("3/1", [0.75f, 0.25f]),
new("4/0", [1, 0])
];
public override IReadOnlyList<JunctionRatioPreset> ThreeOutflowJunctionRatios { get; } = [
new("0/3/3", [0, 0.5f, 0.5f]),
new("3/0/3", [0.5f, 0, 0.5f]),
new("3/3/0", [0.5f, 0.5f, 0]),
new("2/2/2", [1f / 3f, 1f / 3f, 1f / 3f])
];
public override float ConsumerRequiredAmount => 2.5f;
public override float ConsumerRequiredIntensity => 2.5f;
public override float LeakBaseAmount => 0.5f;
@@ -64,4 +67,4 @@ public class NormalBalancing : Balancing
public override int RemedyBlockTurns => 2;
public override int HeatShieldSteps => 3;
public override int InventoryCapacityPerRemedy => 3;
}
}

View File

@@ -1,4 +1,4 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public static class GridPositionExtensions
{
@@ -14,4 +14,4 @@ public static class GridPositionExtensions
{
return Math.Abs(position.X - other.X) + Math.Abs(position.Y - other.Y);
}
}
}

View File

@@ -31,4 +31,4 @@ public sealed record JunctionFlow
return -1;
}
}
}

View File

@@ -94,4 +94,4 @@ public static class JunctionFlowAnalyzer
}
private sealed record SourceBranch(GridPosition Position, int? Distance);
}
}

View File

@@ -1,3 +1,3 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public sealed record JunctionRatioPreset(string Label, float[] Weights);
public sealed record JunctionRatioPreset(string Label, float[] Weights);

View File

@@ -1,4 +1,4 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public enum EEditorTool
{
@@ -160,4 +160,4 @@ public static class LevelEditor
]
};
}
}
}

View File

@@ -1,4 +1,4 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public static class LevelStateExtensions
{
@@ -113,4 +113,4 @@ public static class LevelStateExtensions
{
return edgeA == a && edgeB == b || edgeA == b && edgeB == a;
}
}
}

View File

@@ -1,4 +1,4 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public static class LevelStateFactory
{
@@ -51,4 +51,4 @@ public static class LevelStateFactory
{
return Enumerable.Range(0, width * height).Select(_ => new PropState()).ToArray();
}
}
}

View File

@@ -1,8 +1,8 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public sealed record DoorState
{
public GridPosition A { get; init; } = new(0, 0);
public GridPosition B { get; init; } = new(0, 0);
public EDoorState State { get; init; } = EDoorState.Closed;
}
}

View File

@@ -1,8 +1,8 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public enum EBand
{
Safe,
Caution,
Critical
}
}

View File

@@ -1,8 +1,8 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public enum ECarrierType
{
Fuel,
Coolant,
Electricity
}
}

View File

@@ -1,7 +1,7 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public enum ECellTerrain
{
Floor,
Wall
}
}

View File

@@ -1,4 +1,4 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public enum EConsumerServiceState
{
@@ -7,4 +7,4 @@ public enum EConsumerServiceState
Starved,
Supplied,
Producing
}
}

View File

@@ -1,7 +1,7 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public enum EDoorState
{
Open,
Closed
}
}

View File

@@ -1,4 +1,4 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public enum EForecastKind
{
@@ -7,4 +7,4 @@ public enum EForecastKind
ConsumerStarved,
HazardGrowth,
RuleEvent
}
}

View File

@@ -1,4 +1,4 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public enum ELevelState
{
@@ -8,4 +8,4 @@ public enum ELevelState
Ready,
Lost,
Won
}
}

View File

@@ -1,7 +1,7 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public enum ENetworkValueKind
{
Amount,
Intensity
}
}

View File

@@ -1,7 +1,7 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public enum EPropSwitchState
{
Disabled,
Enabled
}
}

View File

@@ -1,4 +1,4 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public enum EPropType
{
@@ -10,4 +10,4 @@ public enum EPropType
AllSeeingEyeTerminal,
RemedySupply,
ReactorControl
}
}

View File

@@ -1,4 +1,4 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public enum ERemedyType
{
@@ -6,4 +6,4 @@ public enum ERemedyType
CoolantNeutralizer,
ElectricityNeutralizer,
HeatShield
}
}

View File

@@ -1,4 +1,4 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public enum ERuleEffectKind
{
@@ -15,4 +15,4 @@ public enum ERuleEffectKind
RemoveInventory,
MarkTerminalLoss,
EmitWarning
}
}

View File

@@ -1,7 +1,7 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public enum ERuleEventPhase
{
StartOfSimulation,
EndOfTurn
}
}

View File

@@ -1,4 +1,4 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public enum ERulePredicateKind
{
@@ -14,4 +14,4 @@ public enum ERulePredicateKind
RobotAt,
RobotInventoryAtLeast,
AllSeeingEyeUnlocked
}
}

View File

@@ -1,4 +1,4 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public enum ESurfaceInteractionVerb
{
@@ -8,4 +8,4 @@ public enum ESurfaceInteractionVerb
Quench,
Short,
Ignite
}
}

View File

@@ -1,4 +1,4 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public enum ESurfaceQuantity
{
@@ -6,4 +6,4 @@ public enum ESurfaceQuantity
Coolant,
Electricity,
Heat
}
}

View File

@@ -1,8 +1,8 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public enum EUndergroundState
{
Absent,
Intact,
Leaking
}
}

View File

@@ -1,3 +1,3 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public sealed record Forecast(EForecastKind Kind, GridPosition? Position, int Turns, string Message);
public sealed record Forecast(EForecastKind Kind, GridPosition? Position, int Turns, string Message);

View File

@@ -1,4 +1,4 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public sealed record GlobalState
{
@@ -9,4 +9,4 @@ public sealed record GlobalState
public bool AllSeeingEyeUnlocked { get; init; }
public bool TerminalLoss { get; init; }
public IReadOnlyList<string> Warnings { get; init; } = Array.Empty<string>();
}
}

View File

@@ -1,3 +1,3 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public sealed record GridPosition(int X, int Y);
public sealed record GridPosition(int X, int Y);

View File

@@ -1,4 +1,4 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public sealed record LeakState
{
@@ -6,4 +6,4 @@ public sealed record LeakState
public GridPosition UndergroundPosition { get; init; } = new(0, 0);
public GridPosition AccessPosition { get; init; } = new(0, 0);
public bool Repaired { get; init; }
}
}

View File

@@ -1,4 +1,4 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public sealed record LevelState
{
@@ -23,4 +23,4 @@ public sealed record LevelState
public RobotState Robot { get; init; } = new();
public GlobalState Global { get; init; } = new();
public IReadOnlyList<Forecast> Forecasts { get; init; } = Array.Empty<Forecast>();
}
}

View File

@@ -1,4 +1,4 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public sealed record PropState
{
@@ -12,4 +12,4 @@ public sealed record PropState
public int ReactorId { get; init; }
public bool IsEnabled => SwitchState == EPropSwitchState.Enabled;
}
}

View File

@@ -1,4 +1,4 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public sealed record ReactorBinding
{
@@ -9,4 +9,4 @@ public sealed record ReactorBinding
public GridPosition ElectricityConsumerPosition { get; init; } = new(0, 0);
public bool Ready { get; init; }
public bool Activated { get; init; }
}
}

View File

@@ -1,4 +1,4 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public sealed record RobotState
{
@@ -8,4 +8,4 @@ public sealed record RobotState
public int ElectricityNeutralizers { get; init; }
public int HeatShields { get; init; }
public int HeatImmunitySteps { get; init; }
}
}

View File

@@ -1,4 +1,4 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public sealed record RuleEffect
{
@@ -10,4 +10,4 @@ public sealed record RuleEffect
public float Amount { get; init; }
public EPropSwitchState PropSwitchState { get; init; }
public string Message { get; init; } = string.Empty;
}
}

View File

@@ -1,4 +1,4 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public sealed record RuleEventState
{
@@ -11,4 +11,4 @@ public sealed record RuleEventState
public IReadOnlyList<RulePredicate> Predicates { get; init; } = Array.Empty<RulePredicate>();
public IReadOnlyList<RuleEffect> Effects { get; init; } = Array.Empty<RuleEffect>();
public string ForecastText { get; init; } = string.Empty;
}
}

View File

@@ -1,4 +1,4 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public sealed record RulePredicate
{
@@ -15,4 +15,4 @@ public sealed record RulePredicate
public EBand Band { get; init; }
public int InventoryCount { get; init; }
public bool BoolValue { get; init; }
}
}

View File

@@ -1,4 +1,4 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public sealed record SurfaceState
{
@@ -9,4 +9,4 @@ public sealed record SurfaceState
public int FuelBlockTurns { get; init; }
public int CoolantBlockTurns { get; init; }
public int ElectricityBlockTurns { get; init; }
}
}

View File

@@ -1,4 +1,4 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public sealed record UndergroundCell
{
@@ -8,4 +8,4 @@ public sealed record UndergroundCell
public bool IsPresent => State != EUndergroundState.Absent;
public bool CarriesFlow => State is EUndergroundState.Intact or EUndergroundState.Leaking;
}
}

View File

@@ -1,3 +1,3 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public sealed record ValidationIssue(string Message, GridPosition? Position = null);
public sealed record ValidationIssue(string Message, GridPosition? Position = null);

View File

@@ -1,8 +1,8 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public sealed record ValidationReport
{
public IReadOnlyList<ValidationIssue> Errors { get; init; } = Array.Empty<ValidationIssue>();
public IReadOnlyList<ValidationIssue> Warnings { get; init; } = Array.Empty<ValidationIssue>();
public bool IsValid => Errors.Count == 0;
}
}

View File

@@ -1,4 +1,4 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public static class RobotStateExtensions
{
@@ -33,4 +33,4 @@ public static class RobotStateExtensions
{
return Math.Clamp(value, 0, Balancing.Current.InventoryCapacityPerRemedy);
}
}
}

View File

@@ -1,4 +1,4 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public sealed class SimulationEngine
{
@@ -43,4 +43,4 @@ public sealed class SimulationEngine
}
private readonly SimulationCoreSystem m_Core = new();
}
}

View File

@@ -1,4 +1,4 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public sealed record SurfaceInteractionEffect
{
@@ -8,4 +8,4 @@ public sealed record SurfaceInteractionEffect
public ESurfaceQuantity Quantity { get; init; }
public float Amount { get; init; }
public float SecondaryAmount { get; init; }
}
}

View File

@@ -1,4 +1,4 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
public static class SurfaceStateExtensions
{
@@ -25,4 +25,4 @@ public static class SurfaceStateExtensions
_ => throw new ArgumentOutOfRangeException(nameof(carrier), carrier, "Unsupported carrier.")
};
}
}
}

View File

@@ -1,4 +1,4 @@
namespace ReactorMaintenance.Simulation;
namespace ReactorMaintenance.Simulation;
internal sealed class SimulationCoreSystem
{
@@ -703,5 +703,4 @@ internal sealed class SimulationCoreSystem
}
private readonly LevelValidator m_Validator = new();
}
}

View File

@@ -1,4 +1,4 @@
using Microsoft.Graphics.Canvas;
using Microsoft.Graphics.Canvas;
using Microsoft.Graphics.Canvas.Text;
using Microsoft.Graphics.Canvas.UI.Xaml;
using Microsoft.UI;
@@ -717,4 +717,4 @@ public sealed partial class MainWindow
private CanvasBitmap? m_RobotSprite;
private CanvasBitmap? m_LeakSprite;
private CanvasBitmap? m_HeatSprite;
}
}

View File

@@ -405,4 +405,4 @@ public sealed class SimulationEngineTests
}
private readonly SimulationEngine m_Engine = new();
}
}