I have an AI bot (agent) that needs to make intelligent decisions in a survival scenario (hypothetical). I want the bot to choose from a range of options that is somewhat random and somewhat intelligent. I squiggled a tree of possible behaviours my bot can perform
Sorry for all the words but here is how to read it:
Workflow:
- Start at the root node and immediately examine it's children
- Determine child randomly based on priority stored with each child
(find shelther = 4/12 = 33% chance)
(gather resources = 3/12 = 25% chance)
(socialise = 1/12 = 8% chance)
- If randomly chosen child is a leaf then search is over and that action is executed
- If randomly chosen child is not a leaf (e.g. gather resources) then examine all children for this new node
- Determine child randomly based on priority stored with each child
(clay = 2/5 = 40% chance)
- Randomly chosen child is a leaf (e.g. gather wood) so execute action
Long story short - I want a tree where I can insert nodes and give them a nominal priority. The priority only makes sense in the context of the nodes siblings and the priority is a simple mechanism to "weight" or favour some behaviors over others.
Furthermore, some nodes can be 'deconstructed' into more nodes of that same type and a different priority applies in that new context. In the diagram above, the bot has some chance of "singing" but it really isn't very high (1/12 * 1/4 = 1/48 = 2% chance) but every now and then, when you least expect it, that agent will start yodeling. I can also quickly adjust the priority of one node without upsetting the tree or recalculating percentages. Changing "socialise" to two (2) means singing is now 4% chance of being randomly chosen.
I can also add new leaf and sub-trees as I dream up new behaviors and the tree will simply cope.
Anyway. Lots of words. I'm going to assume I'm the first person to invent this device so I'll name it the "weighted Fox tree".
Obvious flaws? Design faults? Anything I overlooked?
If it looks sound then I guess I need to write "tree" code to make this work. I guess each node will be a table and that table can hold another table (which is a node). I can add a new child node with a simple table.insert(node, sub-node) I guess (or something).