Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce AI personality effect on citizen assignment #12636

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

EmperorPinguin
Copy link
Contributor

@itanasi what do you think of this?

@EmperorPinguin
Copy link
Contributor Author

Why is it failing though, this ran fine on my device, wait a moment.

@EmperorPinguin EmperorPinguin marked this pull request as draft December 13, 2024 07:08
@itanasi
Copy link
Contributor

itanasi commented Dec 13, 2024

So this just forces the weights to only span 0.5 to 1.5 instead of 0 to 2? While it's good we avoid weighing something at 0, are we just smoothing everyone back into Generic Civ?

@EmperorPinguin
Copy link
Contributor Author

So this just forces the weights to only span 0.5 to 1.5 instead of 0 to 2? While it's good we avoid weighing something at 0, are we just smoothing everyone back into Generic Civ?

Yes. Generic civ is better than most of these personalities.

@EmperorPinguin EmperorPinguin marked this pull request as ready for review December 13, 2024 07:27
@itanasi
Copy link
Contributor

itanasi commented Dec 13, 2024

My original idea I brainstormed was that we could range from 0.5 to 2. So any value below 5 scales at 0.1 step, and above is 0.2 step. That way the full range of Personalities is either half or double. Helps avoid the 0 weight issue.

Yeah I know you're annoyed Personalities effectively make some of the AI more exploitable/suboptimal. Perhaps we need a mode that turns off Leader Personalities. Or you can try manually optimizing the weights to take advantage of the Uniques. Sounds tedious honestly. But part of the reason for Personalities is to give the AI more contours in behavior so they stand out and players learn how to exploit them. Like Nuclear Ghandi or that Zulu hates you.

@EmperorPinguin
Copy link
Contributor Author

My original idea I brainstormed was that we could range from 0.5 to 2. So any value below 5 scales at 0.1 step, and above is 0.2 step. That way the full range of Personalities is either half or double. Helps avoid the 0 weight issue.

Yes, but half or double food value is not a sensible idea. It's very discrete: going 0.1 below the optimal value, and you could screw over the assignment of every citizen in every city.

@itanasi
Copy link
Contributor

itanasi commented Dec 13, 2024

Your current solution still allows halving the weight, right? I'm just noting that because this is a multiplication, the two edge cases should be half and double in my mind. Right now you've changed the range to halve and +50%. Which is a linear percentage, but unbalanced as a modifier.

@itanasi
Copy link
Contributor

itanasi commented Dec 13, 2024

Anyways, I'm fine with this change. Just want to make sure we've thought it through and slightly prefer 0.5-2 as the range since these are multiplicative weights.

On a different note, where did the Personality Weights come from originally?

@EmperorPinguin
Copy link
Contributor Author

EmperorPinguin commented Dec 13, 2024

Your current solution still allows halving the weight, right? I'm just noting that because this is a multiplication, the two edge cases should be half and double in my mind. Right now you've changed the range to halve and +50%. Which is a linear percentage, but unbalanced as a modifier.

You're right, I misread the math on that. I think that needs to be fixed in a separe PR (it looks like the range ought to be [0.67, 1.5] instead of [0.5, 1.5] as is currently the case). Edit: no, actually not, as then the range of the scaledFocus would be [0.5, 2] instead of [0, 2]. I'll mark this as a draft until that has been figured out.

@EmperorPinguin
Copy link
Contributor Author

On a different note, where did the Personality Weights come from originally?

You could look up the PR for it, I think they're designed to mimick Civ5 behaviour.

@EmperorPinguin EmperorPinguin marked this pull request as draft December 13, 2024 09:13
@itanasi
Copy link
Contributor

itanasi commented Dec 13, 2024

Your current code will make a Personality=0 become weight=0.5, and Personality=10 become weight=1.5. Therefore [0.5, 1.5].

If you intended [0.5, 2] then we probably need a separate function. Linear percentages vs exponential percentages either can work. Generally Linear is better if you're adding vs exponential for multiplying.

Also, 0.1 isn't always a huge deal. Part of the benefit of how we pick tiles/specialists is that this sorts everything and then goes down the list. So small changes typically only change the last few chosen at the margin, not the entire stack. Unfortunately as you notice this does mean we have issues looking at the full state of allocation as a whole like a human might. But solving the Knapsack Problem properly is fairly computationally intensive.

@EmperorPinguin
Copy link
Contributor Author

EmperorPinguin commented Dec 13, 2024

Your current code will make a Personality=0 become weight=0.5, and Personality=10 become weight=1.5. Therefore [0.5, 1.5].

If you intended [0.5, 2] then we probably need a separate function. Linear percentages vs exponential percentages either can work. Generally Linear is better if you're adding vs exponential for multiplying.

I intended [0.67, 1.5]; the highest value multiplies by 1.5, the lowest value divides by 1.5. For assigning value to tiles, this would make more sense than the current approach imo. In the rest of the AI logic, it adds a flat amount multiplied by the modifier to e.g. the motivation to attack. It would make sense here to let the value go to 0 if the user sets such to 0.

Also, 0.1 isn't always a huge deal. Part of the benefit of how we pick tiles/specialists is that this sorts everything and then goes down the list. So small changes typically only change the last few chosen at the margin, not the entire stack. Unfortunately as you notice this does mean we have issues looking at the full state of allocation as a whole like a human might. But solving the Knapsack Problem properly is fairly computationally intensive.

Tile assignment is about a few yields per tile. If there is a choice for multiple citizens between a 1 food 1 production, and a 2 production tile, then value difference is (foodvalue - productionvalue). This delta is pretty big by default, and reducing it a little wouldn't make a difference, but if we reduce it a bit, and then a bit more via personality, the delta might go below 0 and then the population stops growing.

@itanasi
Copy link
Contributor

itanasi commented Dec 13, 2024

Right, but in a typical game you have a spread of tile yields. So eventually you chew through all the 2Prod tiles. Obviously there's edge cases involved, but my point is at the median case you can get around this.

Alternatively, we could have the ranking target +2 Growth as the floor instead of 0 for the Starving logic so that we don't get in Zero Growth cases as easily. And override with Avoid Growth for player obv.

Also, while we're focused on how Food is affected, Personalities weights work on ALL of the yield stats. So make sure the range you pick works across buffing or neutering all yield combos.

@EmperorPinguin
Copy link
Contributor Author

Alternatively, we could have the ranking target +2 Growth as the floor instead of 0 for the Starving logic so that we don't get in Zero Growth cases as easily. And override with Avoid Growth for player obv.

That used to be the case. It was removed as it led to AI working 1 food flat tundra tiles, instead of putting the citizen to more productive use on a 4 production mine or a 5 science specialist.

Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants