Jump to content

Recommended Posts

I can't really help you with the coding (well, I could, but I'm on a mac and unable to start the game (I really don't have the skills required), so it would'nt be fun), but here are some guidances:

-It's not a bad thing to give the AI a specific to-do list early on(such as : until 2 minutes, food, until 4 minutes, food and wood, and do this and that). The human players usually do just that, and it might make it easier to code the AI.

-If the AI is to build towers (and walls if there are in-game), it should know where to properly place them. For walls, it's really a matter of determining what is important and what to protect and build a nice circle around it, but towers are a more strategic matter. It should not clutter more than 2 towers in one area (2 towers are more efficient than one at keeping at bay attacks, but 3 usually is overkill). It should spread the towers so that they share less than 25% of firing range, but there is no hole in "tower coverage" (otherwise it's just too easy for the player to go through).

Ultimately, it should try to learn where enemy attacks are coming from and build one or two more towers there. That's not that hard to do, I think, and it's a pretty great AI response.

Some graphics to illustrate the towers issue:

Bad positioning ( red is the "tower coverage", stars are towers, blue is the sea, sand is ground )

Better positioning.

-Giving the ai some "soft-coded" behaviours depending on the map is pretty useful too, along with giving the AI rush/boom/turtling strategies.

Some other topics that you might consider adding:

-Clever AI, if a lot of space is available, could build houses scarcely. It makes it harder to destroy them all and crash the AI population cap. Or it could build small clutters of 3/4 houses.

-Military buildings should be built in priority closer to the enemy position. Economic buildings should be built farther to protect them.

-On the same topic, the AI could build "outlooks", that is a single tower far toward the enemy to know about attacks earlier.

-For AI attacks, the shortest path is rarely the best. It is much better to alternate between "straight line" attacks and attacks from the side or even the rear if possible.

-AI soldiers could be divided into categories. A "guard" section with some solid defensive units, a "raid" section that harasses the enemy (though they must have some clever attack strategies to work), etc.

-Micromanagement of units during attack can be the difference between success and failure, I dunno if it already does that but it could be a good improvement far harder AIs.

-Again on the "AI response to the player": if the AI attacks, and it sees the player has built numerous towers and walls, it should try to find another attack path, and if there is none, it should note that for further attacks siege engines are required.

That's all I can think of right now.

Link to comment
Share on other sites

  • Replies 84
  • Created
  • Last Reply

Top Posters In This Topic

about revision 9012:

Stop units wasting their lives chasing animals they'll never be able to catch.

Let AI players collect treasures.

In Death Canyon ( on latest build), I couldnt notice these changes ( unless it needs an automated build). about 10 enemy females were chasing a goat in a straight line, quite a funny sight actually :banana:

Link to comment
Share on other sites

They can catch goats - it just takes a long time :). Goats only run once they're attacked, then stop soon after, so their hitpoints go down (by a tiny bit) every time someone catches up with them and hits them, and eventually they'll be defeated. r9012 just changed the behaviour towards skittish animals like gazelles, which run whenever someone is getting close (i.e before anyone can get close enough to actually hurt them).

(Probably the AI ought to use combat units to hunt anything larger than a chicken, and let the female citizens collect the meat afterwards, but that requires more sophistication than the AI is currently capable of.)

Link to comment
Share on other sites

  • 2 weeks later...

Where are the AI scripts? I'm quite keen to have a tinker, but I'm not sure where to find what I'm meant to be tinkering with.

EDIT: Dw, found 'em. Can I use all normal Javascript functions in this? (Say, Math.random and Math.floor for example). Also, the military page seems to be set up to train a mix of javelinists and spear inf. Can anyone tell me why it only makes spearmen in practice?

Edited by Jubalbarca
Link to comment
Share on other sites

They are in: binaries\data\mods\public\simulation\ai (if you're running a release though the files will be in a public.zip file in the mods/public directory, so in that case you'll have to extract that file to that directory, most ZIP/Unzip programs should have an option to e.g. "Extract here" which should get all the content in the right place. I'll leave it to one of the programmers to say what's best in terms of whether or not to keep the zip file, and whether it's better to just extract the needed directory or to extract it all, but there should be no harm in doing that, and I think the extracted files should have priority over the ones in the zip file, so there should be no problem leaving it after you've extracted the contents.).

EDIT: Oh, you've found them :) I'll let the above remain though in case someone else doesn't know where to find them :)

Link to comment
Share on other sites

