Fighter targetting poll

For what's not in 'Top Priority Game Design'. Post your ideas, visions, suggestions for the game, rules, modifications, etc.

Moderator: Oberlus

Choose your targets

Poll ended at Mon Feb 11, 2019 8:48 pm

Bombers should target ships first
7
22%
Bombers should target fighters if there are no ships
4
13%
Interceptors should target Bombers first
7
22%
Interceptors should target ships if there are no fighters
6
19%
Fighters should target enemy ships with flak first
3
9%
Fighters should target enemy fighters first
3
9%
The default number of combat rounds should be increased from 3 to 4
2
6%
 
Total votes: 32

Message
Author
User avatar
Oberlus
Cosmic Dragon
Posts: 5715
Joined: Mon Apr 10, 2017 4:25 pm

Re: Fighter targetting poll

#16 Post by Oberlus »

Ophiuchus wrote: Fri Jun 28, 2019 1:35 pmdamage-per-shot is not possible as you can not query the currently shot (currently).
Do you mean that combat engine does not know what weapon is being fired? I guess I don't understand you (otherwise, how can it deal the damage that correspond to each weapon?).
I do need to make and effort and diggest the backend code for combat engine... can you point me to the relevant files?
damage-per-hit is even more far off
Sorry, my fault, I used "hit" instead of "shot" to avoid "DPS" being confused with damage per second, but... this isn't a RTS so no real ambiguity here. DPS, damage per shot. Let's not get into damage per hit considering shields, indeed.
Much easier: different battle scanner parts for certain structure ranges (so player decides in ship design)
Yes. But I would leave that for version 2.0 of this combat enfine rework (see later).
The model is that each shot is completely random ("simultaneous acquisition"). Implementation is sequential though. The only state that I can see is using value(structure) so that maybe the results would differ in a bout when structure changes.
If the target acquisition is simultaneous (in the sense that all weapons choose target without knowledge of what are targetting the rest of the weapons, and before any shot damage is applied), I think that's fine, and the best way to do it, in fact, so that there is more randomness in the combat.
Oberlus wrote: Thu Jun 27, 2019 3:03 pmIf it is the former, some bouts could get rather odd and inconsistent results, when the there are only a few (or just one) preferred target and the rest of enemies are does not cualify, so ALL your shots on that bout gets concentrated on the few preferred targets, and the rest of enemies are effectivelly immune for that bout.
Thats how it works. For experimentation we could add an "Overkill Compensator" battle scanner which prevents the ship from shooting at a ship which already got so much damage that it will be dead at the end of the bout.
I don't like that, at first glance. Looks like a complicated way to remove randomness of the targetting system, while keeping the randomness in first place. Either we make the combat system not random (which would be a very bad idea in my opinion, gameplay fun-wise) or we keep it reasonably random.
For the latter, I'm convinced it would be better to adjust the targetting rules between preferred and unpreferred target groups to be stochastic (partially random). Let me explain this better using an example of how I think this should work:


For each faction:

