I have a 2d grid level. It infinitely grows. If it was not of infinite size, a 2D array would be perfect, as I need to constantly have each grid talk to its neighbors.
For example, with a 2D array, I can talk to its top neighbor by saying
var topNeighbor = myGrid[x,y+1];
But if I were to use a List, the indices would be changing.
If I just store a list of all grid separately and then iterate through them for each grid, thats an n^2 algorithm running each frame. Each room would have to iterate through every other room just to ask if they were neighbors.
What is the best way to store a 2D grid of an unknown size, assuming each grid needs to talk to its 4 neighboring grids every frame?