I have a two dimensional grid of cells. In this simulation, cells may request to switch position with another cell. The request also has a priority.
The problem is that Im having a hard time coming up with a good way to structure this. If A wants to switch with B, and B also wants to switch with A, they currently can be switched and switched back in a single logic tick (which should be impossible).
The solution probably involves making sure (A to B)==(B to A) and insertion sorting them into a list by their priority.
Does such data structure have a name? Anyone recognise the problem and can provide some good links for reading?
I can’t say that I’ve come across an example like this before, so I don’t know what it would be called, but perhaps something like this would work…
Cell – a class or struct
SwitchRequest – a class or struct
SwitchRequests – an array of SwitchRequests
AlreadySwitchedCells – an array of Cells
Algorithm
For each tick:
Note: There are some options here, like whether you should make the coordinates properties of a Cell or just store the CellIds in an two-dimensional array, but hopefully this gives you a starting point.