I'm implementing a bubble-witch-like game (http://www.king.com/games/puzzle-games/bubble-witch/), and I was thinking on what's the better way to store the "bubbles" and to work with. I thought of using graphs, but that might be too complex for a trivial thing. Thought of a matrix, just like a tile map, but that might get too 'workaroundy'. I don't know.

I'll be doing in Flash/AS3, though.

Thanks. :)


1 Answer 1


You may not want to use a graph, but ultimately the problem is one of planar 6-connectedness. I challenge you to find a simpler and better-suited structure than a graph for this :) I wouldn't be intimidated by the data structure for this -- when you consider how trivial the implementation will be, it's not like you'd be writing Boost Graph Library all over again.

class Bubble
   private static const NEIGHBOUR_TOP_LEFT:int = 0;
   private static const NEIGHBOUR_TOP_RIGHT:int = 1;
   private static const NEIGHBOUR_RIGHT:int = 2;

   var neighbours:Array = [];

...That's your graph data structure.

As for algorithms, in your main class, run through a loop that arrays them according to their connectivity. And when a player shot collides with the rest, join it at the closest grid position, and then walk all neighbours in the connected graph that match the player shot colour, adding these to a list to "pop", and disallowing walks over neighbours that are already in that list (prevents infinite loops from walking cycles of nodes).

  • \$\begingroup\$ Hmm, nice! Simple and easy. It's already working. Thanks. :) \$\endgroup\$
    – CrociDB
    Nov 14, 2011 at 19:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .