Background
I'm trying to write some modular style code in Maya (it's in 3D, but I'm doing it in a 2D style for now), where you make an object, and with each side (x,y,-x,-y), define a connector. There can be multiple connectors per side, and multiple sides/objects per connector. These also have a chance value, both on the connector and object, to determine how frequently they will be generated.
If I can eventually manage, I'll have it able to generate it's own content, so in a way this is more of the backbone of the project. Here is a quick example I've drawn up from a top down view, it has the object names and connector names shown so you can see the way I've designed it to work, currently in a tile based way - https://i.stack.imgur.com/actrW.png
Problem
I got the basic part of the selection code working, where it'll take an object, look up all connectors, pick one, look up all objects with matching connectors, and pick one, to have a seamless transition. However, I realised this is only useful for connecting to a single block, and it'd cause problems if you had any more, and that having more makes it a whole lot more complicated.
So, if there is 1 adjacent block, all that needs to be done is pick an side. If 'x' is chosen, just say that is connected to 'connector1', the code searches 'connector1' for all objects using it, chooses one, and places it in the correct place.
Now, if there are 2 adjancent blocks, it needs to find something that matches both connectors either side. If the sides are 'x' and 'y', and the connectors are 'xconnector' and 'yconnector', it needs to search for any block that uses both 'xconnector' and 'yconnector' with the two sides next to each other, meaning it could be xy, -xy, x-y, -x-y, either normal or mirrored, so there are 8 possible matching combinations.
However, it could be a lot more complicated, especially with 3 or 4 adjacent blocks, so I need to write something that would handle any value thrown at it
So basically, I hope I've explained it well enough, but it has gone slightly over my head so I could do with a little help if anyone has any idea about it :)
If it will help, here are sections of my current code, an example stored list is in the bottom link:
Add/remove object to list: http://pastebin.com/tX5rVLMi
Choose connected edge (works with 1 side): http://pastebin.com/gwDpZV8c
Output stored objects (for knowing what's going on): http://pastebin.com/dQD1i3XU