Chessistics/chessistics-engine/Model/BoardSnapshot.cs
Samuel Bouchet 3120d9835e Phase 2: cargo-type aware transfers via CargoFilter
Add CargoFilter property to PieceState, auto-assigned at placement
by tracing relay chain back to production. TransferResolver now
enforces cargo-type filtering and uses forward-direction sorting
with cargo-aware distance calculations. Prevents cross-route
contamination on multi-cargo boards.

Level 3 restored to dual-cargo (Wood+Stone) with correct 10R+2K stock.
Two new solvability tests validate filter auto-assignment and chain
propagation. All 60 tests green.
2026-04-10 15:35:37 +02:00

44 lines
1.8 KiB
C#

namespace Chessistics.Engine.Model;
public class BoardSnapshot
{
public int Width { get; }
public int Height { get; }
public CellType[,] Grid { get; }
public IReadOnlyList<ProductionSnapshot> Productions { get; }
public IReadOnlyList<DemandSnapshot> Demands { get; }
public IReadOnlyList<PieceSnapshot> Pieces { get; }
public SimPhase Phase { get; }
public int TurnNumber { get; }
public IReadOnlyDictionary<PieceKind, int> RemainingStock { get; }
public BoardSnapshot(BoardState state)
{
Width = state.Width;
Height = state.Height;
Phase = state.Phase;
TurnNumber = state.TurnNumber;
// Deep copy grid
Grid = new CellType[Width, Height];
Array.Copy(state.Grid, Grid, state.Grid.Length);
Productions = state.Productions.Values
.Select(p => new ProductionSnapshot(p.Position, p.Name, p.Cargo, p.Interval, state.ProductionBuffers[p.Position]))
.ToList();
Demands = state.Demands.Values
.Select(d => new DemandSnapshot(d.Position, d.Name, d.Cargo, d.Required, d.Deadline, d.ReceivedCount, d.IsSatisfied))
.ToList();
Pieces = state.Pieces
.Select(p => new PieceSnapshot(p.Id, p.Kind, p.StartCell, p.EndCell, p.CurrentCell, p.Cargo, p.CargoFilter, p.SocialStatus))
.ToList();
RemainingStock = new Dictionary<PieceKind, int>(state.RemainingStock);
}
}
public record ProductionSnapshot(Coords Position, string Name, CargoType Cargo, int Interval, CargoType? Buffer);
public record DemandSnapshot(Coords Position, string Name, CargoType Cargo, int Required, int Deadline, int ReceivedCount, bool IsSatisfied);
public record PieceSnapshot(int Id, PieceKind Kind, Coords StartCell, Coords EndCell, Coords CurrentCell, CargoType? Cargo, CargoType? CargoFilter, int SocialStatus);