Ai for strategies games
How much do you know about AI?
Can you define the problem better?
It is much easier to solve a well defined problem. You'll find, in most cases, just understanding what you're asking will offer up a solution by itself.
For instance, attacking a weak enemy would gain quite a lot (you'd win hands down) but attacking a strong enemy would be foolhardy.
I'm not sure how you'd go about it, but you need to identify some form of scoring for war/peace with all other sides in the game and then throw in a little randomness to give your AI some 'personality'.
All constructive criticism welcome.
There are many methods of programming an intelligence to make decisions. Condition Action rules (split into finite and fuzzy state machines), expert systems and neural networks to name the basic ones. Each of these can also be adjusted by adaptive learning or genetic algorithms.
Am I scaring you yet?
Personally, if you're inexperienced, I'd suggest you get your head around condition action rules first. The basic methodology of this (if there is a complex methodology) is identical to the IF THEN statement. Based on a set of criteria, which is basically the current state of the game at any one point in time, the AI cycles through a set of IF THEN clauses until one is triggered. This is a finite state machine, it uses distinct TRUE and FALSE values about a set of facts to determine an answer, everytime you run it with a set of values it gives an identical reasoning.
Fuzzy logic or fuzzy state machines don't work from TRUE/FALSE criteria, instead they weight values from various inputs from the current environment state and make a less distinct decision.
Here's an example to show the difference between finite and fuzzy state machines (often written as FSM and FuSM).
IF 2 * numberOfEnemies < numberOfAllies THEN attack
This would be a FSM making a logical decision which would always fire given the number of it's allies being at least double the number of it's enemies.
For a FuSM example of the same problem
AttackWeighting = ((NumberOfMyTroops * AverageQualityAlly) / (NumberOfEnemyTroops * AverageQualityEnemy)) + (AmountOfLandGained / EstimatedTroopsLost) + HateTowardsEnemy - EstimatedBadFeelingDueToAttack
if (AttackWeighting > 0.75 - aggression) then Attack
It can be as complicated or as simple as you feel necessary.
Most game AI is written as a mixture of FSM and FuSM and it should solve your problem fine.
The main difference is that values in FuSM (such as aggression and HateTowardsEnemy) are constantly changing throughout the game based on past events but FSMs and FuSMs are essentially the same idea.
Any comments?
Mike
Thank ya a lot. You have clear a lot of question i was having. This give me a good example to work with.
Btw, this is not so scary, this is mainly time consuming as i see. i think i will use the if-then statement first.
The following is the definition of an array database that describes a common puzzle (some of you might even know it). The idea of the puzzle is, that given a number of people, cars, houses etc. (domains) and descriptions such as "mr.x drives a buick", "mr.y lives in a green house" (relations) you should be able to answer a question such as "who lives in the red house?" without that information being given explicitly.
UBB wouldn't eat the post in one chunk, so the example is available at www.array.dk). The puzzle should be obvious from the comments in the example.
Try to envision a program that given ANY set of input values on any (or all) of the variables can INSTANTLY deduce EACH AND EVERY solution that satisfy the given relations. Now, try to program that using IF THEN statements. No easy task (impossible in fact).
What I am trying to illustrate is that the use of state machines in game AI is perhaps one of the most limiting factors today, simply because there is a limit to how complex problems you can solve with IF THEN statements.
An arraydatabase, on the other hand, is a very efficient binary representation of variables and relations (such as the example above) that is guaranteed to be complete, is VERY small, and allow for VERY fast (table lookup) run-time deductions.
If you want to read more about the math behind this, check out our web site at http://www.array.dk
If you find this interresting and feel like playing around with it, a free evaluation kit will be made available within the next couple of weeks.
/Niels
[This message has been edited by Niels (edited November 09, 1999).]
Well, actually, I kinda disagree.
I'm one of the believers that any one representation of AI can be represented in any other representation of AI. You can form a set of CA rules out of a neural net or neural net out of an expert system. Normally, due to complexity, one compact form would turn into a hideous huge form in another representation, probably expanding exponentially in size but possible nonetheless.
However, my main point was to get Sadness started with something simple, easy and quick to learn before trying anything complex. I've written simple neural networks and know they can be difficult to debug when they go wrong (bordering on impossible with more than a few dozen nodes) and auto-adapting them in realtime is something most AI programmers shy away from.
So I stuck with simplcity for now...however I will be checking out the URL.
And while we're here, do you have any thoughts on my unresponded topic on Tessalatable AI?
Reg. tessalation: I was going to post an answer, but it ended up as a rather - eh - "muddy" attempt at saying something clever. If I understand you correctly, I generally like the idea, but see some pitfalls (here it comes ):
1) Obviously, the tessalation parameter would have to be something other than the "visibility" of an NPC. Such as "the importance of the NPC at this particular stage in the game". How you determine this I don't know, it could be as simple as a priority list. The problem is that figureing out what NPC are more important is generally an AI exercise in itself.
2) While owners of slow computers would generally accept lower quality gfx for a faster framerate, I'm not sure they would accept dumb AI. (Besides, what will happen with a game that is hard on a 450PII, when it's run on a 1GHz Athlon?)
/Niels
A finite state machine always goes to a particular next action given the same circumstances.
A Fuzzy state machine, otoh, fires an appropriate but otherwise randomly determined rule given the same circumstances. The randomness can be weighted, as in
c=random(1..100)
if(c>=80)
dostuff;
else if(c>=50)
dootherstuff;
else
doyetotherstuff;
or unweighted,as in
c =random(1..100);
if (c>=(2/3)*100)
dostuff;
else if(c>=(1/3)*100)
dootherstuff;
else
doyetotherstuff;
although weighted usually makes more sense.
Since I'm just a lowly student I'm guessing that that's what the Estimate... bit is used as in an actual implementation. I just didn't get it, so I figured I'd rephrase it.
Anyway,
signing off,
mikey
Just to clarify THAT mess:
dostuff, dootherstuff, and doyetotherstuff are all valid responses to the general game conditions, ie unit health, enemies nearby, etc.
In fuzzy theory this is usually pictured as
d.s. d.o.s. d.y.o.s.
/ \ /\ /\
/ / / \
/ / / \
/ / / \
/ / / \
------------------------------------
^
|
here either
function might be fired,
and the weightings are a
matter of how high the
triangles are at this point
(triangle 'height'
being that big expression
that MikeD wrote out)
And since you're just starting out, I might give you this one piece of advice:
Play with anything you make. Fix the numbers as you play. You might learn some interesting stuff, and as I understand it that's the basic production process in the industry anyway, so you'll have a head start.
Anyway.
signing off,
mikey