AI MapHack!

AI MapHack!

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

Moderators: hoijui, Moderators

User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

AI MapHack!

Post by krogothe » 20 Nov 2005, 19:19

:lol: :lol: :lol: :lol:
Last edited by krogothe on 07 Dec 2005, 17:41, edited 1 time in total.
0 x

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

Post by jcnossen » 20 Nov 2005, 19:34

AI's are already doing something similar, only split up in multiple arrays to save data and speed up. For example there is the metal map that everyone is using, JCAI used to have a map with "scores" for a while, and a 2d array to store occupation of buildings on, a 2d array to store various gamestate such as enemy firepower....

My point is, there is no reason to put all data into one big array. You can better seperate things and make various arrays that are scaled up for a particular job. It's a good programming habit to split tasks up, and so it's logical to also split up the data that is used by these tasks/processes.
0 x

User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Post by krogothe » 21 Nov 2005, 00:07

Actually the Array would be 3 dimensional:

float Score [x][y][typeofscore] = some function

or yes i could make a load of 2d arrays. Some functions however will use combined scores from different things (eg placing a far away resource building like a geo or mex will check against the threat array). The best way would probably be how you suggested since conservative calculations are giving me an array size of over a megabyte already!
I read the source for JCAI and absolutely loved that function to create a TGA picture with the maps. that could be expanded into a realtime PIP map (like the radar), where you can switch the score type displayed using the debugger.
Since the TGA maker would be a simple function that could be reused that is definitely something i want to try!
I need to make a proper, concrete design plan for the whole AI now. I will be an able enough programmer within a couple of days and it is getting quite complex. I shall expand on this idea later!
Thanks for the tip Zaph it does make sense!
0 x

User avatar
Triaxx2
Posts: 422
Joined: 29 Aug 2004, 22:24

Post by Triaxx2 » 21 Nov 2005, 01:26

Why not have a single, expungable 3D array, that is generated only when it's needed, and pulls data from the various 2D array's?
0 x

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

Post by jcnossen » 21 Nov 2005, 01:57

If you're talking about visualization, use the debug window code in JCAI. Type .debugwindow in game to show what it does...

If you need to have a generic scoring function for these 2D arrays, then it is better to use templates than to put everything in one array. I already started to use something similar in JCAI:

Code: Select all

	template<typename HF> int2 SelectGameInfoSector (HF hf)
	{
		float bestscore;
		int2 best (-1,0);

		for (int y=0;y<gsh;y++)
			for (int x=0;x<gsw;x++)
			{
				GameInfo& i=gameinfo[y*gsw+x];
				float score = hf(x,y,i);
				if (best.x < 0 || bestscore < score)
				{
					best=int2(x,y);
					bestscore=score;
				}
			}
		return best;
	}
Now you can write a function:

float GetSectorScore (int  x,int y,GameInfo& i) {
  return i.EnemyValue / i.EnemyPower;
}

or something...

You could argue that this is also possible with a function pointer, but now I can use boost::bind on it...
There are probably better ways to do this, I never spend much time on it, but my point is that there are a lot of ways (and using templates is a very nice one of them) to implement a flexible or generic algorithm into C++.

You could make a template like this:

Code: Select all

template<typename ElemType, int bw, int bh>
class StateMap 
{
public:
  enum { BlockW=bw, BlockH=bh };
  ElemType& Get (int x,int y) { 
   return blocks[(y/BlockH)*w+x/BlockW]; 
  }

  template<typename OtherStateMap>
  ElemType& GetFromOtherStateMapCoords(OtherStateMap &other, int x, int y) {
    int rx = x * OtherStateMap::BlockW;
    int ry = y * OtherStateMap::BlockH;
    return Get(rx,ry);
  }

  int w,h;
  ElemType *blocks;
};

Which you can use like:

StateMap<EnemyInfo, 32,32> enemyInfoMap;
StateMap<MetalInfo,64,64> metalInfoMap;

MetalInfo& mi = metalInfoMap.GetFromOtherStateMapCoords (enemyInfoMap, 3, 5);

// now mi points to the metal info element on (3,5) on the enemyinfo map.
Hmm I should have made this earlier ;)
0 x

b1ind
Posts: 48
Joined: 21 Apr 2005, 04:01

Post by b1ind » 21 Nov 2005, 07:49

OT: What is the need for the enum in there? Is that the only way you can assign default values to members?
0 x

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