At the start of a given bout the engine assign each of the valid targets to each of the basic target type groups (these can be wrong in this example, but you'll get the idea):
  • Armed ships.
  • Unarmed ships.
  • Bombers.
  • Rest of fighters (or fighters and interceptors separated, what makes more sense)
  • Planets.
Then, for each type of weapon, you select the aggregated groups that compose the preferred and unpreferred target groups (again, these might be wrong in this example):
  • For flaks: bombers as preferred group, rest of fighters as unpreferred group (or preferred=bombers+fighters and unpreferred=interceptors; or preferred=bombers+fighters+interceptors, unpreferred=none)
  • For direct damage weapons: preferred=armed+planets+unarmed, unpreferred=bombers+fighters+ìnterceptors.
  • For bombers: preferred=armed+unarmed (or just armed, also with or without +planets), unpreferred=bombers+fighters+interceptors.
  • For interceptors: preferred=bombers+fighters, unpreferred=interceptors (or preferred=bombers+fighters+interceptors and unpreferred=armed+unarmed or none).
  • For fighters: preferred=anything (or...).
Then, for each weapon that's going to shot, you do this:
  • Probability of selecting a target from the preferred group: PP = C*NP/(C*NP+NU)
  • Probability of selecting a target from the unpreferred group: PU = NU/(C*NP+NU) = 1-PP
Where
  • C is a constant (say 2) that could be adjusted via computer targetting parts (basic part, C=3, advanced part C=4, or something like that)
  • NP is the number of targets in the preferred group
  • NU is the number of targets in the unpreferred group.

Example: fleet A 10 robohulls with 2 MDs, 1 flak and shields VS fleet B 10 robohulls with 2 MDs and bombers (1 hangar, 1 launcher).
Fleet A bout 1:
  • Each of the 20 MDs targets one random armed ship (nothing else to shoot at).
  • Flaks have no targets.
Fleet B bout 1:
  • Each of the 20 MDs targets one random armed ship (nothing else to shoot at).
  • 20 bombers are launched.
Each fleet loses 2 ships.
Fleet A bout 2:
  • Each of the 16 MDs targets either one random armed ship with probability=0.4444 [PP=(2*8)/(2*8+20)] or one random bomber with p=0.5556. (*)
  • Each flak targets one random bomber (nothing else to shoot assuming armed ships are not valid targets).
Fleet B bout 2:
  • Same than fleet A.
  • Each bomber targets one random armed ship (nothing else to shoot at).
(*) With current targetting system, in which direct damage weapons does not have a preferred targetting, these probabilities would be PP=0.2857 (target armed) and PU=07143 (target bombers).
With C=3 would be PP=0.5454 and PU=0.4545.

This system prevents those situations in which a single preferred target soaks down all the damage output of the enemy fleet.
I really think that situation must be avoided because it can be exploited, and will require more player attention (micromanagement) without being easy to do (not KISS). Example below.
Oberlus wrote: Thu Jun 27, 2019 3:03 pmOn the other hand, if this targetting policies are scripted in computer parts [...]
Think dedicated trooper-sniper ships are overly specialised, aren't they. Planet attack ships are probably fine. Anti-flak ships maybe overly specialised.
Agree. My point was: better avoid a new toggle for the player to change before each combat, let the decision making be restricted to ship design and fleet composition, so create one part for each combat policy. But that is an opinion, not a conviction.
That was the idea. Bring down the enemy death star. Or bring not so many Snipers to the battle. Maybe that is too situational and rather a policy thingy.
The problem is: if I was using self-gravs and robos, and the self-gravs were much more dangerous (better and more weapons) while the robos were mostly chaff, so you built a lot of snipers to counter that, and then I add to my 100 ship fleet a single titanic hull against your 100 ship fleet (50 snipers), then for the first bout half of your fleet would be concentrating its damage on a single target, so that on second bout I would have 99 ships (and 98% of initial structure points and damage output) while you would have lost many ships and a lot of structure points. Overkilling exploit, not fun at all (for you, in this example).
How about allowing multiple battle scanner parts per ship?
Only if internal slots are on sale. I mean, I don't see it.
For the moment I am thinking that for 0.4.9 maybe we should just adjust the default ShortRange targeting condition to target ships AND planets first, then fighters.
I agree. At least regarding computer parts and the such: I think armed ships should be able to prefer armed ships as target. But I also think the problem pointed out above should be solved (ideally for 0.4.9).

Ophiuchus
Programmer
Posts: 3433
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Re: Fighter targetting poll

#17 Post by Ophiuchus »

Oberlus wrote: Sat Jun 29, 2019 12:15 pm
Ophiuchus wrote: Fri Jun 28, 2019 1:35 pmdamage-per-shot is not possible as you can not query the currently shot (currently).
Do you mean that combat engine does not know what weapon is being fired? I guess I don't understand you (otherwise, how can it deal the damage that correspond to each weapon?).
I do need to make and effort and diggest the backend code for combat engine... can you point me to the relevant files?
combat/CombatSystem.cpp

Everything what creates shots (planets, fighters, weapons) generates one PartAttackInfo per shot.

Targeting is done in ShootAllWeapons().

Code: Select all

            // attacker is source object for condition evaluation. use combat-specific vis info.
            ScriptingContext context(attacker, combat_state.combat_info.empire_object_visibility);

            // apply species targeting condition and then weapon targeting condition
            species_targetting_condition->Eval(context, targets, rejected_targets, Condition::MATCHES);
            weapon.combat_targets->Eval(context, targets, rejected_targets, Condition::MATCHES);
You can query the attacker (Ship|Planet|Fighter via Source) in FOCS, but you do not know which weapon part or PartAttackInfo you have.

Oberlus wrote: Sat Jun 29, 2019 12:15 pm..I'm convinced it would be better to adjust the targetting rules between preferred and unpreferred target groups to be stochastic (partially random).
I agree that a stochastic approach would be sensible for preferences, so maybe it makes sense for battle scanners. Keeping weapon combatTargets hard, expressing what kind of targets you can shoot and use battle scanners for stochastic soft targeting. At least composition would have clear semantics. Your suggestion dividing the targets in two parts should be comparably easy to implement: the battle scanners would in FOCS only implement the preferredTarget part (so not specifying different probablities in FOCS).
Oberlus wrote: Sat Jun 29, 2019 12:15 pm Then, for each weapon that's going to shot, you do this:
  • Probability of selecting a target from the preferred group: PP = C*NP/(C*NP+NU)
So C is basically a weight which prefers the preffered targets. Implementation is quite doable. Note that this is still number-of-ships based, so bringing a lot of decoys would still draw enemy hits (which i consider ok/good).

Notes: C could also have a species trait component. A higher C is not always preferable - depending on how many shots you need to bring down all preferred targets with a high C you might do less damage because you focus too much on your preference.
Oberlus wrote: Sat Jun 29, 2019 12:15 pmthen I add to my 100 ship fleet a single titanic hull against your 100 ship fleet (50 snipers) ... Overkilling exploit
Yes, that would be trying to exploit snipers mechanic and failing at it. The idea is to bring down a single ship, so you probably would only bring 4 snipers.
Oberlus wrote: Sat Jun 29, 2019 12:15 pmAt least regarding computer parts and the such: I think armed ships should be able to prefer armed ships as target. But I also think the problem pointed out above should be solved (ideally for 0.4.9).
Not sure I read you. Without geoff or vezzra backing it, stochastic preferred targets will certainly not happen. I can do an implementation if there is a decision to do it.

Else it would be

Code: Select all

    combatTargets = OrderedAlternativesOf [
        And [
            [[COMBAT_TARGETS_VISIBLE_ENEMY]]
            Armed 
            Or [ Planet [[COMBAT_TARGETS_NOT_DESTROYED_SHIP]] ]
        ]
        And [
            [[COMBAT_TARGETS_VISIBLE_ENEMY]]
            Or [ Planet Fighter [[COMBAT_TARGETS_NOT_DESTROYED_SHIP]] ]
        ]
    ]
That would have the downside that you cant shoot at ships without weapons as long as there at least one armed ship or planet. Also I need to check Armed condition again, especially for planet. So should I try to get that into master?
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Look, ma... four combat bouts!

User avatar
Oberlus
Cosmic Dragon
Posts: 5715
Joined: Mon Apr 10, 2017 4:25 pm

Re: Fighter targetting poll

#18 Post by Oberlus »

Ophiuchus wrote: Sat Jun 29, 2019 7:04 pm combat/CombatSystem.cpp

Everything what creates shots (planets, fighters, weapons) generates one PartAttackInfo per shot.

Targeting is done in ShootAllWeapons().

Code: Select all

            // attacker is source object for condition evaluation. use combat-specific vis info.
            ScriptingContext context(attacker, combat_state.combat_info.empire_object_visibility);

            // apply species targeting condition and then weapon targeting condition
            species_targetting_condition->Eval(context, targets, rejected_targets, Condition::MATCHES);
            weapon.combat_targets->Eval(context, targets, rejected_targets, Condition::MATCHES);
Thank you very much.
You can query the attacker (Ship|Planet|Fighter via Source) in FOCS, but you do not know which weapon part or PartAttackInfo you have.
I assumed we don't need to query that in FOCS. Please, correct me if I'm wrong:
In weapons' FOCS files we set up combatTargets, and the C++ backend takes that into account during the actual combat. Thus, when it is firing (say) the weapon of an interceptor, or a mass driver, it knows the damage of that weapon and the valid and/or preferred targets of that weapon.
Your suggestion dividing the targets in two parts should be comparably easy to implement: the battle scanners would in FOCS only implement the preferredTarget part (so not specifying different probablities in FOCS).
The part of dividing the targets in groups wasn't a suggestion :) That's how I thought it was implemented: combatTargets = OrderedAlternativesOf [ GROUP1 GROUP2 GROUP3] would produce four target groups, GROUP1 the most preferred one, and implicit GROUP4 are the invalidad target, rest of targets not included in groups 1-3. This (with current implementation, if I'm not wrong) make the weapon pick a random target from GROUP1 if not empty, otherwise from GROUP2 if not empty, otherwise from GROUP3 if not empty, otherwise not shooting. Nota bene: I hadn't realised that there could be more than two groups, I see that know checking the combatTargets clause of FT_HANGAR_1.focs.txt.
My suggestion then would be to allow to pick targets from GROUP2 even when GROUP1 was not empty, with stochastic probabilities that favour GROUP1 over GROUP2. The point being to avoid a nasty exploit of deterministic/hard targetting.
So C is basically a weight which prefers the preffered targets.
Right. If C=1 then there is no preference.
Note that this is still number-of-ships based, so bringing a lot of decoys would still draw enemy hits (which i consider ok/good).
Indeed. That's the point.
Notes: C could also have a species trait component.
Nice. Of which kind? "Species X hates species Y"? "Species X is great at targetting, C=C+1"?
A higher C is not always preferable - depending on how many shots you need to bring down all preferred targets with a high C you might do less damage because you focus too much on your preference.
Yes. I also think that's ok, and even reasonable and good for strategic gameplay.
The alternative, targetting always the preferred target, when the enemy takes advantage of the exploit, means you can do waaaaaay less damage because all shots are focused on a single ship.
Oberlus wrote: Sat Jun 29, 2019 12:15 pmthen I add to my 100 ship fleet a single titanic hull against your 100 ship fleet (50 snipers) ... Overkilling exploit
Yes, that would be trying to exploit snipers mechanic and failing at it. The idea is to bring down a single ship, so you probably would only bring 4 snipers.
I disagree.
Think of robo, self-grav and titanic hulls. A "normal empire" can have early game 20 robos, mid game 30 robos + 5 self-grav, late game 10 robos + 20 self-grav + 5 titanic, very late game you have 15 self-grav + 30 titanic.
When fighting this normal empire, assuming robos have laser, self-gravs have plasma and titans have death rays, you want to snipe the bigger hulls soon, so makes sense to put enough snipers to focus say 25% to 50% of your damage output to those hulls.
If "normal empire" gets used to this, he could be "smart empire" and build 99% of ships of the previous hull size, with cutting edge weapons, and only 1 biggest hull with cheapest weaponry (say 99% robos + 1 self-grav at mid game, 99% self-gravs + 1 titan at late game). This single biggest hull will soak 25% to 50% (all the snipers) of all enemy damage on the first bout, that's huge. "Smart empire" will micromanage that at the start of every battle there is just 1 biggest hull to maximise the advantage of this exploit.
To counter this, you will have to remove from your fleets your extra snipers (that's close to lost them or require scrapping, huge blow to your economy) or build less of them in first place. Thus, we might end up with restricted strategic choices: no body builds more than (say) 10% snipers. Then there's no point on building many_small+few_big fleet compositions, so everybody goes for many_big. Then there is no point on installing the sniper part, since all targets will be same hull size.

With stochastic targetting, the exploit pointed out is no longer a killing strategy (not OP), but it is still a valid strategy, so the fleet compositions can be more varied and the sniper part keeps making sense.

At least that's how I foresee things going on.

Not sure I read you. Without geoff or vezzra backing it, stochastic preferred targets will certainly not happen. I can do an implementation if there is a decision to do it.
I understand.
Else it would be

Code: Select all

    combatTargets = OrderedAlternativesOf [
        And [
            [[COMBAT_TARGETS_VISIBLE_ENEMY]]
            Armed 
            Or [ Planet [[COMBAT_TARGETS_NOT_DESTROYED_SHIP]] ]
        ]
        And [
            [[COMBAT_TARGETS_VISIBLE_ENEMY]]
            Or [ Planet Fighter [[COMBAT_TARGETS_NOT_DESTROYED_SHIP]] ]
        ]
    ]
That would have the downside that you cant shoot at ships without weapons as long as there at least one armed ship or planet. Also I need to check Armed condition again, especially for planet. So should I try to get that into master?
Sorry, I'm a bit lost. Would this be for weapons (non-fighters)? Armed means "armed ships but not fighters"? Isn't there a way to ask for "ships (armed or not) - not fighters"?

Ophiuchus
Programmer
Posts: 3433
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Re: Fighter targetting poll

#19 Post by Ophiuchus »

Oberlus wrote: Mon Jul 01, 2019 11:42 am
Ophiuchus wrote: Sat Jun 29, 2019 7:04 pm You can query the attacker (Ship|Planet|Fighter via Source) in FOCS, but you do not know which weapon part or PartAttackInfo you have.
I assumed we don't need to query that in FOCS. Please, correct me if I'm wrong:
In weapons' FOCS files we set up combatTargets, and the C++ backend takes that into account during the actual combat. Thus, when it is firing (say) the weapon of an interceptor, or a mass driver, it knows the damage of that weapon and the valid and/or preferred targets of that weapon.
Yes, but what is the use? Target resolution cannot take the weapon or its stats into account.
Oberlus wrote: Mon Jul 01, 2019 11:42 am
Ophiuchus wrote: Sat Jun 29, 2019 7:04 pm Your suggestion dividing the targets in two parts should be comparably easy to implement: the battle scanners would in FOCS only implement the preferredTarget part (so not specifying different probablities in FOCS).
The part of dividing the targets in groups wasn't a suggestion :) That's how I thought it was implemented: combatTargets = OrderedAlternativesOf [ GROUP1 GROUP2 GROUP3] would produce four target groups
Thats not what I meant. It does not matter how many one of those target groups (four in your example) has for calculating probabilites. It is still the number of targets matching the target condition vs the number of not matching targets.

You get a set of matching targets back from the condition. You do not see multiple target groups, only the result.
Oberlus wrote: Mon Jul 01, 2019 11:42 amMy suggestion then would be to allow to pick targets from GROUP2 even when GROUP1 was not empty, with stochastic probabilities that favour GROUP1 over GROUP2.
Thats not how conditions work. So I would say: too complicated, too much work
Oberlus wrote: Mon Jul 01, 2019 11:42 amNotes: C could also have a species trait component.
Nice. Of which kind? "Species X hates species Y"? "Species X is great at targetting, C=C+1"?[/quote]
I meant the second: GREAT_TARGETING == VERY_PEDANTIC species trait (having a target fixation~)
Oberlus wrote: Mon Jul 01, 2019 11:42 amSorry, I'm a bit lost. Would this be for weapons (non-fighters)? Armed means "armed ships but not fighters"? Isn't there a way to ask for "ships (armed or not) - not fighters"?
Yes in targeting context you have to use

Code: Select all

[[COMBAT_TARGETS_NOT_DESTROYED_SHIP]]
. I thought you preferred to target ships with weapons/carriers. In order to target all ships just remove the Armed combat condition.
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Look, ma... four combat bouts!

User avatar
Vezzra
Release Manager, Design
Posts: 6095
Joined: Wed Nov 16, 2011 12:56 pm
Location: Sol III

Re: Fighter targetting poll

#20 Post by Vezzra »

Oberlus wrote: Mon Jul 01, 2019 11:42 amMy suggestion then would be to allow to pick targets from GROUP2 even when GROUP1 was not empty, with stochastic probabilities that favour GROUP1 over GROUP2. The point being to avoid a nasty exploit of deterministic/hard targetting.
Since the question has been raised what I would back, I'll chime in here to back what Oberlus suggests here. Please no deterministic/hard targetting.

I've already stated during former discussions that I'm wary about the entire combat targetting idea (without also incorporating an abstraction of tactical movement), but if we're going to do this, combat target priorities should shift the probabilities, so that instead of complete random target selection you get higher probabilities to hit your preferred targets, but not replace random target selection by a strictly deterministic target selection.

The only way deterministic/hard targetting would be acceptable is if failing to acquire a valid target during a combat bout even if valid targets are still present on the battlefield is a possibility.
Think of robo, self-grav and titanic hulls. A "normal empire" can have early game 20 robos, mid game 30 robos + 5 self-grav, late game 10 robos + 20 self-grav + 5 titanic, very late game you have 15 self-grav + 30 titanic.
When fighting this normal empire, assuming robos have laser, self-gravs have plasma and titans have death rays, you want to snipe the bigger hulls soon, so makes sense to put enough snipers to focus say 25% to 50% of your damage output to those hulls.
If "normal empire" gets used to this, he could be "smart empire" and build 99% of ships of the previous hull size, with cutting edge weapons, and only 1 biggest hull with cheapest weaponry (say 99% robos + 1 self-grav at mid game, 99% self-gravs + 1 titan at late game). This single biggest hull will soak 25% to 50% (all the snipers) of all enemy damage on the first bout, that's huge. "Smart empire" will micromanage that at the start of every battle there is just 1 biggest hull to maximise the advantage of this exploit.
To counter this, you will have to remove from your fleets your extra snipers (that's close to lost them or require scrapping, huge blow to your economy) or build less of them in first place. Thus, we might end up with restricted strategic choices: no body builds more than (say) 10% snipers. Then there's no point on building many_small+few_big fleet compositions, so everybody goes for many_big. Then there is no point on installing the sniper part, since all targets will be same hull size.

With stochastic targetting, the exploit pointed out is no longer a killing strategy (not OP), but it is still a valid strategy, so the fleet compositions can be more varied and the sniper part keeps making sense.

At least that's how I foresee things going on.
This.

I complete concur with that analysis.
Without geoff or vezzra backing it, stochastic preferred targets will certainly not happen. I can do an implementation if there is a decision to do it.
I understand.
Well, in that case I want to make clear that I definitely back stochastic preferred targetting. :D

User avatar
Oberlus
Cosmic Dragon
Posts: 5715
Joined: Mon Apr 10, 2017 4:25 pm

Re: Fighter targetting poll

#21 Post by Oberlus »

Ophiuchus wrote: Mon Jul 01, 2019 3:37 pm
Oberlus wrote: Mon Jul 01, 2019 11:42 amwhen it is firing (say) the weapon of an interceptor, or a mass driver, it knows the damage of that weapon and the valid and/or preferred targets of that weapon.
Yes, but what is the use?
For dinamically adjusting targetting policies, like the "structure>X" of your proposal but with the X determined by the weapons damage (maybe DPS/3).
But it is true (as you pointed out previuosly) this can be done using one different targetting computer for each weapon's damage range.

Target resolution cannot take the weapon or its stats into account.
Oh, that's a pity.
So you can only take into account target's characteristics, and that's why you suggested that "structure>30". Now I get it.
Ophiuchus wrote: Sat Jun 29, 2019 7:04 pmIt is still the number of targets matching the target condition vs the number of not matching targets.
Yes, that's seems obvious to me, so I think I'm missing something here.
You get a set of matching targets back from the condition. You do not see multiple target groups, only the result.
I assume currently the combat engine gets only a single group of valid targets that is composed of the targets that matches the first target group (unless empty, then look for targets of the second group, etc.), and then roll a dice with uniform probability to pick one target from that single group. And that's what I advise to change.
The engine combat in the backend should get two or more groups of targets to pick from, to enable the stochastic selection. The condition evaluation in "combatTargets" should return (to the combat engine, not FOCS, unless I am missing something, probably) the belonging of each target to each group, and the combat engine would roll a dice for each shot, considering thepreviously mentioned probabilities.


Regarding the introduction (or not) of the direct damage weapons not shooting at figthers:
With the current non-stochastic system, this would make figthers no longer soak damage, making all fighters less interesting. That is ok, or better, IMO.
This no-soak effect is more dramatic for interceptors, which no longer act as a nice substitute of a shield but still takes up an interior slot, and can be shot down in bout 2 or 3 while flaks does not take up interior slot and cannot be taken down until you destroy the ship. This makes flak >> interceptors, but could be balanced via costs and increasing the number of interceptors (just a guess: 1 interceptor hangar + launch bay has 6 interceptors and costs the same than 1 flak).
I don't think that introducing this into master would be too disruptive for AI or general gameplay. In fact, I think AI would benefit (AI still has a clear tendency to oversight figthers until I've been trampling over it with my fighters for 50-100 turns, while it should build carriers from the very beginning).
So I guess you can try to make it into master, without any promise that that would be a definitive change.

With an stochastic targetting system, I would definitively tell you to introduce it to master.

Ophiuchus
Programmer
Posts: 3433
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Re: Fighter targetting poll

#22 Post by Ophiuchus »

Oberlus wrote: Mon Jul 01, 2019 4:47 pm
Ophiuchus wrote: Mon Jul 01, 2019 3:37 pm You get a set of matching targets back from the condition. You do not see multiple target groups, only the result.
I assume currently the combat engine gets only a single group of valid targets that is composed of the targets that matches the first target group (unless empty, then look for targets of the second group, etc.), and then roll a dice with uniform probability to pick one target from that single group. And that's what I advise to change.
On first sight this would break the condition concept. So either this needs to be implemented outside of conditions or the conditions concept needs be expanded/substituted (i think both needs backing by geoff).

Expansion concept could be "GroupingCondition" instead of "Condition". Composability is highly unclear.
Simpler substitution concept could be a hack to handle substitute OrderedAlternativesOf with GroupedAlternativesOf which can only be applied on the toplevel of target conditions in FOCS. This GroupedAlternativesOf would ideally return an iterator of some kind to prevent having to calculate all results.

Another maybe simpler solution is to make a ProballisticOrderedAlternativesOf which does the selection inside of the condition. This would still be composable. The downside is that probably a little bit more of the combat system leaks into FOCS content. For targeting this is probably ok.
Oberlus wrote: Mon Jul 01, 2019 4:47 pm Regarding the introduction (or not) of the direct damage weapons not shooting at figthers:
...
So I guess you can try to make it into master, without any promise that that would be a definitive change.
Not sure what you say. You claim the thing is broken and should be fixed for 0.4.9
So is it a fix or not?
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Look, ma... four combat bouts!

User avatar
Oberlus
Cosmic Dragon
Posts: 5715
Joined: Mon Apr 10, 2017 4:25 pm

Re: Fighter targetting poll

#23 Post by Oberlus »

Ophiuchus wrote: Tue Jul 02, 2019 10:09 amNot sure what you say. You claim the thing is broken and should be fixed for 0.4.9. So is it a fix or not?
I think it is a fix, but I'm not 100% certain because I haven't tested it.
In order to do so, I only need to add the changes you pointed out some posts above, right?

Ophiuchus
Programmer
Posts: 3433
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Re: Fighter targetting poll

#24 Post by Ophiuchus »

Oberlus wrote: Tue Jul 02, 2019 11:08 am
Ophiuchus wrote: Tue Jul 02, 2019 10:09 amNot sure what you say. You claim the thing is broken and should be fixed for 0.4.9. So is it a fix or not?
I think it is a fix, but I'm not 100% certain because I haven't tested it.
In order to do so, I only need to add the changes you pointed out some posts above, right?
Yes, to the weapon part at the right position (have a look at flak sr_0_1).

Planet condition is maybe too simple AFAICR, but should suffice for testing
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Look, ma... four combat bouts!

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Fighter targetting poll

#25 Post by Geoff the Medio »

On first sight this would break the condition concept. So either this needs to be implemented outside of conditions or the conditions concept needs be expanded/substituted (i think both needs backing by geoff).
Could you summarize specifically or with an example of what this would do?
Another maybe simpler solution is to make a ProballisticOrderedAlternativesOf which does the selection inside of the condition.
What would this do that the existing random conditions can't?

Ophiuchus
Programmer
Posts: 3433
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Re: Fighter targetting poll

#26 Post by Ophiuchus »

Geoff the Medio wrote: Tue Jul 02, 2019 5:12 pm
Another maybe simpler solution is to make a ProballisticOrderedAlternativesOf which does the selection inside of the condition.
What would this do that the existing random conditions can't?
It uses probabilities based on matching vs non-matching objects.

Actually I never used Random so I think it could work if we fix the fighters-are-not-part-of-the-universe issue:

Code: Select all

 
OrderedAlternativesOf [
    And [ [[TIER_ONE]]  Random probability = ( [[CNP1]] [[TIER_ONE]] [[CNP2]] ) / ( ( [[CNP1]] [[TIER_ONE]] [[CNP2]] ) / [[NU]] )
    And [ [[TIER_TWO]]  Random probability = ( [[CNP1]] [[TIER_TWO]] [[CNP2]] ) / ( ( [[CNP1]] [[TIER_TWO]] [[CNP2]] ) / [[NU]] )
    [[TIER_THREE]]
]
// Macros
CNP1
'''[[C]] * Count condition =  And [ InSystem id = Source.SystemID '''

CNP2
''']'''

NU
'''And [
            [[COMBAT_TARGETS_VISIBLE_ENEMY]]
            Or [ Planet Fighter [[COMBAT_TARGETS_NOT_DESTROYED_SHIP]] ]
        ]'''
would be the same as the intended

Code: Select all

 
ProballisticOrderedAlternativesOf weight = [[C]] [
    [[TIER_ONE]]
    [[TIER_TWO]]
    [[TIER_THREE]]
]
edit1:
If I grok the Number condition right, the following would also yield something similar (preferring targets from tier one rather targets intier two and falling back to tier three), without coding a convoluted solution and also without the fighter issue. I can not really figure out how to compare the resulting probabilities between the solutions though

Code: Select all

OrderedAlternativesOf [
    Or [
        And [ [[TIER_ONE]]  Random probability = [[CC]] ]      // e.g. 2/3 ~ 0.67 chance per match to be included
        And [ [[TIER_TWO]]  Random probability = 1 - [[CC]] ]  // e.g. 1/3 ~ 0.33 chance per match to be included
    ]
    [[TIER_THREE]]                                              // hard fallback
]

CC
'''[[C]] / ( [[C]] + 1 )'''
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Look, ma... four combat bouts!

Ophiuchus
Programmer
Posts: 3433
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Re: Fighter targetting poll

#27 Post by Ophiuchus »

So I had a stab at the combinatorics of this combatTargets condition using LibreOffice calc

Code: Select all

OrderedAlternativesOf [
    Or [
        And [ Ship Random probability = 0.8 [[COMBAT_TARGETS_VISIBLE_ENEMY]] ]
        And [ Fighter Random probability = 0.2 [[COMBAT_TARGETS_VISIBLE_ENEMY]] ]
    ]
    Or [ Ship Fighter Planet [[COMBAT_TARGETS_VISIBLE_ENEMY]] ]
]
With an enemy consisting of 1 Planet, 2 Ships and 3 Fighter, a shot has 38% chance of hitting a certain Ship and a 7% chance of hitting a Fighter.
In only 2% of the cases no target is selected in the first tier, so the Planet has a 0,3% chance of being hit.
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Look, ma... four combat bouts!

User avatar
Oberlus
Cosmic Dragon
Posts: 5715
Joined: Mon Apr 10, 2017 4:25 pm

Re: Fighter targetting poll

#28 Post by Oberlus »

Ophiuchus wrote: Thu Jul 04, 2019 4:16 pm...
I need more time to diggest all the above posts and the cpp code (having a hard time, I'm so outdated C++ wise).

Edit: Still digesting. I don't even know how are random selection of targets performed in the cpp code, and I'm having a hard time interpretting the meaning of FOCS constructions. See for example:

From FOCS Scripting Details:

Code: Select all

Random probability = PROB
Matches objects with a probability of PROB. That is, objects have a probability of PROB of being matched.

Code: Select all

Ship
Fighter
Fleet
Matches objects with the indicated type.
So what does the following mean?

Code: Select all

And [ Fighter Random probability = 0.2 [[COMBAT_TARGETS_VISIBLE_ENEMY]] ]
Does it have a 20% chance of selecting one fighter from [[COMBAT_TARGETS_VISIBLE_ENEMY]].



I wanted to add the following comments in case you understand better than me my doubts.

What I have in mind (before I really understand how FOCS and the backend combat engine works) is something like this:

FOCS weapon parts would have definitions of target preferences like this:

Code: Select all

// Direct damage weapons
OrderedAlternativesOf [
  Or [ ARMED PLANET ] // first group, most preferred targets
  Or [ FIGHTER BOMBER INTERCEPTOR UNARMED ] // second group, less preferred targets
] // Anything not in the previous groups can't be targetted (nothing in this case)

// Interceptors
Ordered AlternativesIOf [
  Or [ BOMBER FIGHTER]  // first group
  INTERCEPTOR // second group
  Or [ ARMED UNARMED] // third group
] // Anything not in the previous groups can't be targetted (PLANETS in this case)
This is assuming variable number of preferred groups.
I think we could suffice with just two groups: preferred and unpreferred, and the implicit group of invalid targets (the ones not included in preferred or unpreferred). Thus I think it could be easier to understand if FOCS syntaxis was like this:

Code: Select all

// Direct damage weapons
primaryTargets = [ ARMED PLANET ]
secondaryTargets [ FIGHTER BOMBER INTERCEPTOR UNARMED ]
] // Anything not in the previous groups can't be targetted (nothing in this case)

// Interceptors
Ordered AlternativesIOf [
primaryTargets = [ BOMBER FIGHTER]
secondaryTargets =  INTERCEPTOR
tertiaryTargets = [ ARMED UNARMED]
] // Anything not in the previous groups can't be targetted (PLANETS in this case)
Rather simple and intuitive.
I said we could suffice with just primary and secondary (e.g. make interceptors primaryTarget = bomber+fighter+interceptor, secondary = armed+unarmed) because the equations for probabilities are way simpler so that you can know the expected results without resorting to complex spreadsheet calculations. It would not be really hard to implement it with a tertiary set of targets. From here on I assume just primary and secondary sets.

There wouldn't be any actual selection of targets calculated in FOCS, just the definition of the preferences (i.e. a list of tags).
The combat engine in the backend (which I pressume considerably faster than FOCS/Python for intense calculations?), for each faction X, would distribute all possible targets among several target containers (array, list, queue, stack, set, whatever you use), one container for each kind of target, say ARMED_targets_X, BOMBER_targets_X, PLANET_targets_X, etc.. It would also fill another container, say attackers_X, with the weapons of that faction (or with the armed ships, each with its own container of weapons, or whatever you do).
Then the combat engine would do the target selection (see below) for each weapon in attackers_X of each faction X, depending on its targetting preferences (without any of this comming restricted from FOCS); backpropagate the damage, add newly launched fighters to corresponding attackers_X and FIGTHER_targets_Y/Z/etc., cull the dead from all the containers, and continue with next bout.

The target selection
I'm assuming we want primaryTargets to have three times more probabilities to be selected than secondaryTargets. Some examples of the implications:
#Primary#SecondaryProbability of hitting primary
663386%
505075%
336660%
208043%
109025%
I keep in mind computation performance, because that was something quite relevant in other projects I've worked on, in which I was making millions of stochastic selections between groups of sizes ranging between 10 an 10000 objects (genetic algorithms). IDK if it is a sterile concern for FreeOrion combats. I also blindly assume that you are using containers such as arrays, optimised for direct access of Nth element. After this caveats, this is what I suggest:

Weapon to be shoot now, from, faction A, has primary=ARMED+PLANETS, secondary=FIGHTER+BOMBER+INTERCEPTOR.
ARMED_targets_A has 10 elements, PLANET_targets_A has 2 targets, FIGHTER and INTERCEPTOR 0 targets, BOMBER 20.
So primary_targets for this bout are 12 targets and secondary are 20.
We said three times more probability for primary than for secondary, which means:
N=12*3+20=56
P_primary=12*3/56=0.6429
P_secondary=20/56=0.3571
So get a random double r with uniform probability in [0,1] and

Code: Select all

if(r<P_primary)
{
  // pick a random target from the set ARMED_targets_A+PLANET_targets_A
}
else
{
  // pick a random target from the set FIGHTER_targets_A+BOMBER_targets_A+INTERCEPTOR_targets_A
}
IDK if the CPP containers used in the combat engine have built-in methods to get a random object from them, or if it is efficient to ask for one random item from a union of several containers that you don't want to actually join. If this is not the case, you can fill and array with pointers (or whatever) to all the primary targets, and another one with the seconday targets (in previous example, for primary, it would have 12 entries, the 10 ships and 2 planets), and get a random integer to select one of them (e.g. an integer in [1,12] for the primary targets). Take any of this with the proper amount of salt, since I don't know C++ and I know I can be saying something silly (apologies in advance).

Ophiuchus
Programmer
Posts: 3433
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Re: Fighter targetting poll

#29 Post by Ophiuchus »

not really wanting to warm up that discussion, adding some comments for help me thinking on probabilistic effects in freeorion
Oberlus wrote: Fri Jul 05, 2019 12:33 pmSo what does the following mean?

Code: Select all

And [ Fighter Random probability = 0.2 [[COMBAT_TARGETS_VISIBLE_ENEMY]] ]
Does it have a 20% chance of selecting one fighter from [[COMBAT_TARGETS_VISIBLE_ENEMY]].
It has a 20% chance of deciding for a single fighter to be in the target set or not. So if there are a hundred fighters you (gut-feel-)probably have something between 14 to 28 fighters in the target set. Adding to the ~80% of ships targets in the target set in the surrounding expression.

probably the set should be reduced for valid targets before checking randomness, so the result does not depend on e.g. the size of your own fleet. I think we dont have a mechanism for this yet. It could look like this

Code: Select all

RestrictedCondition universe = [[COMBAT_TARGETS_VISIBLE_ENEMY]] condition = OrderedAlternativesOf [
    Or [
        And [ Ship Random probability = 0.8 ]
        And [ Fighter Random probability = 0.2]
    ]
    Or [ Ship Fighter Planet ]
]
or if that would not work as a generic RestrictedCondition, a parameter for OrderedAlternativesOf would certainly work (e.g. OrderedAlternativesOf include = [[COMBAT_TARGETS_VISIBLE_ENEMY]] [ ... ]) .
Oberlus wrote: Fri Jul 05, 2019 12:33 pm Thus I think it could be easier to understand if FOCS syntaxis was like this:

Code: Select all

// Direct damage weapons
primaryTargets = [ ARMED PLANET ]
secondaryTargets [ FIGHTER BOMBER INTERCEPTOR UNARMED ]
] // Anything not in the previous groups can't be targetted (nothing in this case)
yes, that would work well in a declaritive sense. as visibility was moved to focs specification etc. it would probably need to be specified here though or needs another condition parameter on the ship part (e.g. eligibleTargets = [[COMBAT_TARGETS_VISIBLE_ENEMY]]).
Oberlus wrote: Fri Jul 05, 2019 12:33 pm There wouldn't be any actual selection of targets calculated in FOCS, just the definition of the preferences (i.e. a list of tags).
The combat engine in the backend (which I pressume considerably faster than FOCS/Python for intense calculations?)
there seems to be a misunderstanding (or maybe not). What you specify in the FOCS "scripts" creates c++ Condition structures (lets call that the FOCS AST) and evaluation uses those. Those are basically composites of conditions - which you also need for "pure" c++ if you want to be able to specify composition of conditions. Maybe one would be able to hardcode something faster if you can skip some composites - but in that case classical reduction of FOCS "AST" could give the same benefit.
Oberlus wrote: Fri Jul 05, 2019 12:33 pm I'm assuming we want primaryTargets to have three times more probabilities to be selected than secondaryTargets. Some examples of the implications:
If I got you right you would want the weight of the primaryTargets be three times the weight of the secondaryTargets when picking results.
The main thing here is that you need to calculate both target sets before in order to be able to do this. The OrderedAlternativesOf can skip calculating sets.
For primary/secondaryTargets one could skip calculating sets if we would know how large the union of the sets is.

Not sure where the topic popped up last, (probably when LienRag was stumped by the ancient ruins excavation effects); so here some suggestion for syntax of weighted random sampling without replacement using a closed universe assumption...

Code: Select all

WeightedAlternativesOf universe = [[COMBAT_TARGETS_VISIBLE_ENEMY]] conditions =  [
    Alternative weight = 3 condition = Ship
    Alternative weight = 1 condition = Fighter
]
Implementation probably could calculate one target set, then use (relative_weight * size(target_set))/size(universe_set)) to determine if it should pick a target from the set, else carry on with the next target set. Or if we also state distinct alternatives while checking it could restrict search for the next Alternative to non-matches.

...but i took away that geoff does not think we want/need weighted conditions, but weighted effects would make some sense (or was it the other way round?); see PickEffects in
Excrutiating FOCS doubts

edit1: it was the other way round:
I got geoff's input in the dev meetup, as the stated use case is possible with current implementation (chained if-else effects with dependent probabilities) he doesn't want to complicate the scripting context with adding something maybe more complex (e.g. complexity like the LocalCandidate (e.g. what would happen about invariants?, would one need to store very different values e.g. string, int, float, vector<*>..)).

Weighted selection of objects (without replacement) in a condition makes more sense for him, but also there we do not have a pressing use case (there are usually workarounds). So for the moment I guess wait/dig for valid use cases (anyway having a selection-without-replacement function in random would not hurt).
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Look, ma... four combat bouts!

Post Reply