Move Planning¶
planMove¶
planMove(PhysicalBoard& board, const PhysicalMove& move) — Function
Parameters: board – current physical board state (will be read but not permanently modified); move – the physical chess move to plan
Returns: MovePlan – complete execution plan
This is the primary entry point for the board interpreter. It orchestrates all sub-systems to produce the complete MovePlan. The board parameter is passed by reference to allow temporary mutation during planning via a local copy; the original is not modified.
Planning Algorithm¶
Generate candidate paths for the primary piece by calling
generatePath(move).Select the best path using
selectBestPath, which minimises the number of blockers.Identify all blockers on the chosen path using
findBlockers. Intermediate squares only; the destination is excluded.Build the exclusion set containing every square on the primary path and the primary piece’s source square.
Copy the board into
tempBoard. All subsequent mutations happen on this copy.Plan blocker relocations: for each blocker call
planBlockerRelocation, which recursively handles secondary blockers and appendsRelocationPlanentries toplan.relocations.Apply the primary move to
tempBoardso the restored post-move board state is available for restoration path planning.Plan restorations: iterate over
relocationsin reverse order (LIFO). For each relocation, callfindClearPathfrom the parking spot back to the piece’s original square. During execution, the gantry follows this restoration path when it exists; if no clear path exists, the path is left empty and the gantry controller falls back to a direct move.Mark the plan valid and return.
Error Handling¶
MovePlan.isValid is set to false and MovePlan.errorMessage is populated in the following failure cases:
Condition |
Error Message |
|---|---|
No paths generated for piece type |
|
|
|
Blocker cannot be relocated |
|
MovePlan failure modes
Warning
If planMove returns an invalid plan, the gantry controller must not attempt to execute it. The game controller layer is responsible for checking MovePlan.isValid before dispatching commands.