Chessistics/chessistics-tests/Helpers/SimHelper.cs
Samuel Bouchet 2d1aea0a7a Snapshot campaign system progress before automation harness
Bundles in-flight work on the campaign/missions system (CampaignDef,
MissionDef, TerrainPatch, TransformerDef, MissionChecker, CampaignLoader,
FlavorBanner, transformer rules), plan files, and matching tests. Baseline
commit so the upcoming automation testing harness lands on a clean tree.
2026-04-16 21:22:49 +02:00

54 lines
1.8 KiB
C#

using Chessistics.Engine.Commands;
using Chessistics.Engine.Events;
using Chessistics.Engine.Model;
using Chessistics.Engine.Simulation;
namespace Chessistics.Tests.Helpers;
public class SimHelper
{
public GameSim Sim { get; }
private SimHelper(GameSim sim) => Sim = sim;
public static SimHelper FromLevel(LevelDef level) => new(new GameSim(level));
public static SimHelper FromCampaign(CampaignDef campaign) => new(new GameSim(campaign));
public IReadOnlyList<IWorldEvent> Place(PieceKind kind, Coords start, Coords end)
=> Sim.ProcessCommand(new PlacePieceCommand(kind, start, end));
public IReadOnlyList<IWorldEvent> Place(PieceKind kind, (int col, int row) start, (int col, int row) end)
=> Place(kind, new Coords(start.col, start.row), new Coords(end.col, end.row));
public IReadOnlyList<IWorldEvent> Remove(int pieceId)
=> Sim.ProcessCommand(new RemovePieceCommand(pieceId));
public IReadOnlyList<IWorldEvent> Step()
=> Sim.ProcessCommand(new StepSimulationCommand());
public IReadOnlyList<IWorldEvent> Pause()
=> Sim.ProcessCommand(new PauseSimulationCommand());
public IReadOnlyList<IWorldEvent> Resume()
=> Sim.ProcessCommand(new ResumeSimulationCommand());
public IReadOnlyList<IWorldEvent> AdvanceMission()
=> Sim.ProcessCommand(new AdvanceMissionCommand());
public List<IWorldEvent> StepN(int n)
{
var allEvents = new List<IWorldEvent>();
for (int i = 0; i < n; i++)
{
var events = Step();
allEvents.AddRange(events);
// Stop stepping if simulation halted (last mission complete)
if (Snapshot.Phase == SimPhase.MissionComplete)
break;
}
return allEvents;
}
public BoardSnapshot Snapshot => Sim.GetSnapshot();
}