Post by jcnossen » 21 Nov 2005, 12:46

I think you can do it with a constant as well, but then the linker also starts messing with it. I prefer to do it with an enumerator...
0 x

User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Post by krogothe » 21 Nov 2005, 18:05

:lol: :lol: :lol:
Last edited by krogothe on 07 Dec 2005, 17:43, edited 1 time in total.
0 x

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

Post by jcnossen » 21 Nov 2005, 18:42

The statemap template allows you to use maps of different resolutions and compare their values quickly without having to code all the position scaling... sorry if it was a little offtopic, it was a nice idea that I suddenly had to implement :wink:

For pathfinding you might want to look into Dijkstra's algorithm, it allows pathfinding for a single goal and many units so to say... probably very useful when the AI needs to brake through the weakest defenses

If you want to test your energy calculations, you could use JCAI as a base. I never had the time or motivation to make good calculations for the resource "curve", but the framework is there... Look into ResourceUnitHandler.cpp, it's generates the tasks for resource buildings, and if you replace that with your own you can have results very soon... this would be a win-win situation :wink:
Send me a PM if you're interested.
0 x

User avatar
AF
AI Developer
Posts: 20667
Joined: 14 Sep 2004, 11:32

Post by AF » 21 Nov 2005, 20:16

After that i dunno if this would eb of any use.

See the gridmanager clas sin NTAI. It isnt being sued and I had a few extras to add, btu ti let you save values in matrixes of different resolutions and had a few methods to do thgins sucha s icnrease all values in the grid by a percentage and draw TGA etc....
0 x

User avatar
Veylon
AI Developer
Posts: 174
Joined: 21 Sep 2005, 19:45

Post by Veylon » 29 Nov 2005, 21:16

I've done alright with managing energy and metal.

Just make sure the AI doens't build anything unaffordable and no Building units when metal < 10% or factories when metal < 50%. That's about all the rules I've needed.
0 x

User avatar
AF
AI Developer
Posts: 20667
Joined: 14 Sep 2004, 11:32

Post by AF » 29 Nov 2005, 21:18

Aha, I thought G->Pl->feasable was a little odd in how it filtered out odd orders.
0 x

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

Post by jcnossen » 30 Nov 2005, 00:55

Just make sure the AI doens't build anything unaffordable and no Building units when metal < 10% or factories when metal < 50%. That's about all the rules I've needed.
And when it is trying to create new build tasks, you look at all the other tasks to determine whether something is affordable I suppose? Might just work for jcai as well I think... :-)
0 x

User avatar
Targ Collective
Posts: 202
Joined: 12 Nov 2005, 14:16

Post by Targ Collective » 30 Nov 2005, 10:37

Too literal. The AI needs to think in terms of income vs. expenditure, and make decisions based on that; not based on stockpiled resources.
0 x

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

Post by jcnossen » 30 Nov 2005, 11:33

Might be, but you're not making an AI... ;)
JCAI "thinks" in terms of income vs expenditure currently, and see what that leads to. Simpler systems can often be more effective, but they have less "side factors" that have to be fulfilled.
You can't calculate everything, you run into high processor usage or not being able to know things precisely... so then the more precise decision making algorithms can screw things up very much. I'm not saying that's the only thing wrong with jcai right now, but it's one of the biggest problems.
Last edited by jcnossen on 30 Nov 2005, 12:59, edited 1 time in total.
0 x

User avatar
BvDorp
Posts: 439
Joined: 14 Oct 2005, 12:09

Post by BvDorp » 30 Nov 2005, 12:24

Zaphod, I see u talking about JCAI again... why not make some brilliant version to show the others how it must be done? :twisted:

Just kidding you here.. But I see you suggesting some features etc, y not implent them?
0 x

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

Post by jcnossen » 30 Nov 2005, 12:59

Because other things are have a higher priority.
0 x

User avatar
AF
AI Developer
Posts: 20667
Joined: 14 Sep 2004, 11:32

Post by AF » 30 Nov 2005, 20:11

Such a tradeoff is a sign of a bad approach to the problem.
0 x

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

Post by jcnossen » 30 Nov 2005, 20:42

Whatever
0 x

User avatar
AF
AI Developer
Posts: 20667
Joined: 14 Sep 2004, 11:32

Post by AF » 30 Nov 2005, 20:46

-_-
0 x

Post Reply

Return to “AI”