Jump to content

A challenger appears : Marilyn (Yet-yet another AI)


Recommended Posts

There is certainly space to simplify my code, even without any API changes... I've modified stuffs from qBot while not necessarily removing them, changed things, made some pretty idiotic design choices now and then (It's now changed, but I asked the "game" for the entity associated with an ID... By asking said entity to give its ID. In other words, I asked for informations I already had while using it).

I'll try to clean the code, to remove most errors, and to optimize the code for the next version... I'm currently cutting the map into smaller squares for the economy manager so it won't have to loop through every resource on the map each time it wants to assign a unit a task... It's working much faster (on Gambia river, a forest-ridden map, it's at least twice faster for each unit, so it's quite quickly 5 or more times faster), but it demands quite serious code change.

Edited by wraitii
Link to comment
Share on other sites

Allright, I've decided to upload this newer version a bit early, mainly because it's fairly interesting... The main feature is speeding up of the "reassignIdleWorker" function, by dividing the map into subsquares and looking in those. It's really much much faster on maps where there are tons of trees involved. On Gambia River, this newer version is easily 5 times as fast as qBot, sometimes more. There doesn't seem to by any bug left, though if you notice any "dodgy" behavior in the "looking for resources" area, let me know.

Other things I did: clean up of the code, I removed many unused functions that were left-overs from qBot or early development... Actually implemented garrisoning citizens in case of major attacks. I did a lot of fairly small "sanity checks" that should remove most of the "error: whatever is undefined" errors, though I'm not sure I got them all. Fixed a little bug that could happen on some map with houses.

(BTW: qBot should have a check in "accessibility". If the "start" point is undefined, there's an error).

So now I can start the more interesting stuff, such as actually adding features.

Download Link

Edit: bug noticed thanks to Pureon. It's not a gamebreaker but you'll get a ton of error messages if you garrison a soldier:

Fix: line 378 of defence.js, add:

if (enemy.position() == undefined)  // unit is likely garrisoned. DO not check.
continue;

Line 428 of "attack_city.js"

if (enemy.position() == undefined) // likely garrisoned
continue;

In defence.js, line 200, replace the if condition by this one:

if (enemy.owner() == ennemiPotentiel.owner() && enemy.id() !== ennemiPotentiel.id() && enemy.position() !== undefined)

Edited by wraitii
Link to comment
Share on other sites

To notice the speed improvement, you'd have to check the profiler on time warp. It becomes very obvious then (otherwise, this function is called once every 10 turn so it's not that noticeable)

These errors are very weird... Apparently, enemy units that are supposed to exist don't. I see absolutely no reason why... Any particular action that was happening when you got those (attacking marilyn, destroying her?)

The warnings are "normal" debug warnings, though, you can turn it off in "Marilyn.js".

Link to comment
Share on other sites

These errors are very weird... Apparently, enemy units that are supposed to exist don't. I see absolutely no reason why... Any particular action that was happening when you got those (attacking marilyn, destroying her?)

Sorry, nothing obvious - I was still expanding my economy at the time, hadn't even scouted out the AI's base when the errors (not warnings) began appearing. Maybe around 10 minutes into the match.

Link to comment
Share on other sites

These errors are very weird... Apparently, enemy units that are supposed to exist don't. I see absolutely no reason why... Any particular action that was happening when you got those (attacking marilyn, destroying her?)

If you're dealing with positions, there are several reasons why it might be undefined. The target could be garrisoned, dead, or training in progress (created but not yet spawned). Basically you want to check the position is not undefined before using it, as early as possible so the errors don't propagate all over the place. I think this should be added as a helper function for AIs.

Link to comment
Share on other sites

Mmmh, I forgot about garrisoning making the position undefined, this must be it because there's no way the units that are sorted by this function are dead. I'll give it a try.

(What's fun is that I really, authentically suck at this game, so I never try to garrison anything. I'm even unable to defeat my own bot.)

edit: Yup, garrisoning a soldier makes it go mad because I completely forgot about that possibility. Easy fix.

Anyone else tried playing around a bit?

Fix: line 378 of defence.js, add:

if (enemy.position() == undefined)  // unit is likely garrisoned. DO not check.
continue;

Edit: actually elsewhere too, I'll continue to playtest with some garrisoned units to see if there's any other spot.

Line 428 of "attack_city.js"

if (enemy.position() == undefined) // likely garrisoned
continue;

Edit^2: darn, also in defence.js, line 200, replace the if condition by this one:

if (enemy.owner() == ennemiPotentiel.owner() && enemy.id() !== ennemiPotentiel.id() && enemy.position() !== undefined)

Edited by wraitii
Link to comment
Share on other sites

What's fun is that I really, authentically suck at this game, so I never try to garrison anything. I'm even unable to defeat my own bot.

One of the easiest ways to defend against an AI is to garrison your citizen soldiers in a fortress/tower.

