Weapon v unit bonus

Weapon v unit bonus

Here is where ideas can be collected for the skirmish AI in development

Moderators: hoijui, Moderators

Post Reply
hangfire
Posts: 14
Joined: 06 Nov 2010, 08:31

Weapon v unit bonus

Post by hangfire »

Hello all,

Things are progressing nicely albeit slowly with my bot. It can beat RAI no probs, may be not the worlds biggest achievement but I was well happy with myself when it won.

So next I to expand the decision making of the bot in particular building units to meet a certain threat. Lets say the bot has been keeping a log of what units the enemy has produced so far and will use that information to determine what units to build next.

In a rock/sissors/paper fashion I'm guessing there's a way to conclude unit X > unit Y. But I can't see how. I thought there would be a way to compare weapon(damage) type with unit(armour) type to extract a bonus, but can't find anything of that nature.

Can anyone give me a pointer?

Regards
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: Weapon v unit bonus

Post by zwzsg »

hangfire wrote:In a rock/sissors/paper fashion I'm guessing there's a way to conclude unit X > unit Y.
No, there isn't.

I'm afraid it's not that simple. Spring games typically use more behaviors emergent from simulation than hard damage modifier. Too many factors play a role in unit effectivness, it's too easy to overlook some. The most impossible to parse by AI is probably the unit animation: It can't really be accessed in term of stats and tags, and yet it can make or break a unit role. For instance low fire point = shots more likely to get blocked. Or slow turret turn rate making it impossible to track fast moving units. Or toggling armored mode & cloack upon incomprehensible logic.

I'd say the best method to rate units is to cheat, spawn a bunch of unit of one type, switch team, spawn a bunch of unit of another type, godmode, and make them meet. Of course automatising that, and filling a database for all units pairs of a mod isn't as convenient as a formula giving effectivness directly out of unitdefs.

Otherwise I can give you a line of code to get damage x damage modifier for a given pair of unit, but it's in Lua:

Code: Select all

local function GetDamage(predator,prey)
	return WeaponDefs[UnitDefs[UnitDefNames[predator].id].weapons[1].weaponDef].damages[UnitDefs[UnitDefNames[prey].id].armorType]
end
hangfire
Posts: 14
Joined: 06 Nov 2010, 08:31

Re: Weapon v unit bonus

Post by hangfire »

Thanks for the reply zwzsg, as I continued reading the javadoc I started to think that perhaps I was trying to oversimplfy things.

I was thinking along the lines of what you suggested, but have weighted random selection in favour of weapons that had a bonus against armour types, then in turn record the success of chosen units to increase their weight, but as there's no such thing as a bonus I'll have to come up with something else.

Is there a rule of thumb, and I mean rough, that says use skirmish units against ...., use artillery against.... etc etc.

Your code looks like it could be helpful, I take it damages is a method you have created?
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Weapon v unit bonus

Post by hoijui »

i don't think that code is helpful for non Lua AIs. i can not tell you what works best.. hopefully some AI devs will be able to give tips. best thing for sure would be, if you could have a function that compares unit-defs. i would first try to do that, and see how well it works. even if it is only half-assed.. you can still use it as a basis.. like.. find the 5 unit-defs that are most likely a good counter (out of say. 150), and then test them in action to find the best, or build a mixed force. you sure get to usable results fastest this way, avoiding lots of problems like having to cache statistics, wrongly reused statistics, ...

maybe look at other AIs code (the unit properties are called the same in all interfaces, so you may also look at native AIs source code).
hangfire
Posts: 14
Joined: 06 Nov 2010, 08:31

Re: Weapon v unit bonus

Post by hangfire »

Good advice, i've been reading through HughAI, which gives me something more interesting to read at work, plus my boss hasn't got a clue what it is that i'm reading so I tell him it's an advanced algorithm to return statistics from our database, then he runs away...

As far as I could tell HughAI doesn't build units in response to the enemy make up.

However I have just discovered the modinfo site, that's well handy.

Back to drawing board for me and lots more research...wooo
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Weapon v unit bonus

Post by hoijui »

hangfire wrote:Good advice, i've been reading through HughAI, which gives me something more interesting to read at work, plus my boss hasn't got a clue what it is that i'm reading so I tell him it's an advanced algorithm to return statistics from our database, then he runs away...
i love that! :D

works where you are mainly dealing with DBs are like.. against the Geneva convention or something. it is your duty to dedicate as much time as possible to other stuff... the company should be happy for you to do that, trying to stay mentally sane.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Weapon v unit bonus

Post by knorke »

find the 5 unit-defs that are most likely a good counter (out of say. 150), and then test them in action to find the best
I think it would be far less than 150 as you can look at target categories if that unit can even shot at this unit. Look for tags badtargetcategory and nochasecategory.
Instead of only comparing damage you could also try things like building fast, cheap units against enemy units with a long reload time. From dps, range, speed and health you could ie calculate how many units you need to get in range of another unit and kill it.
ie "How many flashes must I use to rush a heavy laser tower?"

Or just build the same stuff as the enemy ;)
At least for *a games that works in a number of cases.

What games do you want your AI to play anyway?
Because I believe hardcoding (some) counters for different games is the way to go. Yes, maybe it would be possible to make an algorythm that searches for the best counters. But you would not know if the algorythm really always gives good results or if you tweaked it in a way that it is kind of like hardcoded counters.
hangfire
Posts: 14
Joined: 06 Nov 2010, 08:31

Re: Weapon v unit bonus

Post by hangfire »

Hey Knorke,

I'm using BA as my test platform. I'm not keen on hardcoding counters to enemy units. Rather I want to use a weighted roulette, the inital weights will need to be hardcoded but will be updated depending on unit successes. I hope in this way to produce a Bot that will be less predictable than a hardcoded build x in response to y.

I'll have to see if my skills are upto it without grinding the processor to halt.

It's sorting out the initial weightings that I'm struggling with, I'm toying with a simple, decision tree. Off the top of my head, is enemy unit slow or fast moving, if slow then select unit which out ranges it and from that range of units apply the weighted roulette to finalize what unit will be built.

Thoughts?

HF
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Weapon v unit bonus

Post by knorke »

I'm toying with a simple, decision tree. Off the top of my head, is enemy unit slow or fast moving, if slow then select unit which out ranges it and from that range of units apply the weighted roulette to finalize what unit will be built.

Thoughts?
Yes that might work.
But even if you code in things like
is enemy unit slow or fast moving, if slow then select unit which out ranges it
you have already taken a decision for the AI. I want to say if you dictate the algorythm too much you kind of also dictate the outcome.

On a sidenote, some units are slow moving but do not need/have a counter that outranges them.
For example the T2 Merl Missle Launchers. vs those you just want anything to get near them, then they are dead.
So you could take the decision and put something in that detects in which cases you do not want to outrange slow units but instead close in on them. But yeah...see what i mean?
Post Reply

Return to “AI”