Use primary constructor for simulation effects
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
namespace ReactorMaintenance.Simulation;
|
namespace ReactorMaintenance.Simulation;
|
||||||
|
|
||||||
public sealed class SimulationEngine
|
public sealed class SimulationEngine(IEnumerable<ISimulationEffect> effects, IEnumerable<IAreaSimulationEffect> areaEffects, IEnumerable<Hazard> hazards)
|
||||||
{
|
{
|
||||||
private const int c_MaxForecastStepCount = 12;
|
private sealed record ForecastKey(EFailureKind Kind, GridPosition? Position);
|
||||||
|
|
||||||
public SimulationEngine()
|
public SimulationEngine()
|
||||||
: this(
|
: this(
|
||||||
@@ -12,13 +12,6 @@ public sealed class SimulationEngine
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public SimulationEngine(IEnumerable<ISimulationEffect> effects, IEnumerable<IAreaSimulationEffect> areaEffects, IEnumerable<Hazard> hazards)
|
|
||||||
{
|
|
||||||
m_Effects = effects.ToArray();
|
|
||||||
m_AreaEffects = areaEffects.ToArray();
|
|
||||||
m_Hazards = hazards.ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
public LevelState AdvanceTurn(LevelState level)
|
public LevelState AdvanceTurn(LevelState level)
|
||||||
{
|
{
|
||||||
return AdvanceTurn(level, true);
|
return AdvanceTurn(level, true);
|
||||||
@@ -29,11 +22,11 @@ public sealed class SimulationEngine
|
|||||||
var forecasts = new List<Forecast>();
|
var forecasts = new List<Forecast>();
|
||||||
var seen = new HashSet<ForecastKey>();
|
var seen = new HashSet<ForecastKey>();
|
||||||
var forecastLevel = level with { Cells = level.Cells.ToArray(), Forecasts = Array.Empty<Forecast>() };
|
var forecastLevel = level with { Cells = level.Cells.ToArray(), Forecasts = Array.Empty<Forecast>() };
|
||||||
|
|
||||||
if (forecastLevel.Global.Lost)
|
if (forecastLevel.Global.Lost)
|
||||||
AddHazardForecasts(forecasts, seen, forecastLevel, 0);
|
AddHazardForecasts(forecasts, seen, forecastLevel, 0);
|
||||||
|
|
||||||
AddReactorReadyForecast(forecasts, seen, forecastLevel, 0);
|
AddReactorReadyForecast(forecasts, seen, forecastLevel, 0);
|
||||||
|
|
||||||
if (IsReactorReady(forecastLevel) || forecastLevel.Global.Lost || forecastLevel.Global.ReactorActivated)
|
if (IsReactorReady(forecastLevel) || forecastLevel.Global.Lost || forecastLevel.Global.ReactorActivated)
|
||||||
return forecasts.OrderBy(f => f.Turns).ThenBy(f => f.Message).ToArray();
|
return forecasts.OrderBy(f => f.Turns).ThenBy(f => f.Message).ToArray();
|
||||||
|
|
||||||
@@ -148,9 +141,9 @@ public sealed class SimulationEngine
|
|||||||
return hasReactor && hasStablePower && hasCooling && reactorStable && !level.Global.Lost;
|
return hasReactor && hasStablePower && hasCooling && reactorStable && !level.Global.Lost;
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly IReadOnlyList<ISimulationEffect> m_Effects;
|
private const int c_MaxForecastStepCount = 12;
|
||||||
private readonly IReadOnlyList<IAreaSimulationEffect> m_AreaEffects;
|
private readonly IReadOnlyList<IAreaSimulationEffect> m_AreaEffects = areaEffects.ToArray();
|
||||||
private readonly IReadOnlyList<Hazard> m_Hazards;
|
|
||||||
|
|
||||||
private sealed record ForecastKey(EFailureKind Kind, GridPosition? Position);
|
private readonly IReadOnlyList<ISimulationEffect> m_Effects = effects.ToArray();
|
||||||
|
private readonly IReadOnlyList<Hazard> m_Hazards = hazards.ToArray();
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user