I quite possibly did garrison a unit just before the errors appeared - it had been attacked by a leopard and needed healing :D

Link to comment
Share on other sites

I can tell you with 100% certainty that you have indeed garrisoned a unit right before the unit appeared :) .

Okay, so since that seems to be taken care of, I'll now proceed to try to actually add stuff. I've already made the AI stop changing its workers of task every minute, so it behaves more humanly (and efficiently)

Edited by wraitii
Link to comment
Share on other sites

He has done a few modifications, but nothing fundamentally different, I think.

I'm not sure what you mean by your second question, could you rephrase it?

I've finished updating my attack plans to allow for more precise unit construction (archers, javelins and not only "ranged"), planning for raids. It was a bit of a pain, but it works.

Link to comment
Share on other sites

Okay, yay new version.

Actual improvements this time around:

-Attack plans are better, and I implemented a "raid the villagers" type of attack... It's much of a work in progress, like the attack plans in general (this is really the one area that's freakin' hard to implement... No wonder most AIs use "create an army and send it to enemy base" as a means of attacking.). Though not all civilizations will benefit from it (It uses cavalry swordsman, and I think only hellenes have an early access to those. It'll be changed in the next version). Test it out on Oasis.

-Attack plans are now started if the "maximum" amount of units are built.

-Generally more efficiency during attacks for attack plans and defense.

-gatherers should generally stay on their resource for longer, ie the AI will change their task less often.

-Queue manager changed again: more readable, more efficient, more modular (individual plans can be set as "most important"). Generally better and more efficient.

Technical stuff:

-Attack plans use their own queues, and generally rewrote those a lot. More modular now.

-Cleaned up the code further

-In the "reassignIdleWorker", it checks if they did something before and puts this as the top priority. This is good: workers will change tasks less often.

-Tactics can now split and regroup groups after initialization.

I'm not 100% sure every new stuff is bug free, but I playtested it fairly thoroughly, so it should work. Report any bug you encounter, as well as any weird AI reaction.

Download Link

Edit: darn ,still a problem I left over with garrisonning... Replace line 285 of "mil-Tactics.js" by this:

if (!entity || !entity.position())

And line 279 also needs to be changed to this:

if (!unit || (unit && !unit.position()) ){

Speed improvements over the economic manager are a bit countered because of the modifications to attack plans, but overall on "time warp" it's still faster than qBot on my computer.

Edited by wraitii
Link to comment
Share on other sites

Is this AI deterministic, in the sense that if the player will play (theoretically) twice exactly the same, then the AI will react exactly the same?

I was just thinking, if you have a modular queue manager, you can arrange the queue with a precise formula that will consider all the input to produce the perfect output, but you can make it adaptable, so it will learn during the game (or between games).

Am I making sense or is it a completely different thing?

(Sorry to burst in like that :P )

Link to comment
Share on other sites

@Gameboy: I doubt qBot is causing the game lag, probably just your hardware.

Definitely not true. Currently, if you play with AI, it will cause lag. If the lag isn't bad from the beginning of the game, it'll only get worse as the game progresses, since the AI is trying to control more and more of the units it's created.

Link to comment
Share on other sites

Is this AI deterministic, in the sense that if the player will play (theoretically) twice exactly the same, then the AI will react exactly the same?

I was just thinking, if you have a modular queue manager, you can arrange the queue with a precise formula that will consider all the input to produce the perfect output, but you can make it adaptable, so it will learn during the game (or between games).

Am I making sense or is it a completely different thing?

You're certainly making sense, but I do not have the skills to make it "non-deterministic". I'm not sure there is a point either. I think the AI in AoE3 is a bit what I'm trying to achieve : deterministic, but able to store a few things (such as "when the player attacked") and sort of react to that. Optimally, I'd like to be able to do that and better, but I'm unsure I have the skills required (I'm not a real programmer... Hell, I'm not even a programmer at all, I'm studying economics.)

I also have very little idea of what the team wants for their AI, though seeing what was already achieved, I think my ideas are not that faraway from theirs.

@Zaggy1024 : indeed.

Edited by wraitii
Link to comment
Share on other sites

I got beat by Marilyn! Playing Oasis I as the persians against Marilyn as Hellenes (Alpha 8 since i had some troubles getting the last version from the svn). I'm not very good a player, but i have to say it really surprised me to see this AI in action. She detected my attacks and sent defense before i could even see one of her buildings (does she ignore the fog of war?). At the last minutes, i packed some skirmishers and archers to scort the rams and noticed she gone for the first units of the formation, leaving the rams free to go for the civ centre, even though when i hit the civ centre she sent a small pack of melee soldiers to bring my rams down. She didn't exactly got me beat, but after she broke my army, i resigned.

Great work, wraitii, i think this is the way to go.

Link to comment
Share on other sites

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...