This code is intended to train a 10 spearman defense force (the "defenders" role does nothing, it's just there as a placeholder really) as top priority, then cycle round spears then javelins. Depending on a strategy which is chosen at random, it then either counts to ten and sends a raiding force or forty for a full-on assault.

Almost needless to say, this does not happen. The defense force is generally larger than it should be, and once it is trained the attack forces are entirely made of javelinmen. It also seems to do a lot more full-scale assaults than probability would dictate. I'm not sure if after it goes onto training javelins it will then go back to training defenders if I kill some, though it should do in theory. Any help much appreciated...


var MilitaryAttackManager = Class({

_init: function()
{
this.targetSquadSize = 20;
this.findatype = 1;
this.squadTypes = [
"units/{civ}_infantry_spearman_b",
"units/{civ}_infantry_javelinist_b",
// "units/{civ}_infantry_archer_b", // TODO: should only include this if hele
];
},

/**
* Returns the unit type we should begin training.
* (Currently this is whatever we have least of.)
*/
findBestNewUnit: function(gameState)
{
// Count each type
var types = [];
for each (var t in this.squadTypes)
types.push([t, gameState.countEntitiesAndQueuedWithType(t)]);

// Sort by increasing count
types.sort(function (a, { return a[1] - b[1]; });

// TODO: we shouldn't return units that we don't have any
// buildings capable of training
// Let's make this shizz random...
var randomiser = Math.floor(Math.random()*types.length);
return types[0][0];
},

update: function(gameState, planGroups)
{
// Pause for a minute before starting any work, to give the economy a chance
// to start up
if (gameState.getTimeElapsed() < 60*1000)
return;

Engine.ProfileStart("military update");
// Also train up some defenders
var pendingdefense = gameState.getOwnEntitiesWithRole("defenders");
if (pendingdefense.length <= 10){
planGroups.economyPersonnel.addPlan(110,
new UnitTrainingPlan(gameState,
"units/{civ}_infantry_spearman_b", 5, { "role": "defenders" })
);
}
// Continually try training new units, in batches of 5
//planGroups.militaryPersonnel.addPlan(100,
// new UnitTrainingPlan(gameState,
// this.findBestNewUnit(gameState), 5, { "role": "attack-pending" })
//);
//this.chat("Hmm, let's pick a number. I think " + findatype + " sounds good.");
if (this.findatype == 1){
planGroups.economyPersonnel.addPlan(100,
new UnitTrainingPlan(gameState,
"units/{civ}_infantry_spearman_b", 5, { "role": "attack-pending" })
);
this.findatype = 0;
}
else {
planGroups.economyPersonnel.addPlan(100,
new UnitTrainingPlan(gameState,
"units/{civ}_infantry_javelinist_b", 5, { "role": "attack-pending" })
);
this.findatype = 1;
}

// Find the units ready to join the attack
var pending = gameState.getOwnEntitiesWithRole("attack-pending");
// Variable for impetuousness, so squads vary in size.
if (this.killstrat == 1){
this.baserate = 41;
}
else {
this.baserate = 11;
}
// If we have enough units yet, start the attack
if (pending.length >= this.baserate)
{
// Find the enemy CCs we could attack
var targets = gameState.entities.filter(function(ent) {
return (ent.isEnemy() && ent.hasClass("CivCentre"));
});

// If there's no CCs, attack anything else that's critical
if (targets.length == 0)
{
targets = gameState.entities.filter(function(ent) {
return (ent.isEnemy() && ent.hasClass("ConquestCritical"));
});
}

// If we have a target, move to it
if (targets.length)
{
// Remove the pending role
pending.forEach(function(ent) {
ent.setMetadata("role", "attack");
});

var target = targets.toEntityArray()[0];
var targetPos = target.position();

// TODO: this should be an attack-move command
pending.move(targetPos[0], targetPos[1]);
}
//Now set whether to do a raid or full attack next time
var whatnext = Math.random();
if (whatnext > 0.25){
this.killstrat = 0;
}
else {
this.killstrat = 1;
}
}

Engine.ProfileStop();
},

});

Link to comment
Share on other sites

  • 2 weeks later...

A few suggestions for improving TestBot and the AI system generally (including UnitAI):

  • Resource collectors will walk all the way across the map to find the nearest resource of the type they want, even if that's in an enemy base! I can't think of many situations where this is a good idea:
    • It takes a long time to reach the destination and by that time the target resource is often gone anyway.
    • Some resources just aren't important enough to risk losing villagers, for example berry bushes. It's quite simple to acquire food by other means.
    • How does the AI know there are resources far away? I think we want to restrict their "knowledge" of the world to what they've actually explored. So the AI will need to "scout".

    [*]If resources are far away from the base, build a drop site (mill or farmstead).

    [*]Soldiers can work too, so if they're not otherwise employed, they should collect resources and construct military buildings.

    [*]Units are able to become "deadlocked" in a few ways I've noticed:

    • If many workers are assigned to construct a new building, others that are passing by may end up stuck while standing on top of the foundation, possibly being told to clear off by the UnitAI but refusing because they have other orders. Maybe we need to prioritize the orders.
    • There should be a timeout so that if a unit can't accomplish an order in a certain time, they give up or wait for a while.
    • If there's a narrow pass and units are going to and fro in opposite directions, they might by chance block each other and constantly try to move in avoidance, but they seem to mirror each other. This is oddly similar to RL behavior but we should probably be smarter than this ;)

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share


×
×
  • Create New...