TAI V1

TAI V1

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

TAI V1

Post by AF »

TAI code has been pushed to the sourceforge TAI CVS.

In the event of loosing itnernet access before fixing the build code, I have uploaded. I have many a new idea on completely re-organising and maybe coding soemthign that sounds like what I've said. The above will attempt to build a base, it wont however do so. It knows what to build and where to build it but It cant deal with build orders correctly, therefore no matter what happens it will always be told you dont have the untis to build that yet even if it does. I should really make a few fixes and adjustments soon such as defences and building scouts and attack units.

Zaphod, hope this helps you somewhat, the OTA parse code works fine, though It doesnt like huge files, I can think of a better way of recoding it but I prioritized oother parts, mainly getting building to work. Integrate the MUtil class more into the build pos finder and make it so it doesnt call SortSects everytime you want a position and it should speed it up a lot. Then it can be adapted to find to the nearest focal point and hey presto your AI's reliance on closestBuildPos() is eliminated and you have a basis for expanding thats much bigger than it was before.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

err how do I commit to cvs with sourceforge =s

edit:: err nevermind it seems to be working..
module name TAI. It isnt showing up in the webcvs view though =S
User avatar
jcnossen
Former Engine Dev
Posts: 2440
Joined: 05 Jun 2005, 19:13

Post by jcnossen »

If it isn't in the webcvs it's not there...
anyway, I'm not seeing the code there so could you try again?
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

Well I could retrieve it using Tortoise cvs..... I'm not sure how I'd commit anyways I just typed in the necessary address username etc and went to commit the TAI folder
User avatar
jcnossen
Former Engine Dev
Posts: 2440
Joined: 05 Jun 2005, 19:13

Post by jcnossen »

But you have to set up an SSL connection with sourceforge to get write access to cvs. It requires setting public and private keys and some other stuff I don't remember. Done all that?

edit: hmm ok SSH connection then :)
Last edited by jcnossen on 14 Aug 2005, 11:44, edited 1 time in total.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

It's connected through ssh yah, but about the key thing erm I dunno, I'm not to clued up on cvs....


EDIT :: http://taiskirmish.sourceforge.net/TAI.rar
Fnordia
Former Engine Dev
Posts: 425
Joined: 13 Aug 2004, 16:11

Post by Fnordia »

Sourceforge has a delay between the anonymous cvs and the developer one.. used to be a day or so, think it's only 5 hours nowadays.
Torrasque
Posts: 1022
Joined: 05 Oct 2004, 23:55

Post by Torrasque »

AF : I just compiled TAI.rar , and tried with spring 61b2.
I launch the game, your IA send some messages and a fews seconds later, the game crash. I tried 4 times, and always the same crash at the same time.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

Try it on small divide, it always seems to play up on castles and mars and I aint tried it on others, untill a hour ago or soemthign I was using 512x512 sectors and 64x64 sectors int he build placement algorithm when I should ahve been using 128x128 sectors and 16x16 subsectors, so it's parsing more info than it should.

Suffice to say I shall cotninue to fiddle among other things, my latest nag is a

Code: Select all

map<string,string> that doesnt like me:
map<int,std::string> ja = ud->buildOptions;
					for (map<int,string>::const_iterator aj = ja.begin();aj !=ja.end();aj._Inc())
					{
						builds.insert(ud->name,aj->second);
					}
gives me an error when I try to compile referring me to a template class in xtree as if I'm doing soemthign wrong, and I dunno what.
But like most other thigns I post here I'll probs delete it and try something else when I get fed up, and as zaphod said, it aint the best way to store things.

Eitherway as long as you play on small divide it wotn crash, it'll just twitter on cosntantly about building things but it never gets round to it....
IMSabbel
Posts: 747
Joined: 30 Jul 2005, 13:29

Post by IMSabbel »

can you put any kind of compiled version (dont care if its debug or anything) online?
I would love to try it out, but dont have Vstudio running here....
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

I'm afraid that any completed version wouldnt really do anything. I put it up because I dont want TAI to be obliterated if my computer gets chucked by my parents, and I've ahd enough of tackling this build problem for ages and ages, maybe this way someone might fix it out fo fustrationa nd get the ball rolling so I can work on attack and zoom ahead again.

Not to mention help others, such as zaphod, who says he's releasing his AI soon anyways, though from what I've seen of his, TAI has a much more agressive build stance that it can never satisfy ;D
User avatar
Triaxx2
Posts: 422
Joined: 29 Aug 2004, 22:24

Post by Triaxx2 »

I'll take a look at it shortly. I'm not a programmer, but in this case, that might be to my advantage.

This part doesn't make any sense at all, if the function is defined somewhere else.

Code: Select all

}
		CUtility->SetBuildOpt(buildOptions);
		CUnits[unit]=info;
		CUtility->AddtoCL(unit,CUnits[unit]);
		if (u->type == "Builder")
		{
			NumCons++;
		}
	}
}
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

