How does it work focus switching?

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

Moderator: Oberlus

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

How does it work focus switching?

#1 Post by Oberlus »

I'm interested into finding out how exactly are performed the different meter changes that depends on focus switching (i.e. not just the MaxMeter modified by the current focus setting, but the effects on every meter affected by a given focus switch), and specially if it works as I thought it does by reading the Pedia (now I'm unsure, after some discussions in the forum): every turn under max value meter goes up +1 (+3 with energy force structures), and every turn it's over its max value meter goes down -3 (-5).
This alone should solve any focus dancing problem for Industry and Research, but I may have understood that that problem is still real because the -3 (-5) is applied only first turn, and rest of turns it is -1 (-3).

This is an example of the behaviour I expect:
* Start of turn 1: FocusIndustry, MaxIndustry=Industry=20, MaxResearch=Research=2
You do a focus change to FocusResearch.
* Start of turn 2: FocusResearch, MaxIndustry=5, Industry=17, MaxResearch=12, Research=3
...
* Start of turn 5: FocusResearch, MaxIndustry=5, Industry=8, MaxResearch=12, Research=6
* Start of turn 6: FocusResearch, MaxIndustry=5, Industry=5, MaxResearch=12, Research=7
...
* Start of turn 11: FocusResearch, MaxIndustry=5, Industry=5, MaxResearch=12, Research=12

Until Research gets maxed in turn 11, Industry is at its minimum since turn 5.
During these 11 turns you got 100 PPs and 77 RPs (instead of 220 and 22 with FocusIndustry all time), so you traded -120 PPs for +55 PPs.
And from there on you are getting 5 PPs and 12 RPs.
For this example, each turn MaxMeter==Meter, you are trading 15 PPs for 10 RPs (or vice versa).
To revert the state from max research back to max industry you need 15 turns (if focus switched in turn 1, it maxes out at turn 16), although your research will be at its minimum in 4 turns (actually 3.33 turns).

To go from max industry to max research and back again, you need 26 turns and get 295 PPs (56.73%) and 139 RPs (44.55%).
If you stay all time at max industry during 26 turns you get 520 PPs (100%) and 52 RPs (16.67%).
If all time at max research, 130 PPs (25%) and 312 RPs (100%).

Regardless of how many colonies made the focus switch, the ratios keep the same.

If in the middle of a switching, before max meter is reached, you switch back the focus, you'll be getting back to your minimum of the other meter much faster, x3 (x1.66) than focused one will recover, so you'll be increases your losses by not letting the meters reach max before switching.

Is all this correct?


Edit: corrected wrong numbers and some wrong conclusions.

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

Re: How does it work focus switching?

#2 Post by Ophiuchus »

I never did the focus dance with research or industry. I think that is because the number of planets is comparably low in comparison to the amounts involved.

I sometimes refocus my empire, but that i never switch many planets to e.g. research and then switch some back after a few just in order to boost research meter growth in order to get research to reach certain number.

With the stockpile focus the numbers may be lower: e.g. i want to build a warship out of supply (costs e.g. 100PP/3turns) in e.g. four turns.
So if my stockpile limit is 10PP, switching 14 planets first turn cuts it. Then microcalculating and switching back saves resources.

1) 10/100 PP (+10PP ; switch 14 planets to stockpile focus)
2) 34/100 PP (+24PP 14*+1; switch back 2 planets)
3) 68/100 PP (+34PP 12*+2; switching back 1 planet)
4) 100/100 PP (+33PP 11*+3; goal achieved: switching back 11 planets)

i actually think the homeworld focus species bonus will alleviate some of the problems as its growth rate is higher while only having to switch a single planet.

edit: had some numbers suboptimal wrong; this microcalcalations are fiddly
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!

Morlic
AI Contributor
Posts: 296
Joined: Tue Feb 17, 2015 11:54 am

Re: How does it work focus switching?

#3 Post by Morlic »

Your meters decay by 1 per turn. On first turn after the focus change, you will get an additional -1 penalty (so it drops by 2 that turn and that turn only).

