TAI part 4 Command queues rules the roost
Moderator: Moderators
TAI part 4 Command queues rules the roost
/*TAI Part 4
The queue to end all queues
So it came to me that we could take commands for units and put them into a script or at least into a queue then copy the queue over to other units or set a factory to automatically give built units the command queue. Of course I now realise a much better use fo trying to get the most out of this system.
If you can make a Factory assign a queue to a unit once it's built then you can assign a factory a build queue and the construction unit a build queue of factories and resources that come from factories. So if you could tell a commander to assign itself a command queue at the beginning of the game and include logic in that queue based on surroundings then yu could essentially create a simple AI.
So what would become of the idea of an AI made totally of a large collection of command queues auto assigned?
Such an AI while providing a simple AI would show a highly customisable AI, however it wouldn't be able to react in the way Sun Tzu would require it to unless you specifically scripted sets fo queues for every map game type and player which is absurd.
So I suggest that TAI brings in a new set of agents, unit agents. A unit is given an instance of a save agent. The AI doesn't bother telling units where to go other than groups to large sectors. These scripts would deal with Micromanagement and would essentially simply be told what to do with no real complexity.
So what do we make all these scripts in? I think I should rule out compiled languages. A language that's easy and popularity, such as Java, or Perl. I'm guessing some sort of Socket layer with an immediate abstraction layer on top providing basic functions and data structures such as the threat array and move here and is anything there type functions. Thus any person could wander into the folder and change the AI to suit them. A basic unit control class for each type would be needed, attack: sea air ground mixed, const: ground sea air mixed Building, and modders could create their own class for custom units through inheritance.
Seeming as most people already have Java and wouldn't want to download active Perl, and the greater portability of Java, I'd say Java was the better to use. So We would have an immediate abstraction layer built in C++ as a dll for the engine that would provide a sockets layer to a Java program which would contain the 'unit agents' and 'system agents'. Unit agents being those that receive basic commands and carry them out and system agents being those that deal with big things and not specific units.
So we have a hovercraft agent a ground agent and amphibious agent a sea agent an air agent a defence agent and a factory agent. All of which accept general commands such as go here attack sector with tactic where a tactic is a class derived from the original class.
System agents would be in two types, those that react to events and those that run at timed intervals. For example resources would be a timed interval, and the construction agent would be event based. Thus an event can be termed as receiving a command or request from another agent.
So a simplistic AI could be*/
//Start AI
MAIN(){
defstructs();
//INITIALISE SYSTEM AGENTS
BUILD build = new BUILD
//SET STARTPOS
float3 startpos = getunitpos(1);//1 being the Unit ID of the first unit, which I'm guessing would be the commander.
//START TIMER
//EVERY MINUTE INITIALISE TIMED AGENTS AGAIN FOR RE-RUN
}
IF (/*MAP COVERED BY RADAR*/){
break;
}
ELSE {
FIND EDGE NEAREST TO STARTPOS = XY
WHAT IS BEST ARADAR AVAILABLE = BUILDING
BUILD.REQUEST( BUILDING , X, Y, NEAREST);
}
}
void DefStructs(){
struct queue{
int BuilderID
int BuiltID
}
}
class BUILD {
/*build agetn, deals with building and deciding wether a build request should go ahead wether it an be built there and thus need moving and wether the resources are available to build it. */
public:
int Request(int UNITID,int X, int Y, char PREFLOCATION[8]);
void queueAdd(int UNITID,int X, int Y, int PRIORITY);
protected:
queue
private:
};
BUILD::Request(int UNITID,int X,int Y, char PREFLOCATION[8]){
IF (CANBUILD(X,Y) = FALSE){
SWITCH (PREFLOCATION){
case 'NEAREST':
//CODE TO FIND NEAREST GRID SECTOR THAT CAN BE BUILT ON
IF (X-NEARESTX>(1SECTOR || -1SECTOR)){
return false;
}
break;
case 'ANYWHERE':
//CODE TO FIND NEAREST SECTOR AGAIN
IF (THREAT(XY); => 1.5*AVERAGE THREAT){
return false;
}
break;
}
}
int PRIORITY = BUILDPRIORITY(UNITID,X,Y)
this.queueAdd(UNITID, X,Y, PRIORITY);
}
void Sight::AddScout(int UnitID){ // for when scout is built and handed over
//FIND NEAREST EDGE OF LOS TO STARTPOS
//SET WAYPOINTS OF UNITID TO PATROL EDGE.
}
class Sight{
public:
void AddScout(int UnitID);
int RmvScout(int UnitID);
protected:
int Scout[100];//stores the Unit ID's of the scous that've been handed over
private:
}
// I├óÔé¼Ôäóll keep changing this post to be ever more full but I thought the general idea needed to be put across so I could get comments since the comments well seems to be drying up and needs new life.
//Argghh I had a terrible head cold when I wrote this so dont be too
//antagonising over errors. Erm I dunno if i should ahe said antagonising
The queue to end all queues
So it came to me that we could take commands for units and put them into a script or at least into a queue then copy the queue over to other units or set a factory to automatically give built units the command queue. Of course I now realise a much better use fo trying to get the most out of this system.
If you can make a Factory assign a queue to a unit once it's built then you can assign a factory a build queue and the construction unit a build queue of factories and resources that come from factories. So if you could tell a commander to assign itself a command queue at the beginning of the game and include logic in that queue based on surroundings then yu could essentially create a simple AI.
So what would become of the idea of an AI made totally of a large collection of command queues auto assigned?
Such an AI while providing a simple AI would show a highly customisable AI, however it wouldn't be able to react in the way Sun Tzu would require it to unless you specifically scripted sets fo queues for every map game type and player which is absurd.
So I suggest that TAI brings in a new set of agents, unit agents. A unit is given an instance of a save agent. The AI doesn't bother telling units where to go other than groups to large sectors. These scripts would deal with Micromanagement and would essentially simply be told what to do with no real complexity.
So what do we make all these scripts in? I think I should rule out compiled languages. A language that's easy and popularity, such as Java, or Perl. I'm guessing some sort of Socket layer with an immediate abstraction layer on top providing basic functions and data structures such as the threat array and move here and is anything there type functions. Thus any person could wander into the folder and change the AI to suit them. A basic unit control class for each type would be needed, attack: sea air ground mixed, const: ground sea air mixed Building, and modders could create their own class for custom units through inheritance.
Seeming as most people already have Java and wouldn't want to download active Perl, and the greater portability of Java, I'd say Java was the better to use. So We would have an immediate abstraction layer built in C++ as a dll for the engine that would provide a sockets layer to a Java program which would contain the 'unit agents' and 'system agents'. Unit agents being those that receive basic commands and carry them out and system agents being those that deal with big things and not specific units.
So we have a hovercraft agent a ground agent and amphibious agent a sea agent an air agent a defence agent and a factory agent. All of which accept general commands such as go here attack sector with tactic where a tactic is a class derived from the original class.
System agents would be in two types, those that react to events and those that run at timed intervals. For example resources would be a timed interval, and the construction agent would be event based. Thus an event can be termed as receiving a command or request from another agent.
So a simplistic AI could be*/
//Start AI
MAIN(){
defstructs();
//INITIALISE SYSTEM AGENTS
BUILD build = new BUILD
//SET STARTPOS
float3 startpos = getunitpos(1);//1 being the Unit ID of the first unit, which I'm guessing would be the commander.
//START TIMER
//EVERY MINUTE INITIALISE TIMED AGENTS AGAIN FOR RE-RUN
}
IF (/*MAP COVERED BY RADAR*/){
break;
}
ELSE {
FIND EDGE NEAREST TO STARTPOS = XY
WHAT IS BEST ARADAR AVAILABLE = BUILDING
BUILD.REQUEST( BUILDING , X, Y, NEAREST);
}
}
void DefStructs(){
struct queue{
int BuilderID
int BuiltID
}
}
class BUILD {
/*build agetn, deals with building and deciding wether a build request should go ahead wether it an be built there and thus need moving and wether the resources are available to build it. */
public:
int Request(int UNITID,int X, int Y, char PREFLOCATION[8]);
void queueAdd(int UNITID,int X, int Y, int PRIORITY);
protected:
queue
private:
};
BUILD::Request(int UNITID,int X,int Y, char PREFLOCATION[8]){
IF (CANBUILD(X,Y) = FALSE){
SWITCH (PREFLOCATION){
case 'NEAREST':
//CODE TO FIND NEAREST GRID SECTOR THAT CAN BE BUILT ON
IF (X-NEARESTX>(1SECTOR || -1SECTOR)){
return false;
}
break;
case 'ANYWHERE':
//CODE TO FIND NEAREST SECTOR AGAIN
IF (THREAT(XY); => 1.5*AVERAGE THREAT){
return false;
}
break;
}
}
int PRIORITY = BUILDPRIORITY(UNITID,X,Y)
this.queueAdd(UNITID, X,Y, PRIORITY);
}
void Sight::AddScout(int UnitID){ // for when scout is built and handed over
//FIND NEAREST EDGE OF LOS TO STARTPOS
//SET WAYPOINTS OF UNITID TO PATROL EDGE.
}
class Sight{
public:
void AddScout(int UnitID);
int RmvScout(int UnitID);
protected:
int Scout[100];//stores the Unit ID's of the scous that've been handed over
private:
}
// I├óÔé¼Ôäóll keep changing this post to be ever more full but I thought the general idea needed to be put across so I could get comments since the comments well seems to be drying up and needs new life.
//Argghh I had a terrible head cold when I wrote this so dont be too
//antagonising over errors. Erm I dunno if i should ahe said antagonising
- [K.B.] Napalm Cobra
- Posts: 1222
- Joined: 16 Aug 2004, 06:15
- Mars Keeper
- Posts: 240
- Joined: 25 Jan 2005, 21:00
- BlackLiger
- Posts: 1371
- Joined: 05 Oct 2004, 21:58
Very interesting. I do see minor flaws here and there in the logic, one of which being certain maps with the AI starting positioned in the middle of a pair of opponents, and being just slightly closer to the wall past an opponent than the one he's supposed to be near. He could end up sending scouts continually to their deaths and get stuck in a loop. Can you account for that, and fix it?
---
As for converting an AI from OTA, it might work, except we're building the AI command and control structure from the ground up.
---
As for converting an AI from OTA, it might work, except we're building the AI command and control structure from the ground up.
Well while I was writting that I was coughing and wheezing and tryign to stop myself puking up every 10 minutes. Yah I'd say the LOS code needs a major re-update aswell as factoring in threats.
Oooo swarm. Anyways the Engine interface si C++ dll, and yes there are many more C++ users than java and if you look closely Java and C++ have identical structures for the most part though not all identical. But one thign is Java can eb written and ran from plain text files, it is an interpreted language. C++ is a compiled language. I want to eb able to have a fodler full of files rather than a single large dll, though there will eb a dll to go between the engine and the Java. Perhaps instead of releasing a whole dll I could release a replacement text file or add files. I could create addons in notepad and add them in. Meanwhile I could find the point I needed to add them code it in and compile then replace the dll with the new dll then restart spring. I cant make my code change itself dynamically either without requiring a built in compiler.
Anyways time to change some of the pseudocode, and yah ti is C++ not java btu only because more people are familiar with c++.
Oooo swarm. Anyways the Engine interface si C++ dll, and yes there are many more C++ users than java and if you look closely Java and C++ have identical structures for the most part though not all identical. But one thign is Java can eb written and ran from plain text files, it is an interpreted language. C++ is a compiled language. I want to eb able to have a fodler full of files rather than a single large dll, though there will eb a dll to go between the engine and the Java. Perhaps instead of releasing a whole dll I could release a replacement text file or add files. I could create addons in notepad and add them in. Meanwhile I could find the point I needed to add them code it in and compile then replace the dll with the new dll then restart spring. I cant make my code change itself dynamically either without requiring a built in compiler.
Anyways time to change some of the pseudocode, and yah ti is C++ not java btu only because more people are familiar with c++.
- [K.B.] Napalm Cobra
- Posts: 1222
- Joined: 16 Aug 2004, 06:15
- [K.B.] Napalm Cobra
- Posts: 1222
- Joined: 16 Aug 2004, 06:15
... java is bytecode, there's no such thing as 'normal bytecode'. if you mean like C++ then that's compiled into binary, yes. java is NOT a script (as in interperated language), there's javascript but that's not really related to java at all... and yeah to me that looks like a mix of pseudo code and C++
- [K.B.] Napalm Cobra
- Posts: 1222
- Joined: 16 Aug 2004, 06:15
Well here's an ai I've sorta been working on, i have no idea whether or not it will work, but hopefully one of the sy's will point out my mistakes.
It is supposed to make any peeper turned "on" go to the center of the map and scout in ever increasing squares...
It is supposed to make any peeper turned "on" go to the center of the map and scout in ever increasing squares...
Code: Select all
#define START 1
#define MOVINGTOCENTER 2
#define SCOUTING 3
class CGroupAI : public IGroupAI
{
public:
CGroupAI();
virtual ~CGroupAI();
virtual void InitAi(IGroupAiCallback* callback);
virtual bool AddUnit(int unit);
virtual void RemoveUnit(int unit);
virtual void GiveCommand(Command* c);
virtual const vector<CommandDescription>& GetPossibleCommands(){return commands;};
virtual int GetDefaultCmd(int unitid);
virtual void CommandFinished(int squad,int type){};
virtual void Update();
struct UnitInfo{
int id;
int status;
int stage;
int substage;
};
int numunits=0;
float3 centre;
UnitInfo myUnits[10000];
vector<CommandDescription> commands;
IGroupAiCallback* callback;
};
CGroupAI::CGroupAI()
{
lastUpdate=0;
}
CGroupAI::~CGroupAI()
{
for(map<int,UnitInfo*>::iterator ui=myUnits.begin();ui!=myUnits.end();++ui)
delete ui->second;
myUnits.clear();
}
void CGroupAI::InitAi(IGroupAiCallback* callback)
{
this->callback=callback;
}
bool CGroupAI::AddUnit(int unit)
{
const UnitDef* ud=callback->GetUnitDef(unit);
if(!ud->UnitName=="ARMPEEP")
{
callback->SendTextMsg("Can only use peepers",0);
return false;
}
UnitInfo* info=new UnitInfo;
info.id=unit;
const std::vector<CommandDescription>* cd=callback->GetUnitCommands(unit);
for(std::vector<CommandDescription>::const_iterator cdi=cd->begin();cdi!=cd->end();++cdi)
{
if(cdi->id==CMD_ONOFF)
{
int on=atoi(cdi->params[0].c_str());
if(on)
info->turnedOn=true;
else;
info->turnedOn=false;
break;
}
}
info->centercoords.x=(callback->GetMapWidth())/2;
info->centercoords.z=(callback->GetMapHeight())/2;
myUnits[unit].status=MOVETOCENTER;
Command c;
c.params=center;
c.id=CMD_MOVE;
return true;
}
void CGroupAI::RemoveUnit(int unit)
{
delete myUnits[unit];
myUnits.erase(unit);
numunits--;
}
void CGroupAI::GiveCommand(Command* c)
{
}
int CGroupAI::GetDefaultCmd(int unitid)
{
return CMD_STOP;
}
void CGroupAI::CommandFinished(int unit, int type)
{
int ref;
float3 newcoords;
Command c;
for(int i=0;i<numunits;i++)
{
if(myUnits[i].id==unit);
{
ref=i;
}
}
if(myUnits[ref].status==MOVETOCENTER)
{
myUnits[ref].status=SCOUTING;
myUnits[ref].substage=0;
}
if(substage==0)
{
myUnits[ref].stage++;
myUnits[ref].substage++;
newcoords.x=centercoords.x-myUnits[ref].stage;
newcoords.z=centercoords.z-myUnits[ref].stage;
}
else if(substage==1)
{
myUnits[ref].substage++;
newcoords.x=centercoords.x+myUnits[ref].stage;
newcoords.z=centercoords.z-myUnits[ref].stage;
}
else if(substage==2)
{
myUnits[ref].substage++;
newcoords.x=centercoords.x+myUnits[ref].stage;
newcoords.z=centercoords.z+myUnits[ref].stage;
}
else if(substage==3)
{
myUnits[ref].substage=0;
newcoords.x=centercoords.x-myUnits[ref].stage;
newcoords.z=centercoords.z+myUnits[ref].stage;
myUnits.stage++
}
c.id=CMD_MOVE
c.params=newcoords;
callback.GiveOrder(myUnits[ref].id, &c);
}
void CGroupAI::Update()
{
}
Ah and thou hast released where oen thought thou said he would not.
Anyways for th emost part the first releases of TAI will be C++ anyways as a single dll as wont be arsed with Java interface, though being a winsocks interface I dont see why perl python C++ x86 asm or any other language capable of sockets could be used, and it does give an extensibility to the AI, hence if you dont have the resources to run the AI you can just run it on another computer by itself as long as there's a sockets connection.
Anyways for th emost part the first releases of TAI will be C++ anyways as a single dll as wont be arsed with Java interface, though being a winsocks interface I dont see why perl python C++ x86 asm or any other language capable of sockets could be used, and it does give an extensibility to the AI, hence if you dont have the resources to run the AI you can just run it on another computer by itself as long as there's a sockets connection.
Ick
For normal users, both C++ and Java are far too cumbersome. Complex syntax, cumbersome libraries, and slow compile times make both of them inappropriate for user-oriented extension modules.
A far better approach would be to use a language designed for embedding such as Lua.
A far better approach would be to use a language designed for embedding such as Lua.
- PauloMorfeo
- Posts: 2004
- Joined: 15 Dec 2004, 20:53
It's arguable if it is not hard to learn or not.Torrasque wrote:... And C++ is not hard to learn. ...
But one thing i'm sure. It's hard to make anything usefull with it. Only people who are very acustumed to C++ can actually do other stuff than minor programs.
I know BASIC, Pascal, C/C++/C#, Python, SQL and maybe something else i may be forgetting.
C++ is an object oriented language, but to a lesser extent than Java or C#. That is because it is backwards compatible with C, which had no objects or classes, only structs. However, object oriented code is generally easier to modify than non-object oriented code, especially in something large like an AI. Non-object oriented code can be a challenge to keep organized, whereas one can quickly grasp the structure of even mediocre object oriented code. In short language.ObjectOriented==good;
Actually C++ has objects btu ti is officially a 'CLASS ORIENTATED' Besides I said ebfore the reason was that Java is an INTERPRETED language and C++ is a COMPILED Language.
Now as for LUA, explain to em how I can construct an LUA program to use a sockets layer and use classes to create an AI? As far as I am aware LUA is a scripting language and whatsmore it isnt a scripting language interpreted by 80%+ of all computers. There is far greater support for runnign Java than LUA which I know nothign about. Besides can you tell em you can run an LUA AI as a standalone program on another computer usign a sockets connection to control a player in an engien on another computer r will ti ahve to eb directly integrated and developed into the AI engien interface?
Also object orientated code has less redundant code to type out.
And as for C++ being hard to learn and Java too because they sue complex syntax. When I first decided to learn C++ I had doen no programmign before hand and it was all ery new to me. The problems that I encountered where the concepts of pointers and Object orientated programming not the syntax, which i found rather easy and well defined.
As for compile times I am sure tht fi java is a problem we can always go for perl or python but not everyone has that. Of course I've said Java implementation fo the AI command structure would use sockets, and sockets can eb accessed from C++ java perl python x86 asm etc So you can just go create your own command structure or translate mine if your not happy. But then again noughts been finalised as this is a thought process.
Now as for LUA, explain to em how I can construct an LUA program to use a sockets layer and use classes to create an AI? As far as I am aware LUA is a scripting language and whatsmore it isnt a scripting language interpreted by 80%+ of all computers. There is far greater support for runnign Java than LUA which I know nothign about. Besides can you tell em you can run an LUA AI as a standalone program on another computer usign a sockets connection to control a player in an engien on another computer r will ti ahve to eb directly integrated and developed into the AI engien interface?
Also object orientated code has less redundant code to type out.
And as for C++ being hard to learn and Java too because they sue complex syntax. When I first decided to learn C++ I had doen no programmign before hand and it was all ery new to me. The problems that I encountered where the concepts of pointers and Object orientated programming not the syntax, which i found rather easy and well defined.
As for compile times I am sure tht fi java is a problem we can always go for perl or python but not everyone has that. Of course I've said Java implementation fo the AI command structure would use sockets, and sockets can eb accessed from C++ java perl python x86 asm etc So you can just go create your own command structure or translate mine if your not happy. But then again noughts been finalised as this is a thought process.