idea generator - adQuid/DecentAI GitHub Wiki

A strategy game could, in theory, have nearly infinite, nearly identical, possible actions available for a player to do, and even if not Decent AI still would not know what actions exist in your game. To solve this problem the developer is required to implement IdeaGenerator, which spitballs sets of actions that seem reasonable for the AI to try out.

In an effort to reduce the complexity of all possible courses of action down to something that can be calculated in a reasonable period of time, DecentAI uses "iterations" of lists of actions. Each iteration is like a layer of actions, tested independently for positive effects, then either rejected or layered on and considered set in stone afterwards. The AIBrain will continue to try new actions for as long as hasFurtherIdeas() returns true, and will provide the current iteration to both that method and the method call to generate ideas. For each such iteration, the IdeaGenerator is called on to return a list of lists of actions. Out of these, the AI will select the best list of actions to add as the next iteration.

At the time of writing, IdeaGenerator writing is an art form that has only been practiced twice, but here are some things to keep in mind:

  • Be optimistic. The whole point of Decent AI is to weed out bad ideas, so include all actions that make any sense unless you are starting to see computation times take too long. The AI may come up with ideas that surprise you.

  • The IdeaGenerator is a good place to put in any fixed sequences or "manners" that don't change much based on context. If you would never take off with a plane without putting fuel in it that same turn, simply always pair those two actions together here, saving computation time and preventing bots from doing strange behaviors.

  • The list of actions returned by an individual iteration should be an atomic "move", with minimal connection to actions taken in previous iterations in the turn. In the Medciv game, for example, the provided generator returns sets of actions specific to each animal owned by a player, since milking an animal and feeding it are likely to go together, rather than providing a set of actions to milk every animal, and one to tend to every animal. The latter runs a risk of forcing the AI to make strange compromises because it couldn't, for example, choose to just feed and milk more valuable livestock when the player can't care for them all, since feeding one cow means feeding all of them. It would be possible to be even more granular, splitting out the tending and feeding of each animal, but at a steep cost in calculation time that would be noticeable in a full sized game.

⚠️ **GitHub.com Fallback** ⚠️