Triaxx :: For CUtility look at CUtil.h
That was my first attempt at sorting out cosntruction, by placing idle con untis in a list in a class whcih also kept track fo what they could build and could return a type of unit or a unti that could build a type. It was hopelessly reliant on a function todo with build options that was flawed, and I dont know why. It is that problem which ahs been cropping up continually for the last 2 months. Solve it for me and you've fixed the construction bug.

}
CUtility->SetBuildOpt(buildOptions);
//move over a set of build options so the CUtillity class can access them
CUnits[unit]=info; //Add the unit structure to the array see BOUI.h
CUtility->AddtoCL(unit,CUnits[unit]); //Add the unit to the CUtility class
if (u->type == "Builder")
{
NumCons++;
//because in this function we're dealing with both builders and factories this is in an if statement. NumCons is the total nubmer of construction units.
}
}
}


I updated the CVS again. OTA AI definition backwards compatability is no longer supported though the code is still there. I ahve an incomplete LUA interpreter inplace to parse build information from scripts, and this time I'm gonan go zaphods way and tell it in the config what can build what for total control. It isnt in a compilable state at the moment due to teething problems with getting luabind working but I'm getting there. There's also a suggested interface for LUA that isnt linked with the rest of the code, it has been put into another test project though that is incomplete hence the binding code in the LUA_INTERFACE class. The LUA_AGENT class is definately being ported over.


Sorry for the colours
b1ind
Posts: 48
Joined: 21 Apr 2005, 04:01

Post by b1ind »

Cool, I'm heading to school in acouple days and I'll definitely take a look at the code. Maybe you could give us a bit of a more encompassing description of the problem so that we don't have to wade through vast amounts of code.
User avatar
Triaxx2
Posts: 422
Joined: 29 Aug 2004, 22:24

Post by Triaxx2 »

Shouldn't this:

Code: Select all

void CUtil::PurgeList()//BROKEN
{
	IdleCons.erase(IdleCons.begin(),IdleCons.end());
}
Be this:

Code: Select all

void CUtil::PurgeList()//BROKEN
{
	IdleCons.begin(IdleCons.erase(),IdleCons.end());
}
The idea being that it starts it, erases and then ends it.

As for the build code you've got two things that are confusing me:
int CUtil::GetTypecanBuildCL(int id)//fixme
and
int CUtil::GetTypecanBuildACL(int id)//fixme

What's the difference, and why are there two of them? Could it be that it's unsure which to call when?
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

ACL and CL. CL was for idle construction units. ACL was at 2 points, all construction units and at another point Active construction units.

Suffice to say ACL is no longer used and I havent gotten around to dealing with it.


Right now I am tryign to get it so that the engine generates a vector<Bbo> builds where Bbo is a structure containing the name of a builder and somethign ti can build. Such as CORCOM and CORWIN. That his how JCAI works, exept instead of dynamically generating the data absed on a list of unit names, it's instead written down in a config file.

As it stands I am trying tog et LUA to work, the only obstacle to that left being luabind and compiling it into a static library and thus getting rid of the need for everyone to downlaod the 10MB boost 1.32 files and the luabind source. I'll then use the same method as Zaphod and write it all down in LUA, exept it'll be better than simply using a text config file as I'll have an entire language with classes comments etc implemented for me. Once I've got ti workign and I can add that way using the Unit class that I've defined in BOUI.h I can add extra's. For one you'll see I've added techlevel and difficulty values for the build options in the Unit class, so I'll have support for difficulty and more accurate information.

I'll thus work on integrating the cheat interface into LUA for mission support and scripted cutscenes (remind me to ask for a few things to control the camera to be added to the cheats interface, and maybe to display arbitrary images and text outside the console.). That shouldnt be too hard as luabind does all the hard work.

As for CUtil(), the whole point was to keep track of and manage construction units, and make build orders easy by shoving them away in a small class so I'd never need bother with ti again. Or so I thought at the time.

void InitCUtil();

Initialises the class

void AddtoCL(int unit, UnitInfo* ug);

Add a construction unti to the list (idle con units) Units are added in UnitFinished and UnitIdle functions in CGlobalAI.

void RemCL(int unit);

To remove from the above list.

bool FindUnitCL(int unit);

Find a unit that was added through AddtoCL()

bool FindTypeCL(int id);

Find a unit in the idle list that is of this type, it might have been rpeferrable to use a string for unti name so that you could get a unitdef through callback. It simply looks for one btu it doesnt return it it justs ays if there is one.

int GetTypeSCL(string name);

Oh and the above as a string parametre but it returns the unti ID so that it can eb removed and used.

int GetTypeCL(int id);

Above but with Integer type. This isnt really of much use.

int GetTypecanBuildCL(int id);

