Page MenuHomeWildfire Games

Petra: fix a case where the AI loose control of its units (they become only driven by UnitAI)
ClosedPublic

Authored by mimo on May 23 2017, 8:51 PM.

Details

Summary

when the AI is attacked, and the attacking units retreat, the AI follows them and them decide at some point to stop and go back to its base. But as the units were chasing the enemies, UnitAI has still the control and make the units continue the chase, usually driven by the retreating enemy up to towers or fortress where they are killed. The patch let the AI really stop the chase.

the patch is not complete though, as the same problem could happen again if the enemy attack again the AI while it is going back to its base, and then retreat again. But that should be another patch.

Test Plan

test in game the AI's behaviour in this situation.

Diff Detail

Repository
rP 0 A.D. Public Repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

mimo created this revision.May 23 2017, 8:51 PM

Nice! I will test.

Vulcan added a subscriber: Vulcan.May 23 2017, 10:15 PM

Build is green

Executing section Default...
Executing section Source...
Executing section JS...
Executing section Python...
Executing section Perl...

http://jw:8080/job/phabricator_lint/23/ for more details.

Build is green

Updating workspaces.
Build (release)...
Build (debug)...
Running release tests...
Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK!
Running debug tests...
Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK!

http://jw:8080/job/phabricator/1331/ for more details.

Sandarac requested changes to this revision.May 24 2017, 4:14 PM

It will be good to have these improvements to Petra's behavior towards "kiting" :)

binaries/data/mods/public/simulation/ai/petra/army.js
284 ↗(On Diff #2157)

Maybe defensive structures should be favored?

329 ↗(On Diff #2157)

This won't work as there should be a check for plan === -2 || plan === -3 to see if the ent is already garrisoned, or errors could happen in the garrisonManager.

binaries/data/mods/public/simulation/ai/petra/defenseManager.js
686 ↗(On Diff #2157)

Maybe for symmetry with the other garrison... functions in the defenseManager, they could also return bools as well (it is not a big thing).

This revision now requires changes to proceed.May 24 2017, 4:14 PM
mimo updated this revision to Diff 2179.May 24 2017, 9:16 PM
mimo edited edge metadata.
mimo edited the summary of this revision. (Show Details)

fix sandarac comments

binaries/data/mods/public/simulation/ai/petra/army.js
284 ↗(On Diff #2157)

ok now it is the nearest defensive if any, otherwise nearest one

329 ↗(On Diff #2157)

You are right, i should have done the removeOwn before. Now fixed

binaries/data/mods/public/simulation/ai/petra/defenseManager.js
686 ↗(On Diff #2157)

ok now done

Build is green

Executing section Default...
Executing section Source...
Executing section JS...
Executing section Python...
Executing section Perl...

http://jw:8080/job/phabricator_lint/39/ for more details.

Build is green

Updating workspaces.
Build (release)...
Build (debug)...
Running release tests...
Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK!
Running debug tests...
Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK!

http://jw:8080/job/phabricator/1349/ for more details.

I have noticed something else. When territory boundaries are close, it can happen that units can get stuck in a loop between retreating to the nearest structure and moving out towards enemy units, and this results in jerky movements for the units back and forth (It's kind of hard to explain). Maybe there needs to be a threshold set up with metadata or something (I'm not entirely sure).

mimo added a comment.May 25 2017, 5:14 PM

I have noticed something else. When territory boundaries are close, it can happen that units can get stuck in a loop between retreating to the nearest structure and moving out towards enemy units, and this results in jerky movements for the units back and forth (It's kind of hard to explain). Maybe there needs to be a threshold set up with metadata or something (I'm not entirely sure).

Do you have a replay exhibiting this problem? i was afraid this could happen, and thought that maybe switching to another stance (defensive or standground) while retreating could help. But i need to test it.

I believe it may happen in this one, for player 4 in particular.

mimo added a comment.May 25 2017, 6:39 PM

I believe it may happen in this one, for player 4 in particular.

Could you be more explicit? this replay has 24000 turns, and watching such a long game to catch a unit jerking is too much for me. Do you know approximately the turn number, otherwise if it happens again, the simpler is to save a game when this happen and upload it here. I've tried several times on my side, and could not reproduce it.

In D545#22430, @mimo wrote:

Could you be more explicit? this replay has 24000 turns, and watching such a long game to catch a unit jerking is too much for me. Do you know approximately the turn number, otherwise if it happens again, the simpler is to save a game when this happen and upload it here. I've tried several times on my side, and could not reproduce it.

Sorry, I'm not very familiar with how replays are used for ai debugging for things like this (I don't believe there are any relevant docs/wiki). It was around turn 400, but this sort of thing may be rare if you could not reproduce it. There weren't any other issues I noticed from this patch.

mimo added a comment.May 25 2017, 9:27 PM

OK then could you accept it, and i'll commit it in that state. We can always improve it later when somebody provide a way to reproduce such problems.

Sandarac accepted this revision.May 25 2017, 9:49 PM
In D545#22497, @mimo wrote:

We can always improve it later when somebody provide a way to reproduce such problems.

Sure.

This revision is now accepted and ready to land.May 25 2017, 9:49 PM
This revision was automatically updated to reflect the committed changes.

Here is an example when enemy structures are close to the AI's territory, maybe there needs to be a check for structure, the units will get stuck in a loop indefinitely; there are three enemy houses below the civic center:

mimo added a comment.EditedMay 30 2017, 9:30 PM

Here is an example when enemy structures are close to the AI's territory, maybe there needs to be a check for structure, the units will get stuck in a loop indefinitely; there are three enemy houses below the civic center:

Thanks for the report. It seems rather a problem with rP19547?
see D579