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.
112 lines
4.2 KiB
C#
112 lines
4.2 KiB
C#
using Chessistics.Engine.Model;
|
|
using Xunit;
|
|
|
|
namespace Chessistics.Tests.Model;
|
|
|
|
public class TerrainPatchTests
|
|
{
|
|
[Fact]
|
|
public void TerrainPatch_DemandOverwritesProduction_ClearsProduction()
|
|
{
|
|
// Setup: board with a production at (2,0)
|
|
var state = BoardState.FromCampaign(new CampaignDef
|
|
{
|
|
Name = "Test", InitialWidth = 4, InitialHeight = 1,
|
|
Missions = [new MissionDef
|
|
{
|
|
Id = 1, Name = "M1",
|
|
TerrainPatch = new TerrainPatch
|
|
{
|
|
NewWidth = 4, NewHeight = 1,
|
|
Cells = [new PatchCell { Col = 2, Row = 0, Type = CellType.Production,
|
|
Production = new ProductionDef(new Coords(2, 0), "Prod", CargoType.Wood, 4) }]
|
|
},
|
|
Stock = []
|
|
}]
|
|
});
|
|
|
|
// Apply mission 0 terrain
|
|
state.ApplyTerrainPatch(state.Campaign!.CurrentMission.TerrainPatch, 0);
|
|
Assert.True(state.Productions.ContainsKey(new Coords(2, 0)));
|
|
|
|
// Now overwrite with a demand at same position
|
|
var patch = new TerrainPatch
|
|
{
|
|
NewWidth = 4, NewHeight = 1,
|
|
Cells = [new PatchCell { Col = 2, Row = 0, Type = CellType.Demand,
|
|
Demand = new DemandDef(new Coords(2, 0), "Demand", CargoType.Wood, 2) }]
|
|
};
|
|
state.ApplyTerrainPatch(patch, 1);
|
|
|
|
// Production should be gone, demand should exist
|
|
Assert.False(state.Productions.ContainsKey(new Coords(2, 0)));
|
|
Assert.True(state.Demands.ContainsKey(new Coords(2, 0)));
|
|
Assert.Equal(CellType.Demand, state.GetCell(new Coords(2, 0)));
|
|
}
|
|
|
|
[Fact]
|
|
public void TerrainPatch_WallRemovesPiecesOnCell()
|
|
{
|
|
var state = BoardState.FromCampaign(new CampaignDef
|
|
{
|
|
Name = "Test", InitialWidth = 4, InitialHeight = 2,
|
|
Missions = [new MissionDef
|
|
{
|
|
Id = 1, Name = "M1",
|
|
TerrainPatch = new TerrainPatch { NewWidth = 4, NewHeight = 2, Cells = [] },
|
|
Stock = [new PieceStock(PieceKind.Rook, 2)]
|
|
}]
|
|
});
|
|
state.ApplyTerrainPatch(state.Campaign!.CurrentMission.TerrainPatch, 0);
|
|
state.AddStock(state.Campaign.CurrentMission.Stock);
|
|
|
|
// Place a piece with start=(2,0), end=(3,0)
|
|
state.Pieces.Add(new PieceState(1, PieceKind.Rook, new Coords(2, 0), new Coords(3, 0), 1));
|
|
state.RemainingStock[PieceKind.Rook] = 1;
|
|
|
|
// Apply wall on (2,0) — should remove the piece
|
|
var patch = new TerrainPatch
|
|
{
|
|
NewWidth = 4, NewHeight = 2,
|
|
Cells = [new PatchCell { Col = 2, Row = 0, Type = CellType.Wall }]
|
|
};
|
|
state.ApplyTerrainPatch(patch, 1);
|
|
|
|
Assert.Empty(state.Pieces);
|
|
Assert.Equal(2, state.RemainingStock[PieceKind.Rook]); // returned to stock
|
|
}
|
|
|
|
[Fact]
|
|
public void TerrainPatch_ProductionOverwritesDemand_ClearsDemand()
|
|
{
|
|
var state = BoardState.FromCampaign(new CampaignDef
|
|
{
|
|
Name = "Test", InitialWidth = 4, InitialHeight = 1,
|
|
Missions = [new MissionDef
|
|
{
|
|
Id = 1, Name = "M1",
|
|
TerrainPatch = new TerrainPatch
|
|
{
|
|
NewWidth = 4, NewHeight = 1,
|
|
Cells = [new PatchCell { Col = 1, Row = 0, Type = CellType.Demand,
|
|
Demand = new DemandDef(new Coords(1, 0), "D", CargoType.Wood, 2) }]
|
|
},
|
|
Stock = []
|
|
}]
|
|
});
|
|
state.ApplyTerrainPatch(state.Campaign!.CurrentMission.TerrainPatch, 0);
|
|
Assert.True(state.Demands.ContainsKey(new Coords(1, 0)));
|
|
|
|
// Overwrite with production
|
|
var patch = new TerrainPatch
|
|
{
|
|
NewWidth = 4, NewHeight = 1,
|
|
Cells = [new PatchCell { Col = 1, Row = 0, Type = CellType.Production,
|
|
Production = new ProductionDef(new Coords(1, 0), "P", CargoType.Stone, 4) }]
|
|
};
|
|
state.ApplyTerrainPatch(patch, 1);
|
|
|
|
Assert.False(state.Demands.ContainsKey(new Coords(1, 0)));
|
|
Assert.True(state.Productions.ContainsKey(new Coords(1, 0)));
|
|
}
|
|
}
|