- uses *O(1) memory* - requires *no preprocessing* - handles *arbitrary obstacle maps* - and finishes in under 0.1ms even on large grids (e.g. 16,000×16,000 from bottom-left to top-right)
It works without BFS, DFS, A, or flood fill. The core idea is a hybrid of greedy movement toward the goal and robust outline-following (wall tracing) that switches direction when needed and detects loops to ensure correctness.
The algorithm is fully deterministic and guarantees correctness for any map and any pair of walkable start/end points.
My motivation: I want to make traditional flood fill obsolete for any project that uses it purely for reachability checks. In many real-time systems (like games), a full BFS/DFS or even region-preprocessing is overkill when you just need to answer: “Can I reach tile B from tile A?”*
Here’s the Swift version of the main logic
https://github.com/MatthiasGibis/2D-Grid-Reachability-Check/blob/main/mgReachabilityCheckGibis.swift
A variant that considers *height differences* is also available.
https://github.com/MatthiasGibis/2D-Grid-Reachability-Check/blob/main/mgReachabilityCheckGibisWithHeight.swift
1 comments