Here's the problem function. There have been many versions of this (some are still ther ejust commented out, soem take strigns instead of integers).

int GetTypecanBuildACL(int id);

Same as above but for any unit.

void SetParent(IGlobalAI* ppointer);

Points to main CGlobalAI of the dll. Not really much use, should be changed to CGlobalAI*

void SetCallback(IGlobalAICallback* c);

Important, provides class with a GlobalAI callback interface to use.

//void SetUtility(Util* u);

This was supposed to give ti access tot he Util class, but it didnt work and I didnt think it was that important so I left it.

void PurgeList();

Erases the idle and active lists

float Distance(float3 pos1, float3 pos2);

Fidns the distance between 2 float3 co-ordinates

int RandomNum (int low, int high);

random number generator


void RegCon(int unit);

Add to active unit list

void RemCon(int unit);

Remove from Active unit list
void SetBuildOpt(map<int,BuildOption*> bO);

When a new con unit or factory was built, the map<int, BuildOption*> thign in CGlobalAI was updated, thent eh unitwas added tot he idle list, to save processing it's options voer again I just copied the structure.


Put in hat would parse the OTA AI def. It would sort all unitnames into categories and add them to an array. Such as PMex or PEnergy which are of type vector<string>.

When a type was needed PullOutOfHat was called given a type as a parametre. PullOutOfHat would then search through the respective array iterating through each item. It would see if it was better than the best currently found. Then it would check to see if it was buildable aka do we have any construction units that can build this. This si where the fabled GetCanBuildCL came in. GetCanBuildCL returned the unti ID of an idle unti capable of building it. If it returned zero then it skipped the item and carried on till there where no more left resulting in a return value of zero, btu there isnt a unit called zero.

The problem was the GetTypeCanBuildCL ALWAYS returned zero. Thus a suitable building could never be found and a command would always be issued saying unti zero is to build a unit of type zero at these co-ordinates, which the engine simply passes voer and does nothing because it cant do anything. Thus the AI never builds anything. If GetTypeCanBuildCL is fixed then PullOutHat is fixed and so is Util::CBuild and cosntruction occurs. The AI will thus attempt to build resource structures. Defences and factories and other units have no support yet as it was more important to get the AI to build anything first. It is also why Attack agents havent been implemented and only a set of 3 or 4 functions dealing with setting targets where ever written. Those should be deleted too anyways as they arent used.

In future the entire Util class should be re-written in LUA exept for the building placement algorithm, which needs hefty optimizing. The Map class could also be moved to LUA too as it isnt too complex.

Code: Select all

void CUtil::PurgeList()//BROKEN
{
   IdleCons.erase(IdleCons.begin(),IdleCons.end());
} 
The STL documentation says that the one overloaded function of the erase method is that it takes 2 iterators and erases everything inbetween. Here it erases starting from the beginning uptill the end.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

Ok, the LUnit (renamed from Unit) class is done, I just need to add the code that searchs through them to the CUtil class and hey presto building is done. The bindings are there for LUA. could someone write a script XTA.lua using the following?

Code: Select all

class Unit
{
string builder;
string buildOption;
int techlevel;
int difficulty;
}

UnitBuildOptions.pushback();
UnitBuildOptions.popback();

int difficulty;
string modname;
UnitBuildOptions being of type vector<LUnit> in C++.

Edit::

Very basic missions.

Code: Select all

LGC::

DrawUnit(string unit, float3 pos, int lifetime, int team)
Print(string y);
CreateUnit(string unit, float3 pos);
string Mapname;

float3::

int x,y,z;
distance2D();

UnitList::

push_back(Unit u);
pop_back(Unit u);

Unit::

string builder;
string buildOption;
int techlevel;
int difficulty;
User avatar
Triaxx2
Posts: 422
Joined: 29 Aug 2004, 22:24

Post by Triaxx2 »

Missions? That's great. Now we just need to start translating OTA missions to Spring. I'll do number five! As soon as I lay hands on a copy of XP that is.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

You'll need the maps converted over to spring format, I dont think any mission maps have had that done yet.

And so far untill I implement LUA_AGENT class and bind it and create the necessary management for it, then the only real missions you can ahve are eliminate the enemy missions with prebuilt bases.

Oh btw it's compiling btu before it links it gives the error that LUnit::LUnit and its destructor cant be linked in TestAI.obj because it's already defined in GlobalAI.obj. I dont know whats up with that, someone look into it? I also uploaded the other 2 files with classes suggested for binding to LUA, they're int he oddbits fodler.
User avatar
Dragon45
Posts: 2883
Joined: 16 Aug 2004, 04:36

Post by Dragon45 »

I havnet looked at that code, but from the sound of the error, it looks like your defintion of the LUnit constructor is actually the second constructor, the original one being defined in GlobalAI.obj. You might try deleting the one there first.
Post Reply

Return to “AI”