The idea behind focus dithering is that your meters decay and grow by the same rate (prior to the force-energy structures). So without a focus change penalty, you can trade research for industry in a 1:1 ratio. With the penalty, you will get a worse ratio (the longer . If the ratio at which you trade is better than your (subjective) weighting of RP relative to PP, then it is a net benefit to dither the focus around the max meters. A longer cycle will bring the trading ratio closer to 1:1.

The math behind it is pretty straight forward:
Morlic wrote:

Code: Select all

Assuming we switch to a research focus for n turns with a focus penalty of p and assuming integer values of Research(R) and Industry(I) only:

R = {sum(i), i=1..n}    =  n(n+1)/2
I = {-sum(i+p), i=1..n} = -n(n+1+2p)/2

Growing up again until industry meter maximum, we need (n+p) turns.
R = {sum(i), i = 0..n-p-1} = (n-p-1)(n-p)/2
I = {-sum(i), i = 1..n+p-1} = (n+p-1)(n+p)/2

Adding both, we have
R = n^2 - np + p^2 / 2 + p/2
I = - (n^2 + 2np +p^2/2 -p/2)

With current p = 1 this yields
R = 1 + n(n-1)
I = - n(n+2)
or a cost ratio of -I/R = n(n+2) / (1+n(n-1))

For example, a cycle consisting of switching 5 turns to research yields (n=5)
R = 21
I = -35
or a cost of ~1.67 PP per RP
Note that cycles of length n >= p+1 were implicitly assumed in the derivation, it does not hold for shorter cycles.
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

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

Re: How does it work focus switching?

#4 Post by Oberlus »

Thanks for the explanation!

Ok then, maybe you'd like to consider making the standard decrease -3 every turn (-5 with energy force structures) to better discourage micromanagement of foci.

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

Re: How does it work focus switching?

#5 Post by Ophiuchus »

Oberlus wrote:Thanks for the explanation!

Ok then, maybe you'd like to consider making the standard decrease -3 every turn (-5 with energy force structures) to better discourage micromanagement of foci.
Maybe somebody could link the design discussion when this was changed to 1:1 ratio.

Anyway, reading the FOCUS_CHANGE_PENALTY code again I now understand why i was confused at the beginning. I first thought it penalizes the focus you switch to (which would suck a bit because you dont simply pay a cost but also dont have the effect).

Then I thought it penalizes the focus you switch from until i figured out that this is strange because there is no way in FOCS to find out the previous focus. What actually happens generally it penalizes industry AND research (AND stockpile) on every focus switch (its just not applied to the focus you switch to). So switching to e.g. supply will mean penalty for those three.
I dont think this is right.
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: How does it work focus switching?

#6 Post by Vezzra »

Ophiuchus wrote:What actually happens generally it penalizes industry AND research (AND stockpile) on every focus switch (its just not applied to the focus you switch to). So switching to e.g. supply will mean penalty for those three.
I dont think this is right.
I agree. Making focus switching cost influence instead should solve all these issues. :D

User avatar
Dilvish
AI Lead and Programmer Emeritus
Posts: 4768
Joined: Sat Sep 22, 2012 6:25 pm

Re: How does it work focus switching?

#7 Post by Dilvish »

Ophiuchus wrote:So switching to e.g. supply will mean penalty for those three. I dont think this is right.
I think you are still missing some details, and that it is OK the way it is now. If you had been on Industry for a while, and then switched to Supply, chances are the Research had already bottomed out, and so would not take a further hit from switching from Industry to Supply. (For a few months this year an accidental change had made Research still take a penalty in that case, but it was recently fixed).

Also, at the time that was fixed I noticed that since Stockpiling is a currently Max type meter, the penalty is currently meaningless for it-- it drops all the way down the instant you switch away, regardless of penalty. I had made a note of that someplace (in the penalty script, or the PR, or whatever), and had wanted to give it a little time so just in case I was overlooking something someone could point it out (I think enough time has passed now).
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

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

Re: How does it work focus switching?

#8 Post by Geoff the Medio »

Vezzra wrote:Making focus switching cost influence instead should solve all these issues. :D
Unless, potentially, an empire has lots of influence, and thus doesn't mind spending some to do some focus switching micromanagement...

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

Re: How does it work focus switching?

#9 Post by Vezzra »

Geoff the Medio wrote:Unless, potentially, an empire has lots of influence, and thus doesn't mind spending some to do some focus switching micromanagement...
That's a problem we can't avoid regardless what kind of penalty/cost we decide to apply to focus switching. If an empire can, for whatever reason, easily afford that cost/penalty, it can happily switch around.

However, making the costs for focus switching high enough (whatever those costs are) should ensure that the resources you need to invest into providing enough of whatever it is to be able to do that focus switching should outweigh the benefits you gain from the micromanagement. It's all a matter of getting the balance right.

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

Re: How does it work focus switching?

#10 Post by Oberlus »

Vezzra wrote:If an empire can, for whatever reason, easily afford that cost/penalty, it can happily switch around.
As long as it is affording a cost in the sense of spending something that could have been giving a different, bigger benefit (so you are giving more than what you get) that could be enough, because then wisely "macro-managing" your foci (as the opposite of micro-managing) will get you more overall output. I'm consciously ignoring opportunity costs (i.e. sometimes the micromanagement will allow you to achieve some particular goal that will get you a better outcome than letting the foci stationary (something like getting two turns earlier that weapon refinement tech that will allow you to turn an incoming battle result from defeat to victory).

Problem I see right now (without influence) is there is no such cost, 1:1 trade-off between increase and decrease is not discouraging at all, there is no loss at all in foci-dancing.

But with influence, if I got my theory right, as long as you need more population focused into influence to pay for the foci-dance than the population you need to produce (without foci-dance) the extra anything (industry, research, stockpile) you are getting from the foci-dance, I think everything will be good.

Maybe better explained as follows, for the industry case:
Q>c*P

Where
C is the influence cost (IPs) of a focus switch.
F is the extra PPs you get from a focus switch.
P is the industry-focused population required to produce F PPs.
Q is the influence-focused population required to produce C IPs.
c >= 1 (probably in [2..5])

F/P (C/Q) is equal to the summation of the pop-based multipliers of the industry (influence) species trait, techs and buildings. For example, with all techs and buildings F/P is over 3. C/Q is yet to be decided but if I'm right it should be something like a half or a quarter of F/P.

Gault.Drakkor
Space Floater
Posts: 40
Joined: Sat Jul 01, 2017 4:54 am

Re: How does it work focus switching?

#11 Post by Gault.Drakkor »

What I don't understand is, why isn't it simpler?

Toss the immediate cost for switching. Increase the drop rate.

That is if you want to avoid focus dance, make the per turn cost greater then the per turn benefit. Which currently is not true. so focus dance is viable.

current
+1, -1, force energy: +3, -5
suggesting
+1, -3, force energy: +3, -6

Then you don't have to worry about what the immediate cost should be, or what the previous focus was.
Also with that it makes it so force energy isn't a down grade of the penalty side( absolute and relative), suggestion is only a downgrade of absolute.

User avatar
Krikkitone
Creative Contributor
Posts: 1559
Joined: Sat Sep 13, 2003 6:52 pm

Re: How does it work focus switching?

#12 Post by Krikkitone »

Gault.Drakkor wrote:What I don't understand is, why isn't it simpler?

Toss the immediate cost for switching. Increase the drop rate.

That is if you want to avoid focus dance, make the per turn cost greater then the per turn benefit. Which currently is not true. so focus dance is viable.

current
+1, -1, force energy: +3, -5
suggesting
+1, -3, force energy: +3, -6

Then you don't have to worry about what the immediate cost should be, or what the previous focus was.
Also with that it makes it so force energy isn't a down grade of the penalty side( absolute and relative), suggestion is only a downgrade of absolute.
Very much agree.
If focus dancing is to be avoided, then just have things drop faster

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

Re: How does it work focus switching?

#13 Post by Vezzra »

Gault.Drakkor wrote:What I don't understand is, why isn't it simpler?

Toss the immediate cost for switching. Increase the drop rate.
Sure, that's a possible viable approach.

However, the basic issue here is that the scale of the various meters is not comparable. For switching between industry and research that works, as 1PP is roughly equal 1RP. But e.g. the planetary shield and supply meters have a very different scale (and for both meters there are foci which can boost them).

E.g. an increase or drop of 1PP/RP isn't the same as an increase/drop of 1 supply. Therefore, if you e.g. want to boost your supply range in a certain area, just switch some of your colonies to (I think it's) the Logistics focus. Within each turn, your supply range increases by 1, which equals one more jump - not spectacular, but still considerable. Loosing 2 or 3 industry/research per turn on the colonies that have been switched is a comparably small cost. Switch back for a couple of turns so your industry/research meters can recover, then switch to Logistics again.

