Page 3 of 3

Posted: 19 Nov 2005, 18:33
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.

Posted: 19 Nov 2005, 18:37
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).

Posted: 19 Nov 2005, 18:41
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.

Posted: 20 Nov 2005, 06:13
by ILMTitan
C++ has try and catch?? since when?

Posted: 20 Nov 2005, 07:10
by krogothe
Since whenever! even i knew that :o
I thought i had to include a file with an exception handling class though!

Posted: 20 Nov 2005, 17:27
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.

Posted: 20 Nov 2005, 18:57
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).

Posted: 20 Nov 2005, 19:02
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