



Moderators: hoijui, Moderators
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...
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.
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.