Unit category sorter class + functions - Page 2

Unit category sorter class + functions

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

Moderators: hoijui, Moderators

User avatar
jcnossen
Former Engine Dev
Posts: 2440
Joined: 05 Jun 2005, 19:13

Post by jcnossen »

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.
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.
User avatar
Targ Collective
Posts: 202
Joined: 12 Nov 2005, 14:16

Post by Targ Collective »

You don't have to know C to know what a module is, Zaphod. There is a great deal to learn, but Krogothe may already have some experience in programming through another language.
User avatar
jcnossen
Former Engine Dev
Posts: 2440
Joined: 05 Jun 2005, 19:13

Post by jcnossen »

Could be, but how is it modular if it is not yet written?
The point is that the whole "I have made an AI in my head and it works very well" doesn't make sense, it never works out that way in practice...
submarine
AI Developer
Posts: 834
Joined: 31 Jan 2005, 20:04

Post by submarine »

thx zaphod , 100% ack :)
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

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).
User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Post by krogothe »

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!
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

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.
User avatar
jcnossen
Former Engine Dev
Posts: 2440
Joined: 05 Jun 2005, 19:13

Post by jcnossen »

Why couldn't those be NTAI bugs? Seems more likely especially since submarine and I have no such problems...
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

because I have logged excessiely and NTAI logged every stage of the process what the engine returned and what it did.

eitherway i have no source for AAI, and nobody si helping me with NTAI. But I shall search on for the reasonf ro these problems!
User avatar
jcnossen
Former Engine Dev
Posts: 2440
Joined: 05 Jun 2005, 19:13

Post by jcnossen »

I looked a bit at your code and saw that you store the AICallback in a global pointer... this is probably part of the problem since every team has a different AICallback instance.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

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.
User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Post by krogothe »

So far the only engine shortcoming was a commander not building something if it is near enough to discourage pathfinding but far enough so it cant reach it... extremely easy to fix by issuing a move order...
Im wrestling with C++ pointers for ages now!
User avatar
sp2danny72
Posts: 60
Joined: 09 Jan 2005, 04:52

Post by sp2danny72 »

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.
User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Post by krogothe »

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!

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...
submarine
AI Developer
Posts: 834
Joined: 31 Jan 2005, 20:04

Post by submarine »

what does the compiler actually say? maybe we can figure out what's your mistake...

and why is your destructor declared "virtual"?
User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Post by krogothe »

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:

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
I cant recall even using IGlobalAICallback in that code!
submarine
AI Developer
Posts: 834
Joined: 31 Jan 2005, 20:04

Post by submarine »

ok you can remove the virtual before the constructor...

try this:

Code: Select all

const UnitDef *def = cb->GetUnitDef(name);

float IncomeMultiplier = 1;
float MetaltoEnergyRatio = 30;
float Cost = def->metalCost * MetaltoEnergyRatio + def->energyCost;
....
User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Post by krogothe »

*def pointer works fine (it does point to cb->GetUnitDef correctly), but i get the exact same errors!
I think its the cb pointer thats causing all the grief!
submarine
AI Developer
Posts: 834
Joined: 31 Jan 2005, 20:04

Post by submarine »

can you email me your whole project? i'll have a look at it...
submarine
AI Developer
Posts: 834
Joined: 31 Jan 2005, 20:04

Post by submarine »

ok i made your project compile.... mail has been sent
Post Reply

Return to “AI”