Add square grid system, positional combat, sacrifice, and Placement phase

Grid infrastructure (SOR.Game/Grid/):
- Coord — immutable (X,Y) struct with Manhattan distance, adjacency, BFS helpers
- Tile — mutable affinity slots (Base1/Base2) + occupancy tracking
- Board — 8×8 (configurable) grid, PlaceUnit/RemoveUnit/MoveUnit/BuildOccupancyMap
- Pathfinding — Walk/Flight BFS (GetReachableWithCost), Jump/Teleport range (GetJumpRange)
- LineOfSight — supercover DDA; occupied intermediate tiles block LOS
- AffinitySystem — full Resolve table for all 20+ affinities per affinity.md,
  PushAffinity, ApplyPlacementAffinity, IsAffinityValid (basic vs non-basic rules)

Combat (SOR.Game/Combat/):
- AttackSystem — Manhattan range + optional LOS validation (§6.10)
- SacrificeSystem — exact ST return formula from gameplay.md §6.15

Abilities (SOR.Game/Abilities/):
- AbilitySystem stub — future pass per abilities.md

Game engine / state changes:
- GamePhase: added Placement phase (before Draw)
- GameRuleSet + GameRules: added BoardWidth/BoardHeight (default 8×8)
- GameState: added Board, PlayerOneAccountId; CardInstance gains MovementType,
  MaxMp, MinAttackRange, MaxAttackRange, RequiresLos, MinChannelRange,
  MaxChannelRange, IsLeader (moved from FieldCard); FieldCard adds Position + CurrentMp
- [JsonPolymorphic] on CardInstance so FieldCard survives JSONB round-trip
- JsonStringEnumConverter added to GameEngine serializer options
- GameEngine.Initialize: creates Board + sets Placement phase; no opening draw yet
- GameEngine.PlaceArchSpirit: validates row, pushes affinity, triggers opening draw
  and SP gain when both players placed
- GameEngine.ChannelCard (was PlayCard): validates channeling range + affinity for Spirits
- GameEngine.MoveUnit: Walk/Flight BFS, Jump (1 MP/landing), Teleport (LOS + 1 MP)
- GameEngine.Attack: adds range+LOS validation via AttackSystem
- GameEngine.Sacrifice: adjacency + SacrificeSystem ST formula
- GameEngine.EndTurn: now also restores MP (§6.0 step 1) for next player
- ToDto: includes Board tiles with resolved affinities; CardInstanceDto gets Position,
  CurrentMp, MaxMp, MovementType

New handlers: game.place_arch_spirit, game.move_unit, game.sacrifice
Updated handlers: game.play_card (target tile), GameReadyHandler (new Initialize sig)
Migration: AddBoardDimensions (board_width/board_height on game_rule_sets)

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
dingo
2026-02-26 11:22:30 -05:00
co-authored by Claude Happy
parent 7ab11e6f46
commit 9b6b7191f0
27 changed files with 1739 additions and 127 deletions
+70
View File
@@ -0,0 +1,70 @@
namespace SOR.Game.Grid;
/// <summary>
/// Pathfinding algorithms for all four movement types on a square grid.
///
/// Walk / Flight — BFS returning tiles reachable within a given MP budget.
/// Walk: blocked by any occupied tile.
/// Flight: blocked only by tiles occupied by other Flight units.
/// Callers are responsible for building the appropriate blocked set.
///
/// Jump / Teleport — range set: all in-bounds tiles within Manhattan [1..maxMp].
/// Each landing costs exactly 1 MP regardless of distance.
/// Teleport additionally requires LOS — callers filter with LineOfSight.HasLos.
/// </summary>
public static class Pathfinding
{
/// <summary>
/// BFS for Walk/Flight movement.
/// Returns all reachable non-blocked tiles mapped to their step cost.
/// The starting tile is excluded from results (can't "move" to current position).
/// </summary>
public static Dictionary<Coord, int> GetReachableWithCost(
Board board, Coord from, int maxMp, IReadOnlySet<Coord> blocked)
{
var result = new Dictionary<Coord, int>();
var queue = new Queue<(Coord coord, int cost)>();
result[from] = 0;
queue.Enqueue((from, 0));
while (queue.Count > 0)
{
var (current, cost) = queue.Dequeue();
if (cost >= maxMp) continue;
foreach (var neighbor in current.OrthogonalNeighbors())
{
if (!board.IsInBounds(neighbor)) continue;
if (blocked.Contains(neighbor)) continue;
if (result.ContainsKey(neighbor)) continue;
result[neighbor] = cost + 1;
queue.Enqueue((neighbor, cost + 1));
}
}
result.Remove(from);
return result;
}
/// <summary>
/// Jump/Teleport range: all in-bounds tiles within Manhattan distance [minRange..maxMp]
/// from the starting position.
///
/// For Teleport, callers should additionally filter by LineOfSight.HasLos.
/// </summary>
public static IEnumerable<Coord> GetJumpRange(
Board board, Coord from, int minRange, int maxRange)
{
for (int dy = -maxRange; dy <= maxRange; dy++)
for (int dx = -maxRange; dx <= maxRange; dx++)
{
var target = new Coord(from.X + dx, from.Y + dy);
if (!board.IsInBounds(target)) continue;
var dist = from.ManhattanDistance(target);
if (dist < minRange || dist > maxRange) continue;
yield return target;
}
}
}