Chessistics/chessistics-tests/Rules/CollisionResolverTests.cs
Samuel Bouchet a7280b1a5a Overhaul turn mechanics, collision destruction, and visual animations
- New turn order: produce -> transfer -> move -> collision resolution
- Collisions now destroy weaker pieces (status > level > mutual destruction)
  instead of halting the simulation. SimPhase.Collision removed.
- Add piece Level property (all level 1 in proto, prepared for future)
- Production fires every turn (interval concept removed), buffer = Amount
  (default 1, future 2-4), leftovers overwritten each turn
- Transfer tiebreaker: status > level > clockwise direction (alternating
  even/odd turns in y-up coords), replaces distance-to-production
- Demands always accept matching cargo even when already satisfied
- TurnNumber added to all turn events for animation grouping
- Simultaneous animations: produce flash, cargo slide, parallel piece moves
- Camera centering fix + middle-click pan
- GDD updated with new rules + lore section added

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 21:44:12 +02:00

87 lines
3.2 KiB
C#

using Chessistics.Engine.Model;
using Chessistics.Engine.Rules;
using Xunit;
namespace Chessistics.Tests.Rules;
public class CollisionResolverTests
{
[Fact]
public void NoCollision_PiecesOnDifferentCells()
{
var pieces = new List<PieceState>
{
new(1, PieceKind.Rook, new Coords(0, 0), new Coords(1, 0), 0) { CurrentCell = new Coords(0, 0) },
new(2, PieceKind.Rook, new Coords(2, 0), new Coords(3, 0), 1) { CurrentCell = new Coords(2, 0) }
};
var results = CollisionResolver.ResolveCollisions(pieces);
Assert.Empty(results);
}
[Fact]
public void HigherStatus_Survives()
{
var cell = new Coords(1, 0);
var rook = new PieceState(1, PieceKind.Rook, new Coords(0, 0), cell, 0) { CurrentCell = cell };
var knight = new PieceState(2, PieceKind.Knight, new Coords(2, 0), cell, 1) { CurrentCell = cell };
var pieces = new List<PieceState> { rook, knight };
var results = CollisionResolver.ResolveCollisions(pieces);
Assert.Single(results);
var (survivor, destroyed, resultCell) = results[0];
Assert.Equal(rook, survivor);
Assert.Single(destroyed);
Assert.Equal(knight, destroyed[0]);
Assert.Equal(cell, resultCell);
}
[Fact]
public void SameStatusAndLevel_MutualDestruction()
{
var cell = new Coords(1, 0);
var pieces = new List<PieceState>
{
new(1, PieceKind.Knight, new Coords(0, 0), cell, 0) { CurrentCell = cell },
new(2, PieceKind.Bishop, new Coords(2, 0), cell, 1) { CurrentCell = cell }
};
var results = CollisionResolver.ResolveCollisions(pieces);
Assert.Single(results);
var (survivor, destroyed, _) = results[0];
Assert.Null(survivor);
Assert.Equal(2, destroyed.Count);
}
[Fact]
public void HigherLevel_SurvivesWhenSameStatus()
{
var cell = new Coords(1, 0);
var knightL2 = new PieceState(1, PieceKind.Knight, new Coords(0, 0), cell, 0, level: 2) { CurrentCell = cell };
var knightL1 = new PieceState(2, PieceKind.Knight, new Coords(2, 0), cell, 1, level: 1) { CurrentCell = cell };
var pieces = new List<PieceState> { knightL1, knightL2 };
var results = CollisionResolver.ResolveCollisions(pieces);
Assert.Single(results);
var (survivor, destroyed, _) = results[0];
Assert.Equal(knightL2, survivor);
Assert.Single(destroyed);
Assert.Equal(knightL1, destroyed[0]);
}
[Fact]
public void ThreePieces_StrongestSurvives_OthersDestroyed()
{
var cell = new Coords(1, 0);
var rook = new PieceState(1, PieceKind.Rook, new Coords(0, 0), cell, 0) { CurrentCell = cell };
var bishop = new PieceState(2, PieceKind.Bishop, new Coords(2, 0), cell, 1) { CurrentCell = cell };
var knight = new PieceState(3, PieceKind.Knight, new Coords(3, 0), cell, 2) { CurrentCell = cell };
var pieces = new List<PieceState> { rook, bishop, knight };
var results = CollisionResolver.ResolveCollisions(pieces);
Assert.Single(results);
var (survivor, destroyed, _) = results[0];
Assert.Equal(rook, survivor);
Assert.Equal(2, destroyed.Count);
}
}