I've recently started working on a turn based strategy game much like games from the Fire Emblem or Final Fantasy Tactics series. However, I'm running into a few problems concerning the storage of the tile data and unit data. For example, just like in Fire Emblem I want to show all possible movement when you click on one of the units. Here is an image showing what I mean.
In this image the possible fields to move to have been indicated with a blue color. Fields that are in range for an attack have been indicated with the red color. Normally the tile the enemy unit is on would be in range to move to, however since there is someone standing on the tile the game has recognized that you can't move there.
I understand the need for an algorithm like Breadth-First Traversal to find out all possible fields to move to, but I'm unsure how to exclude fields occupied by an enemy. In order to avoid circular dependencies between fields and units I only store a reference to field in the unit class and not the other way around. So when I work my way through the fields to check all possible moves, how do I best find out if that field is actually valid?
I could of course just loop through the list of all enemies for each field that I process to see if it's occupied. Another way to potentially solve it would be to loop through the list of possible fields and removing fields occupied by enemies from that list, but I think that wouldn't work properly because occupied fields can also have the effect that empty fields around them are no longer reachable (due to the enemy blocking access to them). The easiest way to solve it would be to also store a reference to the unit within the field class. This would of course introduce a circular dependency.
I feel like there should be a much better solution than the ones I can think of, but I just can't figure it out.
Thanks in advance!