This is probably a very exotic example, but it illustrates the fundamental problem. To account for that, you'd have to have different growth/shrink rates for the different meter types, depending on their overall scale throughout a typical game. Which of course can be done, but then this approach isn't quite as simple anymore. At least not simpler than a simple influence "fee". ;)

User avatar
Krikkitone
Creative Contributor
Posts: 1559
Joined: Sat Sep 13, 2003 6:52 pm

Re: How does it work focus switching?

#14 Post by Krikkitone »

Vezzra wrote:
Gault.Drakkor wrote:What I don't understand is, why isn't it simpler?

Toss the immediate cost for switching. Increase the drop rate.
Sure, that's a possible viable approach.

However, the basic issue here is that the scale of the various meters is not comparable. For switching between industry and research that works, as 1PP is roughly equal 1RP. But e.g. the planetary shield and supply meters have a very different scale (and for both meters there are foci which can boost them).

E.g. an increase or drop of 1PP/RP isn't the same as an increase/drop of 1 supply. Therefore, if you e.g. want to boost your supply range in a certain area, just switch some of your colonies to (I think it's) the Logistics focus. Within each turn, your supply range increases by 1, which equals one more jump - not spectacular, but still considerable. Loosing 2 or 3 industry/research per turn on the colonies that have been switched is a comparably small cost. Switch back for a couple of turns so your industry/research meters can recover, then switch to Logistics again.

