stratagus-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Stratagus-devel] AI in stratagus


From: ludo
Subject: [Stratagus-devel] AI in stratagus
Date: Thu, 28 Aug 2003 17:13:31 +0000
User-agent: KMail/1.4.3

Hello !

I had a look some time ago to fr^H^Hstratagus's computer AI. I was wondering 
how to enhance it...

I rapidly saw that lots of behaviour were hardcoded ( how workers goes to 
mines, ... ), and not easy to read, because you have to keep the state of the 
unit from game cycle to game cycle.

So I searched a way to make AI more "customizable"...

I came to the idea that it could be interesting to write units's AI 
sequencially, as if their code was executing in separate threads. 
I think it could make AI for unit very simple; for exemple :

function attak(goal){
        while (!canFire(goal)){
                moveNear(goal,fireRange);
        }
        fire(goal);
}

There we have a problem if the goal can't be reached, but this could be solved 
by the way of exception : moveNear(...) throw an exception, which the caller 
of attack will receive. If the caller is the player, the exception will just 
be printed on the screen (can't attack : can't move to unit). 

We can also define these function in a kind of "class", binded to UnitType, so 
that a new unittype could use its own attack function...

The same approach can be followed for computer IA. It could be possible to 
write some small script ( ground attack, air attack, mixed attack, ... ) and 
then make the AI choose between them :

function transported_attack(attackers,transporter,landzone,attackzone){
        foreach unit in attackers{
                // Give some orders...
                attackers.stand
                transporter.take(attacker)
        }
        
        while(not all_orders_done){
                // Wait some time
                wait
        }
        attacker.moveTo(landzone)
        while((not transporter.underAttack)&&(not all_orders_done)){
                wait
        }
        attacker.unloadAll();
        foreach unit in attackers {
                attackers.attack(attackzone)
        }
}

This way, it is possible to go further, by allowing the IA to execute 
simultaneously multiple functions ...
So the hardcoded AI would resume to choose which and how many scripts it 
should execute at a given moment... ( maybe based on its ressources, ... )

I started working on this approach, by writing the interpreter which would 
allow such scripts to be executed in parallel, at low cost ( cpu & memory ).

But before i go further on this direction, I'd really like to know what you 
think about these ideas ?

Ludovic

-- 
Debug is human, de-fix divine.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]