I’m making a game and I need to represent a “layered” circle in some clever datastructure.
A circle can have any number of layers. Each layer has a number of “slices”, they can be of different lengths and pieces can be missing. The innermost layer is always a full circle. Each segment has a color, multiple segments with the same color can be next to each other.
circle with layers http://webbfarbror.se/dump/datastructure.gif
Realistically a circle wont have more than about 40 layers or about 1500 individual slices.
I will need to be able to easily find adjacent pieces to a specific piece, see if a piece is “hanging in free air” (imagine gravity towards the center), and to remove pieces leaving a hole in their place.
I’ve already got a few ideas for how to store this, but I thought it was an interesting question so I figured I’d post it here for kicks.
I will be coding this in Actionscript 3.0, but feel free to post ideas in any language.
Just thinking quickly about this, I could see some kind of directed graph with different kind of edges.
Probably something like this
You would have two set nodes, one being the center circle and one representing a ficticious most outter circle.
You can then easily navigate between levels, from neighbourgh to neighbourgh in any direction. To find all the slices which are “in the air”, you can start from the inner or outer node and find any slice that does not have a parent or a child.
The only thing this does not handle is the case where there is two disjunct parts to your layered circle, ie. with a fully missing layer. It could support it though by adding weights on the edges to represent the distance.