Gameplay Graph Implemented
I’ve successfully implemented the gameplay graph this week, which has been harder than I thought it would be but I’m relatively happy with the result.
The above is a visualization of an example graph generated by my algorithm. The gray squares are nodes of the graph, and lines denote child/parent relationships. As you can see, translating this to a spatial world shouldn’t be too hard, as I’m essentially going to be putting corridors between connected rooms and laying them out in the above order (minus the top-down tree structure, of course).
I’m not completely happy with the results, as sometimes using random elements in the graph generation can lead to undesirable results, as seen above. The above gameplay graph has what I call a one-sided graph; that is, the right side is much, much longer than the left side from the spawn node (14 vs 2 rooms).
This one is even worse, with the right side having 47 rooms while the other two “sides” having a cumulative sum of 6 rooms. This can be attributed to the probability space I assign to determining how many child rooms a node should have: once a node is two or more rooms away from the spawn node (the top one), it uses a probability distribution of [ .7, .1, .1, .1 ] that is associated with [ 0, 1, 2, 3 ] child rooms. The problem with this is that it’s still too easy for a branch of rooms to exponentially grow with the 10% of generating three child rooms, which all have a 30% each of having their own child rooms, so on and so forth. I need to have the probability space change to favor 0 child rooms more, but alas, my attempts to do so have been rough at best.
Additionally, the total number of rooms differs a lot, as it can be anywhere from 4 to 60 rooms realistically speaking, and 1 to an infinite number theoretically speaking. I need to write a post-generation script that checks the graph for a couple of constraints, like maybe being between 10 and 20 rooms, and having relatively well distributed branches of rooms. If the graph fails to meet the conditions, I’ll just run the algorithm again.
But at any rate, now that I have the gameplay graph algorithm, its time to write a script that can convert the graph to an actual combination of Rooms. Thankfully I’ve already created what I believe is a pretty modular Room system, so I’ll just need to write a corridor-creation algorithm and add some code for randomly generating the enemies, size, and obstacles in a Room and I’ll be set.