Hi guys, im making a small game in java where i have these sorts of overlays (e.g. a unit is clicked and it shows an overlay of reachable tiles based on the units movement points, or a city is clicked and it shows the supply range). I have attached an image of what i mean by "overlay" (where the reachable tiles are shaded light gray and the unreachable ones are dark gray).
I have an issue where i have these different types of overlays to compute, and the traversal logic is very similar, but there have to be little changes inside the traversal based on what overlay i'm computing.
Currently, the traversal computes a Hashmap of reachable tiles and their costs, as well as a Hashmap called parent which allows rebuilding the shortest path to a reachable tile. As far as im aware, all the overlays should have at least these two.
However, the traversal for unit movement does something custom where it excludes hexes from the reachable hashmap if they have an enemy unit on them, and instead add them to an attackable hashmap. The issue is that this happens right in the middle of the traversal, and it is also not something that is needed when calculating a traversal for, e.g., supply range.
My question is, how would it be best to extract the core traversal to be reusable and not need to rewrite it each time, while also accounting for the quirks that the different types of overlays require?