AI MapHack!
Moderators: hoijui, Moderators
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.
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.
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!
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!
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:
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:
Hmm I should have made this earlier
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...
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.
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
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
Send me a PM if you're interested.
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
Send me a PM if you're interested.
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....
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....
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...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.
- Targ Collective
- Posts: 202
- Joined: 12 Nov 2005, 14:16
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.
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.