- Abbinamento mensile dei pendolari sul LineGraph (60/90 minuti con i tratti a piedi, quote proporzionali ai lavoratori liberi, capacità residua delle linee), pacchetti giornalieri, coperture e scioglimento dei contratti. - LineGraph con maschere dei carichi: merci, lavoratori e personale viaggiano solo su linee i cui treni li possono portare; durata dei giri con le soste di carico e scarico. - Industria servita = merce ritirata o consegnata dal vettore. - Parametri residui spostati in data/*.json. - Test di accettazione F2 sullo scenario Valdoria con tre linee, test del pendolarismo (copertura > 0,9 in 60 giorni, capacità, scioglimento). - viaferrea-tools bench: 2.000 treni, tick medio 0,84 ms. - ADR 0007 e 0008, ARCHITECTURE e STATE aggiornati. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0191R7vXgtbAvSV4V8tj8uzL
90 lines
3.5 KiB
C#
90 lines
3.5 KiB
C#
using ViaFerrea.Core.Commands;
|
|
using ViaFerrea.Core.Common;
|
|
using ViaFerrea.Core.Rail;
|
|
using ViaFerrea.Core.Simulation;
|
|
using ViaFerrea.Core.Simulation.Scenarios;
|
|
using ViaFerrea.Tests.Harness;
|
|
using ViaFerrea.Tests.Scenarios;
|
|
|
|
namespace ViaFerrea.Tests.Rail;
|
|
|
|
/// <summary>Mondo con comandi di comodo per i test ferroviari.</summary>
|
|
public sealed class RailFixture
|
|
{
|
|
public World W { get; }
|
|
public LoadedScenario? Scenario { get; }
|
|
public CompanyId Me => W.Player.Id;
|
|
|
|
public RailFixture(World w, LoadedScenario? scenario = null)
|
|
{
|
|
W = w;
|
|
Scenario = scenario;
|
|
}
|
|
|
|
public static RailFixture Valdoria() { var s = ScenarioHelper.Load("valdoria"); return new RailFixture(s.World, s); }
|
|
|
|
public static Vec2 K(double x, double y) => new(x * 1000, y * 1000);
|
|
|
|
/// <summary>Esegue il comando nel prossimo tick e ne restituisce l'esito.</summary>
|
|
public CommandResult Do(GameCommand c, CompanyId? issuer = null)
|
|
{
|
|
W.Enqueue(c with { Issuer = issuer ?? Me });
|
|
W.RunTicks(1);
|
|
return W.DrainResults().Last();
|
|
}
|
|
|
|
public int Ok(GameCommand c, CompanyId? issuer = null)
|
|
{
|
|
var r = Do(c, issuer);
|
|
Assert.True(r.Ok, $"{c.Type}: {r.Error} {r.Message}");
|
|
return r.Created.Length > 0 ? r.Created[0] : -1;
|
|
}
|
|
|
|
/// <summary>Esegue giorni finché la condizione è vera (o scade il limite).</summary>
|
|
public bool RunUntil(Func<bool> condition, int maxDays)
|
|
{
|
|
for (int d = 0; d < maxDays * 8; d++)
|
|
{
|
|
if (condition()) return true;
|
|
W.RunTicks(W.Calendar.TicksPerDay / 8);
|
|
}
|
|
return condition();
|
|
}
|
|
|
|
/// <summary>Compra veicoli e compone un treno nel deposito.</summary>
|
|
public int Train(int depot, string loco, int locos, string car, int cars, string name)
|
|
{
|
|
var ids = new List<VehicleId>();
|
|
ids.AddRange(W_Buy(loco, depot, locos));
|
|
if (cars > 0) ids.AddRange(W_Buy(car, depot, cars));
|
|
return Ok(new ComposeTrainCommand(new DepotId(depot), ids, name));
|
|
}
|
|
|
|
/// <summary>Compra veicoli di più tipi e compone un treno nel deposito.</summary>
|
|
public int Train(int depot, string name, params (string Type, int Count)[] vehicles)
|
|
{
|
|
var ids = new List<VehicleId>();
|
|
foreach (var (type, count) in vehicles) ids.AddRange(W_Buy(type, depot, count));
|
|
return Ok(new ComposeTrainCommand(new DepotId(depot), ids, name));
|
|
}
|
|
|
|
private IEnumerable<VehicleId> W_Buy(string type, int depot, int count) =>
|
|
Do(new BuyVehicleCommand(type, new DepotId(depot), count)).Created.Select(i => new VehicleId(i));
|
|
|
|
/// <summary>
|
|
/// Rete merci di Valdoria: stazione delle miniere, stazione dell'acciaieria, deposito e
|
|
/// tracciato per il valico; restituisce (miniera, acciaieria, deposito).
|
|
/// </summary>
|
|
public (int Mine, int Mill, int Depot) BuildFreightNetwork(bool waitForConstruction = true)
|
|
{
|
|
int mine = Ok(new BuildStationCommand(K(2.2, 2.6), 2, "Rocca Bruna"));
|
|
int mill = Ok(new BuildStationCommand(K(10.6, 5.4), 4, "Acciaieria"));
|
|
int depot = Ok(new BuildDepotCommand(K(2.6, 4.4), "small", "Deposito Rocca Bruna"));
|
|
Ok(new BuildTrackCommand(Scenario!.Route("valico", Me).Polyline, AllowTunnels: false));
|
|
Ok(new BuildTrackCommand(new[] { K(2.6, 4.4), K(2.92, 4.95) }));
|
|
if (waitForConstruction)
|
|
Assert.True(RunUntil(() => W.Network.Edges.All(e => e.State == EdgeState.Active), 400), "cantieri completati");
|
|
return (mine, mill, depot);
|
|
}
|
|
}
|