Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 25 Mar 2012
Offline Last Active Apr 25 2012 03:25 PM

Topics I've Started

Efficient data structure for a maze

28 March 2012 - 10:48 AM

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...)