how to start the AI - Page 3

how to start the AI

Here is where ideas can be collected for the skirmish AI in development

Moderators: hoijui, Moderators

User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

Code: Select all

struct cscore{
    int energy;
    int mex;
    int attacker;
    int defender;
    int builder;
    int factory;
    int scouter;
};

class cscorer : public base {
public:
    scorer()
    ~scorer()
    void InitAI(Global* GL);
    cscore Score(UnitDef* u);
    cscore Score(int unit);
private:
    int energyscore(UnitDef* u);
    //... and so on
    Global* G; // if not NTAI use IAICallback* cb;
}; 

cscore cscorer::Score(UnitDef* u){
    cscore s;
    s.energy = energyscore(u);
    s.mex = mexscore(u);
//etc....
    return s;
}
As for errors.... try doing this

Code: Select all

cscore s;
try{
    s = scorerclass->Score(u);
}catch(...){
    cb->SendTextMsg("exception in scoring function!",1);
}
If you want to do all of them at once then I guess you could do another function, that got every single unitDef and cached all the generated scores by iterating through them and calling Score(ud); for each one.
User avatar
jcnossen
Former Engine Dev
Posts: 2440
Joined: 05 Jun 2005, 19:13

Post by jcnossen »

I have made catching AI exceptions optional in the current CVS, so you can just let the debugger catch the exceptions and show you the code.
You can disable them through the settings application and it's enabled by default (obviously).
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

In my case I have yet to get the debugger to work at all on my machine, i find it easier to simply see the exception messages my AI logs.
User avatar
ILMTitan
Spring Developer
Posts: 410
Joined: 13 Nov 2004, 08:35

Post by ILMTitan »

C++ has try and catch?? since when?
User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Post by krogothe »

Since whenever! even i knew that :o
I thought i had to include a file with an exception handling class though!
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

hhmm I just shove a try catch thing in there and it works.

In NTAI I do something more like:

Code: Select all

try{
    ...
}catch(exception e){
    G->L->iprint("Exception in ...");
    G->L->print(e.what);
}
exception is an STL class.
User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Post by krogothe »

Alantai Firestar wrote:

Code: Select all

struct cscore{
    int energy;
    int mex;
    int attacker;
    int defender;
    int builder;
    int factory;
    int scouter;
};

class cscorer : public base {
public:
    scorer()
    ~scorer()
    void InitAI(Global* GL);
    cscore Score(UnitDef* u);
    cscore Score(int unit);
private:
    int energyscore(UnitDef* u);
    //... and so on
    Global* G; // if not NTAI use IAICallback* cb;
}; 

cscore cscorer::Score(UnitDef* u){
    cscore s;
    s.energy = energyscore(u);
    s.mex = mexscore(u);
//etc....
    return s;
}
Now that I actually understand that:
Yeah its a great idea, however it wont be used for dynamic scoring like my(buggy) function does.
Ill be making a structure for the initial sorting. Each unit gets a rating for each class which tell the AI if it is an energy building or an attacking unit. Then arrays of all structures (units) are then saved along with the relevant values of its UnitDef (energyMake for plants, Speed for units etc). Each array for each type of unit!


Where can i start uploading my code? I need people to check that function since its giving me an exception every time i return a value with it (its either the UnitDef or the return bit, since removing both makes it work).
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

Upload it ehre or join the TAISkirmish project and I'll give you cvs access. Maybe then soemone can upload all this NTAI code, as I cant do it.

maybe to extend cscore I could do:

Code: Select all

struct cscore{
    int type; //suggested type with thigns such as #define ENERGY 1
    int energy;
    int mex;
    int attacker;
    int defender;
    int builder;
    int factory;
    int scouter;
};


then inside the class a cahce like

Code: Select all


map<int,cscore> cache 
where the integer is the unit type id

I'll talk more tomorrow as I've ran out of time
Post Reply

Return to “AI”