Page MenuHomeWildfire Games

[AI] introduce simple kiting
AbandonedPublic

Authored by marder on Mar 30 2022, 11:59 AM.

Details

Reviewers
None
Group Reviewers
Restricted Owners Package(Owns No Changed Paths)
Summary

This is an experiment to introduce a simple form of kiting to the ai.

Since the ai currently has no per turn fine control over what the units do (or at least doesn't do it), this just uses the minimal distance of ranged units to simulate a kiting-like behavior.
So the problem is being outsourced from Petra to UnitAi, but it should lead to a better fighting position for the ai, since the ranged units will more likely walk behind the melee units and therefore be more protected and provide more value.
Also, attacker will be more spread out and spend more time chasing.

Disclaimer: There are now a number of ai mods out there, which all try to improve the ai. I haven't look at any of them, but since this is a minor change, chances are that someone else had the same idea before me, so if someone has done/ used the same thing it is coincidental and I wouldn't mind giving them credit.

Test Plan

Looks for bad edge cases, play a few games on hard / very hard difficulty and see if the ai actually is harder to beat.
Discuss if this is actually an improvement in the behavior.

Event Timeline

marder created this revision.Mar 30 2022, 11:59 AM

Build failure - The Moirai have given mortals hearts that can endure.

builderr-debug-macos.txt
fatal error: fatal errorfile '/Users/wfg/Jenkins/workspace/macos-differential/build/workspaces/gcc/../../../libraries/source/glad/include/glad/gl.h' has been modified since the precompiled header 'obj/graphics_Debug/precompiled.h.gch' was built
: fatal error: fatal error: file '/Users/wfg/Jenkins/workspace/macos-differential/build/workspaces/gcc/../../../libraries/source/glad/include/glad/gl.h' has been modified since the precompiled header 'obj/graphics_Debug/precompiled.h.gch' was built
notefile '/Users/wfg/Jenkins/workspace/macos-differential/build/workspaces/gcc/../../../libraries/source/glad/include/glad/gl.h' has been modified since the precompiled header 'obj/graphics_Debug/precompiled.h.gch' was builtnote
file '/Users/wfg/Jenkins/workspace/macos-differential/build/workspaces/gcc/../../../libraries/source/glad/include/glad/gl.h' has been modified since the precompiled header 'obj/graphics_Debug/precompiled.h.gch' was built
note: : please rebuild precompiled header 'obj/graphics_Debug/precompiled.h.gch': 
note: please rebuild precompiled header 'obj/graphics_Debug/precompiled.h.gch'
please rebuild precompiled header 'obj/graphics_Debug/precompiled.h.gch'
please rebuild precompiled header 'obj/graphics_Debug/precompiled.h.gch'
1 error generated.
make[1]: *** [obj/graphics_Debug/MiniMapTexture.o] Error 1
make[1]: *** Waiting for unfinished jobs....
1 error generated.
make[1]: *** [obj/graphics_Debug/CinemaManager.o] Error 1
1 error generated.
make[1]: *** [obj/graphics_Debug/MapGenerator.o] Error 1
1 error generated.
make[1]: *** [obj/graphics_Debug/MapReader.o] Error 1
make: *** [graphics] Error 2

Link to build: https://jenkins.wildfiregames.com/job/macos-differential/5887/display/redirect

Successful build - Chance fights ever on the side of the prudent.

Link to build: https://jenkins.wildfiregames.com/job/vs2015-differential/6978/display/redirect

marder added inline comments.Mar 30 2022, 12:09 PM
binaries/data/mods/public/simulation/helpers/InitGame.js
46

TODO: add a comment here

marder requested review of this revision.Mar 30 2022, 12:12 PM
marder edited the summary of this revision. (Show Details)Mar 30 2022, 2:32 PM
lyv added a subscriber: lyv.Mar 30 2022, 2:46 PM

Since the ai currently has no per turn fine control over what the units do

Would every 8 turns be too slow to kite? 8*250 or 2 seconds.

I do think so (without having tested it).

The question is also if it would conceptually be a different logic than using UnitAI? Isn't kiting always: hit the target, but retreat if it comes too close?
A more involved kiting should probably consider not only the target, but any enemy unit coming too close. But that sounds like it would need a lot more range queries.

I was just pleasantly surprised when I tried this out and it just worked without having to introduce any new logic :D

marder added inline comments.Mar 30 2022, 3:18 PM
binaries/data/mods/public/simulation/helpers/InitGame.js
49

Should I use const or stay with let for modding purposes?

lyv added a comment.EditedMar 30 2022, 3:24 PM

Isn't kiting always: hit the target, but retreat if it comes too close?

I guess so. But minimum ranges bring over other side effects with them. The most noticeable being that kiting would end up being forced which might make the AI easier.

Using min ranges make ranged units unable to attack any chasing unit that are faster. Cavalry would practically be immune once they get within 15 meters.

True, that's why the test says: Look for bad edge cases :)

From what I tested you are correct, it makes one singular ranged units easier to kill by a faster unit, since it cannot longer react or escape, but to me it seems quite useful when:

  • the ai attacks with a group of ranged units -> they split up and get more distance and you as an attacker would need to have very good micro to target every unit individually. Also, since one units is running away, you're units will try to chase after it, which wastes more time than attacking a stationary target.
  • the ai attacks with a mixed army (which it usually does)

But yes, this is more of an experiment so that people can test the patch and see how it feels. Although I quite like it.

Interesting idea. :)
I think D368 would allow this (kiting) even nicer, though.

binaries/data/mods/public/simulation/helpers/InitGame.js
49

(const vs let vs var doesn't play within functions.)

63

This should be moved to PetraAI.

I think D368 would allow this (kiting) even nicer, though.

Not sure I understand. sure, with two attacks you wouldn't be in a situation, where the min distance prevents you from attacking, but how would it allow for nicer kiting?

Sort of UnitAI support. :) And no inability to attack from up close indeed.

lyv added a comment.Mar 30 2022, 5:20 PM

Feels like this should be a stance then. Obviously, preferably it should be in the AI, but if this route is taken, stances sound more correct than introducing minimum ranges.

In D4582#195172, @smiley wrote:

Feels like this should be a stance then. Obviously, preferably it should be in the AI, but if this route is taken, stances sound more correct than introducing minimum ranges.

+1

marder added a comment.EditedMar 30 2022, 5:28 PM

ah ok got it.

I mean yes, if you want to do some wizardry in UnitAI to check if your target is faster than you and if there are any other attackers coming for you, to factor that into the decision if a unit should kite be my guest :D
But that still sounds computationally more expensive and wouldn't that also be applied to the player? (it shouldn't imo).

lyv added a comment.Mar 30 2022, 5:35 PM

It would be an internal stance only used by the AI.

In terms of behaviour, to start you can just move away N times and attack normally after N attempts if you never managed to get away.

marder abandoned this revision.Dec 2 2022, 1:46 PM

need a better implementation from someone who knows more of UnitAI

It is unfortunate but I believe @bb or @Freagarach are more knowledgeable about this.

Unknown Object (User) added a subscriber: Unknown Object (User).Feb 3 2024, 7:04 AM