This is probably a very exotic example, but it illustrates the fundamental problem. To account for that, you'd have to have different growth/shrink rates for the different meter types, depending on their overall scale throughout a typical game. Which of course can be done, but then this approach isn't quite as simple anymore. At least not simpler than a simple influence "fee". ;)

Well then revert them to max meters... or possibly make them max meters for focus switching only (ie when you switch focus all meters are reduced to their maximum under the new focus.)

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

Re: How does it work focus switching?

#15 Post by Oberlus »

Vezzra wrote:the basic issue here is that the scale of the various meters is not comparable. For switching between industry and research that works, as 1PP is roughly equal 1RP. But e.g. the planetary shield and supply meters have a very different scale (and for both meters there are foci which can boost them).
Doesn't seem difficult to balance the change rate of the different meters (please, correct me if I'm wrong in the assumptions):
EFS: Energy Force Structure
* Research and industry: +1/-3 (decrease is 3x faster) or +3/-5 when has EFS (so decrease is 1.66x faster) (*). More formulaic:
NextTurnMeter = min(CurrentMeter+1+2*HAS_EFS ,MaxMeter) if CurrentMeter<MaxMeter or max(CurrentMeter-3-2*HAS_EFS,MaxMeter) if CurrentMeter>MaxMeter
* Planetary shields and troops: I haven't checked the actual (composite) formulae the shields and troops already have to decide the increase or decrease rate (based on researched defense techs, current planet focus and current MaxMeter and CurrentMeter), but I assume the formulae are already more or less adjusted to the dimension of each meter (shield and troops) or could be further adjusted, and the point would be to make the formula for decrease to give values roughly equivalent to twice the corresponding rate for increase.
* Stockpile: I wouldn't dare to try to find an equivalence between Stockpile and Industry/Research points. From playtesting current (and previous, similar) IS mechanics, I can tell that making it +1/-3 could work just fine (with or without the inclusion of the same effect EFS has in Industry/Research meters, to make it +3/-5).
* Supply: Maybe +1/-1, unaffected by EFS, is enough (if we rely on the penalisation over the RP/PP). However, if it is possible to have a +0.5 supply value without this causing any problem (because the supply spread algorithm does support real numbers or because it can round them down to integers), then I would suggest +0.5/-1, which should work charms (you need 2 turns to get the extra +1 supply you are looking for instead of one, for which you'll lose 3+6 PPs, and then you'll need 6 turns to get your industry back to max, further increasing the loses to 24 PPs (for that extra +1 hop during a single turn).

If these ratios between decrease and increase ratios (3:1 for Res., Ind. and Sto., 2:1 for defense and supply, although just 1:1 for supply would be reasonable too) seem not enough --for example, if you think that paying 24 PPs to get an extra hop for faster expansion is cheap compared to the benefits you'll get from it, which then encourages you to do that kind of micromanagement and you would like it to be really discouraging--, then we can make them bigger the ratio decrease:increase of the Industry and Research meters. Make them 5:1 (and the previous example to get +1 supply would require 70 PPs), or 10:1 (you get the idea).

The definitive solution would be to make the ratio infinite:1. That is, CurrentMeter is not allowed to be over MaxMeter (as Krikkitone has suggested right now).


(*) I like that the EFS makes the penalisation smaller (without eliminating it), so I wouldn't like to make it +3/-6 as suggested by Gault.Drakkor.

Post Reply