2026-04-10 14:58:03 +02:00
|
|
|
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));
|
|
|
|
|
|
2026-04-16 21:22:49 +02:00
|
|
|
public static SimHelper FromCampaign(CampaignDef campaign) => new(new GameSim(campaign));
|
|
|
|
|
|
2026-04-10 14:58:03 +02:00
|
|
|
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());
|
|
|
|
|
|
2026-04-16 21:22:49 +02:00
|
|
|
public IReadOnlyList<IWorldEvent> AdvanceMission()
|
|
|
|
|
=> Sim.ProcessCommand(new AdvanceMissionCommand());
|
2026-04-10 14:58:03 +02:00
|
|
|
|
|
|
|
|
public List<IWorldEvent> StepN(int n)
|
|
|
|
|
{
|
|
|
|
|
var allEvents = new List<IWorldEvent>();
|
|
|
|
|
for (int i = 0; i < n; i++)
|
2026-04-16 21:22:49 +02:00
|
|
|
{
|
|
|
|
|
var events = Step();
|
|
|
|
|
allEvents.AddRange(events);
|
|
|
|
|
// Stop stepping if simulation halted (last mission complete)
|
|
|
|
|
if (Snapshot.Phase == SimPhase.MissionComplete)
|
|
|
|
|
break;
|
|
|
|
|
}
|
2026-04-10 14:58:03 +02:00
|
|
|
return allEvents;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public BoardSnapshot Snapshot => Sim.GetSnapshot();
|
|
|
|
|
}
|