Kohan Film Database




Kings of War - Editing


Inside KoW AI
by Seyal

Information and reference for this article are from Section
4.7 of "AI Game Programming Wisdom 3", an article on Goal
Based AIs (and K2 used as a specific example) written by
Kevin Dill of Blue Fang Games.

All credit to information derived from his writing goes to him,
and I make no claim to his work.

AI designing is something I enjoy. If I ever become a game programmer
professionally, I want to design the AI, or at the least be the one
who creates the AI players that ship with the game. I can't remember
the first AI I ever wrote for myself, but every new game that I get,
the first thing I check is to see if the AI is mod-able and how flexible
the system is.

Eventually I would stumble upon KIS and the AI system there. Then KAG,
and finally K2 - making AIs along the way, largely for my own enjoyment
and to give me a good, hard game of Kohan when I don't have the
time/desire to hit the online world.

Which leads me here, to K2's AI system. I find it is rather flexible and
strong, able to pretty much re-create most straight-forward,
 human-designed builds and strategies, at least at the high level. It
struggles with things only human players can come up with such as
complex timing or highly complex build orders, but it can hold it's
own in many other areas in terms of getting it to play a lot like a
decent to good human player would play the race/faction combo.

The core of the system is the Think Cycle, and will be the focus
of the meat of this discussion. Credit to Kevin Dill for outlining
the steps that take place in the Think Cycle. I'll talk about how I
implement the step in my own AIs or my interpretation based on what I
do know (which is far from everything!)

The Think Cycle

1. Select the appropriate ego.
An ego is a section of a playbook. It contains all the "plays" to be
used in the current game situation. Using an example of an NFL playbook,
 the ego would be plays for 1st and 10, or plays for 3rd and long, or
goal line defense situations. These would all be egos in the K2 system.
The designer can create as many as desired and specify the situation
with quite a few possibilities. Personally, I keep things relatively
simple, following the example of the stock AIs, but expanding on it to
cover more game situations or broader situations in more fine detail,
especially the early-game since a good, quick start is an important

The absolutely great thing about egos is that they can inherit from
other previously defined egos. I like to set up a "global" ego, sort
of a base from which the others can pull values from if I don't need
to specifically name out a setting in the lower ego. To me, this is like
the human player's personality. A player that's typically aggressive
will view battle situations differently than a player that likes to
play defense or have a slower military start. A player that likes to
make units fight "to the last man" (as Chandra Majere, a nationalist
kohan is apt to say) will have a different overall style than a player
that's more concerned about preserving units. These sort of things
are a lot of what I use the "global" ego for.

Another thing I use it for is for settings I don't want to/need to
change with each AI. Some things work well for the AI in general, and
these things I like to not have to re-type with every AI or tinker
with each time. So they go into the "global" ego as well.

2. Identify the inactive and completed goals and drop them from
No sense trying to do what's already been done. There's not a lot the
designer can do about the inactive goals, although there's one really
nice control feature I utilize a lot. Every major goal can have a
minimum value assigned to it. If the actual priority for a specific
goal doesn't make the minimum, then it doesn't get done. For example,
if an attack goal has a minimum of 1500, and the priority is 1200 on
a specific target, that target doesn't get considered and those
troops can get assigned to do something else, like join an attack
that's already got a high enough priority.

3. Calculate the base priority for the goals.
This ties in with step two as far as using the minimum value goes.
It also considers several other things such as the strength that the
AI wants to bring to bear, distance from current location, etc. Any
"bonuses" and such don't get counted - yet. Incidentally, this is shown
in the first column of the GoalPriorityCSV output.

4. Assign resources to the goals - using as little as possible.
I see this a lot in the build orders, especially when the AI needs to
do something while continuing its build. If it needs to build a
component, but also has the cash to settle, it will either settle or
wait until both goals can be achieved and do both at once. The decision
to wait or not largely depends on how long it would take to store up
the gold. The AI will also assign future resources to goals if it
will be enough to accomplish a big goal, like teching Opal Rings or
another 500 gold tech, or upgrading to a city.

5. Optimize resources, moving them from any goal to any other goal if
it will increase the priority of the goal.
I know the least about this step of them all, but it does have something
to do with positioning actors closer to goals or in better pathfinding
positions to their goal. This is probably most seen, based on what I
can observe, with troop movements, namely shifting units from one attack
to another one if the situation the troops are currently in no longer
requires their presence, etc.

6. Mark the goals we are going to do and send the orders.
Pretty straight forward here. Nothing really needs to be done on the
designer's end.

Other features of the AI

The Think Cycle isn't the only cool thing about the AI system. The AI is
also able to utilize other human-ish things such as committing to goals.
The AI can commit with time and/or by focus. Time commitments generally
come from saving up gold to do something big, like teching or recruiting
those expensive company combinations. Focus commitment comes from goal
inertia, which can help keep the AI from playing like a hyperactive
little kid, always jumping from one thing to the next. These things
are settings the designer can modify, and they can be set per
ego if desired. I usually leave them at the "global" level and let the
other egos pull this value.

One aspect I don't use much is fuzziness. I realize its there to try to
make the AI be more random, but quality human players don't really act
randomly, in my opinion, but change with a certain exact purpose in
mind. If they decide to do something else, it's not because of a random
influence, but because of a game situation, or in response to their
opponent, and the AI already has features for that. Egos go a long way,
and there's other aspects such as learning factors and the Reactive AI
to handle things of that nature.

Speaking of the Reactive AI, it's the quarterback on the field. It
doesn't act much on it's own, but instead acts within the framework of
the goal engine's decisions. It tends to evaluate things more frequently
because the unit's situation changes with relative frequency, but
doesn't derive decisions on it's own. If the goal engine gives a Recover
goal to a unit, the RAI decides where to retreat the unit and when to
make it accessible to the goal engine/itself for further orders. If
the goal engine gives an attack goal and assigns a unit to that goal,
the RAI will comply, but if the battle is well taken care of in it's
opinion, it will attack something else with that unit or group.

The last thing I want to mention is something I never heard being in
the AI system until reading Kevin Dill's article. The AI can cache
paths. It basically allows the AI to "see" a path and "pre-calculate"
the time it would take to travel that path. This will help it make
better distance-related decisions when it comes to picking out targets
to attack or defend. So instead of having to traverse each path to
discover the time it would take, it can figure out and "save" all the
paths between two relatively close points, estimate the times of all
the paths, and make its adjustments at the goal level.

Well, that's all I wanted to talk about. Hopefully, it was interesting
to read. Thanks again to Kevin Dill for writing a great article that was
very entertaining to read. It certainly gave me another view of the AI
and some new angles to try, as well as teaching me even more about
the AI in K2. Thanks also to Dan Genovese (Chimaeros) for putting this
on his The Awakening fansite.




Copyright 2001, 2004
Dan "Chimaeros" Genovese
No reproduction or other use of content contained within this site is allowed without specific written permission.
Kohan: Copyright 2000-2001 TimeGate Studios, Inc. All rights reserved.
All other logos, brand names, product names listed are trademarks or registered trademarks of their respective holders.