How are you claiming an AI that is not written is 100% modular and all that? You know C++ for about 5 days now, I don't think you can have a good view of what modular programming and optimizations mean in practice.... be realistic.plus its 100% modular, universally compatible and not all that CPU intensive, as well as providing great diversification and allowing for a comprehensive difficulty level which can adapt to the player.
Unit category sorter class + functions
Moderators: hoijui, Moderators
- Targ Collective
- Posts: 202
- Joined: 12 Nov 2005, 14:16
NTAI had agents that where modular, totally independant of anythign as long as it had the ability to do G->cb-> which needed a Global structure contianing IAICallback cb;
But recent versions have eliminated that as agents are calling eachothers functions now and sharing structures. Still doesnt mean i cant add new agents thata re totally seperated like before, such as cains metal class, or the scouter class (which remains independant).
But recent versions have eliminated that as agents are calling eachothers functions now and sharing structures. Still doesnt mean i cant add new agents thata re totally seperated like before, such as cains metal class, or the scouter class (which remains independant).
The AI will be extremely modular since pretty much avery action is guided by a function that gives a score for a given unit/action at any given time or conditions!
Zaphod, you are the living proof that my economy scorer system is modular since you added it to your AI :)
Most functions of my AI will take arguments like an unit or unitdef, read factual information like the map properties and return a value!
The sorter class can be used by any AI to divide units into categories no matter the mod, it reads the mod file or unitdefs (still evaluating which will work better) and return arrays with each unit.
Granted, some modules are bigger, such as the pathfinding one that once (if) implemented will take up a load of arrays of values and work out solutions from it, but even that can be broken down into standalone modules. The whole design of my AI centers around independent scoring functions and decision functions (which compare scores and take an action, you could feed your own scores into these and have them work)
If you want to be 100% literal yes i lied, my AI will not be 100% modular, since i cant really make the core of the AI that handles all the modules modular now can i??
And I have now written down a lot of the functions that the AI will use, the requirements for each category for the sorter class, and the inputs/outputs for them, so far they look pretty modular and qith the exception of the map arrays it all seems pretty CPU-friendly (working out 10 formulas every few seconds cant be all that bad)...
It is true i only started at C++ this week, but i know how programs work. To prevent people going "I TOLD YOU SO!!" later in case my AI goes wrong, ill ask for your fogiveness for making assumptions so early. Time will tell eventually! As i said, the plans are for a pretty awesome AI but it could really suck once implemented, dont you guys forget that!
Anyhow, I need to get over pointers, been stuck at them for a few days now!
Zaphod, you are the living proof that my economy scorer system is modular since you added it to your AI :)
Most functions of my AI will take arguments like an unit or unitdef, read factual information like the map properties and return a value!
The sorter class can be used by any AI to divide units into categories no matter the mod, it reads the mod file or unitdefs (still evaluating which will work better) and return arrays with each unit.
Granted, some modules are bigger, such as the pathfinding one that once (if) implemented will take up a load of arrays of values and work out solutions from it, but even that can be broken down into standalone modules. The whole design of my AI centers around independent scoring functions and decision functions (which compare scores and take an action, you could feed your own scores into these and have them work)
If you want to be 100% literal yes i lied, my AI will not be 100% modular, since i cant really make the core of the AI that handles all the modules modular now can i??
And I have now written down a lot of the functions that the AI will use, the requirements for each category for the sorter class, and the inputs/outputs for them, so far they look pretty modular and qith the exception of the map arrays it all seems pretty CPU-friendly (working out 10 formulas every few seconds cant be all that bad)...
It is true i only started at C++ this week, but i know how programs work. To prevent people going "I TOLD YOU SO!!" later in case my AI goes wrong, ill ask for your fogiveness for making assumptions so early. Time will tell eventually! As i said, the plans are for a pretty awesome AI but it could really suck once implemented, dont you guys forget that!
Anyhow, I need to get over pointers, been stuck at them for a few days now!
Yu ran into engine unreliability yet krogothe? I've jut spent an hour wrestling with it and NTAI 0.28b5 and construction code.
for example ym construction code orders a con kbot to build something. It returns an error, but the unit actually goes and builds it, so NTAI thinks its failed when it hasnt.
And sometimes the NTAI commander will stop buildign adn go onto its next command, not because of NTAI but because the human players commander has become idle and as a result the engine has told NTAI that the NTAI commander is idle instead.
for example ym construction code orders a con kbot to build something. It returns an error, but the unit actually goes and builds it, so NTAI thinks its failed when it hasnt.
And sometimes the NTAI commander will stop buildign adn go onto its next command, not because of NTAI but because the human players commander has become idle and as a result the engine has told NTAI that the NTAI commander is idle instead.
Every NTAI instance has its own instance of the Global structure.
Eitherway i shall look into this.
So is this to say that for all the players usign NTAI there is a single instance of NTAI cotnrolling them all? If so that explains a lot and I am curious as to why nobody has pointed it out before now.
Eitherway i shall look into this.
So is this to say that for all the players usign NTAI there is a single instance of NTAI cotnrolling them all? If so that explains a lot and I am curious as to why nobody has pointed it out before now.
- sp2danny72
- Posts: 60
- Joined: 09 Jan 2005, 04:52
Pointers are easy. When I first learned C, I believed that pointers were
difficult, and as a result they were. When I stopped believing that pointers
were difficult, they stopped being so.
Memory is a contiguous sequence of bytes, with numerical addresses,
starting from 0. A pointer is simply an integer, wich is interpreted as a
such address. It has a type associated with it, so that the compiler knows
what is supposed to be at that address. Thats it, basicly.
There is one thing that can be surprising for the beginner:
If you add a number, say one, to a pointer, the pointer is not increased
with one, but with the size of the object pointed to.
You have probably read all this and more in some form, but,
decide that pointers are easy, and read it again.
difficult, and as a result they were. When I stopped believing that pointers
were difficult, they stopped being so.
Memory is a contiguous sequence of bytes, with numerical addresses,
starting from 0. A pointer is simply an integer, wich is interpreted as a
such address. It has a type associated with it, so that the compiler knows
what is supposed to be at that address. Thats it, basicly.
There is one thing that can be surprising for the beginner:
If you add a number, say one, to a pointer, the pointer is not increased
with one, but with the size of the object pointed to.
You have probably read all this and more in some form, but,
decide that pointers are easy, and read it again.
Thanks danny but i know most of the theory behind it, i know about creating and deleting them, about how they are an address but they point to data, how to use them as dynamic arrays using the new command etc...
Now pointing to IAICallback and IGlobalAICallback to get the AI to work is proving incredibly frustrating, nothing seems to work at all!
The above code is attempt no 19 at getting the callback to work on a different class. cb points to the IAICallback class, which should allow me to use things like UnitDef() but it wont, it will just cover the compiling window with errors.
its just not happening for my AI...
Of course i could just pile in 300+ functions into one class/source file and not care about this OOP ideal. It would be ugly, messy and slow but it would work...
Now pointing to IAICallback and IGlobalAICallback to get the AI to work is proving incredibly frustrating, nothing seems to work at all!
Code: Select all
#include "GlobalAI.h"
#include "IAICallback.h"
class Test
{
public:
IAICallback* cb;
Test(IAICallback* callback);
virtual ~Test();
float GetEnergyScore (const char *name);
};
Test::Test(IAICallback* callback)
{
this->cb=callback;
}
Test::~Test()
{
}
float Test::GetEnergyScore (const char *name)
{
float IncomeMultiplier = 1;
float MetaltoEnergyRatio = 30;
float Cost = (cb->GetUnitDef(name)->metalCost * MetaltoEnergyRatio) + cb->GetUnitDef(name)->energyCost;
float Production = cb->GetUnitDef(name)->energyMake - cb->GetUnitDef(name)->energyUpkeep;
float CurrentIncome = IncomeMultiplier*(cb->GetEnergyIncome() + (cb->GetMetalIncome() * MetaltoEnergyRatio));
float Hitpoints = cb->GetUnitDef(name)->health;
float EScore = (Production/((Cost+CurrentIncome)* Cost))*sqrt (sqrt (Production)* sqrt (sqrt ((Hitpoints*Hitpoints)/Cost)))*10000*CurrentIncome;
return EScore;
}
The above code is attempt no 19 at getting the callback to work on a different class. cb points to the IAICallback class, which should allow me to use things like UnitDef() but it wont, it will just cover the compiling window with errors.
its just not happening for my AI...
Of course i could just pile in 300+ functions into one class/source file and not care about this OOP ideal. It would be ugly, messy and slow but it would work...
Im just copying the code from other AIs, i thought a destructor couldnt be virtual anyways since it cant have a type or arguments...
i get these errors:
I cant recall even using IGlobalAICallback in that code!
i get these errors:
Code: Select all
.\Res.cpp(29) : error C2027: use of undefined type 'UnitDef'
..\rts\IGlobalAICallback.h(7) : see declaration of 'UnitDef'
.\Res.cpp(29) : error C2227: left of '->metalCost' must point to class/struct/union/generic type
.\Res.cpp(29) : error C2027: use of undefined type 'UnitDef'
..\rts\IGlobalAICallback.h(7) : see declaration of 'UnitDef'
.\Res.cpp(29) : error C2227: left of '->energyCost' must point to class/struct/union/generic type
.\Res.cpp(30) : error C2027: use of undefined type 'UnitDef'
..\rts\IGlobalAICallback.h(7) : see declaration of 'UnitDef'
.\Res.cpp(30) : error C2227: left of '->energyMake' must point to class/struct/union/generic type
.\Res.cpp(30) : error C2027: use of undefined type 'UnitDef'
..\rts\IGlobalAICallback.h(7) : see declaration of 'UnitDef'
.\Res.cpp(30) : error C2227: left of '->energyUpkeep' must point to class/struct/union/generic type
.\Res.cpp(32) : error C2027: use of undefined type 'UnitDef'
..\rts\IGlobalAICallback.h(7) : see declaration of 'UnitDef'
.\Res.cpp(32) : error C2227: left of '->health' must point to class/struct/union/generic type
ok you can remove the virtual before the constructor...
try this:
try this:
Code: Select all
const UnitDef *def = cb->GetUnitDef(name);
float IncomeMultiplier = 1;
float MetaltoEnergyRatio = 30;
float Cost = def->metalCost * MetaltoEnergyRatio + def->energyCost;
....