We can now finally focus on creating the individual AI, using each of the pre-existing mechanics to replicate individual personalities and decision-making abilities.
As a disclaimer, this project was created in Unity rather than Python or Unreal simply due to my level of comfort and if approached on a much larger scale, much like
my upcoming thesis, might be worth reconsidering the Engine.
When designing and later implementing AI, it's important that each action remains distinct and clear for the player observing, certain avenues and shortcuts being required to
maintain each player's magic circle and create an enjoyable player experience. All code for this project can be viewed on the GitHub link below at the directory -
...Behavior-Trees/tree/main/CW2AI/Assets/Scripts/AI - and shows the implementation in greater detail.
The goal for this project and its use of fuzzy logic was to ultimately replicate how a human would react in a similar way, though in much simpler terms. For example, the King understands
that the kingdom requires more gold. The King has numerous decisions they can make, but in a binary sense that can simply translate to:
if (Gold <= 75)
However, this betrays the point of studying and breaking down intelligent AI - rather than create such binary rules, we can instead implement numerous values that calculate
elements such as the economical weight, distance from goal, and lastly what the AI did prior, then start branching and replicating human-like behavior. It's incredibly interesting to observe
how humans interact with simple decisions in the real world, the basic question of "should I go eat?" varying wildly due to time, schedules, and laziness.
It's these branching choices that make this topic of study interesting, and is what I tried capturing with this project and later my thesis.
Below is an example of what a similar behavior tree might look like with the external fuzzy factors in very basic code:
if (Gold >= unitCost && Random.value > 0.5f && Public <= 75)
Unit.Schedule.Add("Create Unit Worker");
Gold -= unitCost; Public += 25;
// Else if Public is above Military, create Military Unit.
else if (Gold >= 40 && Random.value > 0.5f && Public > Military)
if (Random.value > 0.85f) Unit.Schedule.Add("Create Unit Scout");
else Unit.Schedule.Add("Create Unit Knight");
Gold -= 25; Public -= 35; Military += 25;
It's this level of intelligence and both strategic and reactive behaviour that makes for an intelligent AI agent, and allows the world to both expand whilst
allowing each individual unit that level of distinct, realistic control over their environment and world.
All of these elements then function together to create this procedural artificial intelligence and, once sped up, shows the evolution and natural expansion of the world in intriguing
and vastly distinct ways. There is currently no win or lose condition but upon losing your King the game slows down and requires a reset to witness a new iteration of the world.
I hope you enjoyed watching and reading about how this world builds up as much as I enjoyed creating it. Make sure to give The Throne a try if you wish to see this
project at its full potential!