I'm building a simple 2D maze game using pygame. I'm not sure what would be the best data structure to represent the maze itself.
So far I'm using 2 classes, Cell and Grid. The Grid class is a 2D array of Cells. Each Cell contains 4 variables: w_n w_s w_e w_w, which are boolean flags indicating whether there is a wall in that direction.
One problem I can see is that each wall is stored twice e.g. one Cell with w_e set true requires a neighbour with w_w set true. This makes setting the walls up inefficient as when I remove a wall in one cell I have to remove it in its neighbour's as well.
Is there a better way to represent the maze? (I'm sure there is...)
flembobsMember Since 25 Mar 2012
Offline Last Active Apr 25 2012 03:25 PM