Hello hello!
Looking for some general advice or guidance for a small problem I am having, I would appreciate any help.
It's basically about trying to implement a robust decision making process for a group of things, which try and act on other things, and intermittently one group of things go in to 'stasis' temporarily (not acting) to disappear if they are not re-activated quick enough - and the other things (the things they are acting on) also disappear occasionally. Essentially the groups of entities are often changing 'classification' and therefore the rules they are subject to also change.
Basically, it's a group of 'heroes' going to 'dungeons'.
I'm coming across bugs which are related to this 'reclassification' of either entity, and due to the way I have the code structured it is very difficult for me to debug 'why' and 'where' these problems are introduced.
What I don't really want to do, at this stage, is retain my current code - introducing a manual checkpoint at every single decision where I can see it going wrong (which is only occasional, but inevitable):
i.e.
Everytime I ask a hero to do something, check if the hero is dead, for every new possible action.
Everytime a hero acts on a dungeon in any way, check if the dungeon actually exists.
What I want to do is completely rewrite the code, creating many more functions covering discrete actions, limiting the ways in which the actions can relate to each other, minimising 'entry points' to functions and therefore hopefully making the system far more robust to the future introduction of new actions.
At the minute it just steps through a few hundred lines of code, calling the occasional function as necessary - which was easy enough to create and is understandable to me reading it back. But it is entered through various different ways, and it is obvious that it is not working IN ALL CASES as errors get thrown up after heroes dying, dungeons disappearing, heroes moving on to different lists etc. - and still getting acted upon - presumably because my 'status-checking' is not robust enough and allows certain actions to be happening when I think they shouldn't.
So the question is, are there any good examples of an existing system that would allow all the above to happen? Any ideas for creating decision trees for sets of entities etc. that may change classification regularly within the code?
My main gripe with introducing thousands* of "if I shouldn't be doing this, don't" checks, is because most of the time I don't actually believe I should be doing this (or fully understand the reason - because I don't fully understand the path the code is going through), and therefore I doubt by doing this I am making the code more robust.
*hyperbole
Thanks for any ideas,
Cheers.
mendonca