I have this question since a while now. In a TRPG game like Fire Emblem or Advanced Wars (or even in something simpler like a chess game) with tiles and units, you need to store where each unit is in order to calculate the movement of the units, if there is already another unit within the path or just to display the unit correctly in the world. How do you think is the best way to store all this information?
I can think of a couple ways to do this but I'm sure there is a better way.
The easier way is to store a reference to the unit in the cell. I think this is not optimal cause sometime I'm forced to either go through all cells or have an additional array with the cells that contain an unit. Both of this solutions sound... primitive.
If you store the cell reference in the unit you still need an array with all cells in your map. Also, usually you need to know if a cell contains an unit, so again you have to go through all units to check if a cell contains an unit or not. It seams cheaper this way (since there is less units than cells) but still primitive.
Having the reference in both entities sounds like the cheaper way to access the info you need, but maintaining it is complicated and it looks like weird. I've read on some places that this is the way to do it, but I don't really think it's a good practice.
Maybe the best way is to have another class to do this work by having the reference in both directions and creating the methods you need to retrieve or update both references at the same time. But I'm not sure how...
What do you guys think??
Thanks you!!