Problem
HexBoard.hex_route() performs a breadth-first search, then reconstructs the route by taking the first neighboring cell whose distance is n - 1. When several equally short predecessors exist, the fixed direction order makes the selected geometry arbitrary and dependent on which terminal is passed as the source.
This appeared while routing the four td2f serial signals. Routing DTR from GPIO12 to the header selected a shortest path that blocked a later signal. Calling the same route with its endpoints reversed selected another equally short DTR path and allowed DTR, RX, TX, and RTS all to route. Copper is electrically directionless, so argument order should ideally have less influence on route quality.
Proposed heuristic
During backtracking, collect all neighboring cells whose distance is n - 1 and rank them by:
- Greater local clearance, initially the number of unblocked cells among the six hex neighbors.
- Optionally, distance from existing copper and keepouts using a clearance/distance field.
- Continuing in the current direction to avoid unnecessary turns.
- A stable coordinate tie-breaker so builds remain deterministic.
The clearance score must use the original board blockage map (self.blocked[layer]). The local blocked array used by the breadth-first search has been mutated to mark every visited cell and cannot measure physical openness.
Tests / acceptance criteria
- Add a small synthetic grid test with multiple equal-length paths and verify that the route chooses the higher-clearance path.
- Verify deterministic output across repeated builds.
- Check whether swapping source and target produces equivalent or at least equally useful geometry.
- Use td2f's DTR/RX/TX/RTS routing as a regression case; ideally all four should route without requiring the DTR call to be reversed.
- Confirm existing board output invariants where applicable.
This is still a local greedy heuristic; global congestion handling or rip-up/reroute would be a separate enhancement.
Problem
HexBoard.hex_route()performs a breadth-first search, then reconstructs the route by taking the first neighboring cell whose distance isn - 1. When several equally short predecessors exist, the fixed direction order makes the selected geometry arbitrary and dependent on which terminal is passed as the source.This appeared while routing the four td2f serial signals. Routing DTR from GPIO12 to the header selected a shortest path that blocked a later signal. Calling the same route with its endpoints reversed selected another equally short DTR path and allowed DTR, RX, TX, and RTS all to route. Copper is electrically directionless, so argument order should ideally have less influence on route quality.
Proposed heuristic
During backtracking, collect all neighboring cells whose distance is
n - 1and rank them by:The clearance score must use the original board blockage map (
self.blocked[layer]). The localblockedarray used by the breadth-first search has been mutated to mark every visited cell and cannot measure physical openness.Tests / acceptance criteria
This is still a local greedy heuristic; global congestion handling or rip-up/reroute would be a separate enhancement.