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 Place(PieceKind kind, Coords start, Coords end) => Sim.ProcessCommand(new PlacePieceCommand(kind, start, end)); public IReadOnlyList 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 Remove(int pieceId) => Sim.ProcessCommand(new RemovePieceCommand(pieceId)); public IReadOnlyList Step() => Sim.ProcessCommand(new StepSimulationCommand()); public IReadOnlyList Pause() => Sim.ProcessCommand(new PauseSimulationCommand()); public IReadOnlyList Resume() => Sim.ProcessCommand(new ResumeSimulationCommand()); public IReadOnlyList AdvanceMission() => Sim.ProcessCommand(new AdvanceMissionCommand()); public List StepN(int n) { var allEvents = new List(); 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(); }