I basically need to sort of create a room generation but with jenga blocks. Each jenga block specifically designed to have stations, entrances that allow to to other blocks or just go out of and fall down. (All blocks are hollow)
First of all, A+ question in terms of info provided.
Your requirement that every block be reachable is simple to check, but you can make decisions to affect how hard it is to actually generate a tower with this property. To check it:
Take a random block and put in the “Reachable” list.
Check each block that is connected to this block via an entrace, make sure it is not already in Reachable, then add it to Reachable.
If you added the block, repeat the above check for its entrances (recursive step)
Repeat this until you’ve checked all entrances to the first chosen block
If the Reachable list has all the same elements as the full list of blocks, every block is reachable.
You may find that a good way to ensure a valid tower can always be generated with all the required special blocks is to let it keep growing until those conditions are met. This affects your height requirement.
For welding, you can just weld everything to the platform, unless you want the welds to be realistic for some other reason, such as having a block fall if it is no longer supported.
Ensuring that a valid tower is always possible for a set of constraints (set of special blocks, where they are placed, forced types of blocks) may be really easy or really hard. It would be quite hard to answer, so your best bet is to just try it once you’re able and see how often it fails.
As for actually coding this, I think its a good idea to separate it into different components:
A component to choose blocks, which is random but affected by height and which special blocks are left to place.
A componentfor placing a block. It will have the possibility of failing, so it needs a way to return that failure so a different block can be picked.
A component for placing groups of blocks. Layers seem like a good way of organizing this for several reasons. You can rule out certain placements early if its obvious they will result in an invalid tower. E.g. a layer with no entrances on top or no entrances on the bottom will make some part of the tower unreachable.
The smaller of a group you choose, the simpler the placement problem becomes, but the less convoluted the resulting maps can be, which might not be acceptable for gameplay reasons. If you use single layers as your group of blocks, then the path from bottom to top is guaranteed to have a no-backtracking path. If you generate 3 layers at a time, then backtracking routes can exist up to 3 layers deep.
There are small little structures found in the blocks however. Adding these in naturally + having a max and minimum amount each can occur in one full end result is something of its own issue because there are also bottom entrances and you cannot put these against a wall which isn’t exactly a wall but another entrance
Well does a place for a station depend on anything other than the entrances in that block? If not, then you can count the number of station locations as soon as the entrances for a set of blocks are decided.
My suggestio: make all variable block (1-6 entrance) which front face always the entrance one, from there entrancr generate a block(make it face to the last block). And one the last block having above 2 entrane the loop will running