-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
AI citizen focus change #11908
AI citizen focus change #11908
Conversation
@tuvus, if we're in negative happiness and we've got a 1-pop expand city with e.g. Old Faithful, I think in many cases it's best to work the happiness so our other cities can continue growing. Similary, if we're losing a lot of gold per turn, we need all our cities' help to avoid units disbandment. I often work gold tiles in small pop expand cities, especially if I'm both in negative happiness and negative gold. The AI rightfully values gold lower in small cities (you don't want citizens to get distracted by camp-luxury tiles early on), but shouldn't be completely prevented from working gold/happiness if need be. |
if (city.civ.getHappiness() < 0) { | ||
// 75% of excess food is wasted when in negative happiness | ||
yieldStats.food /= 4 | ||
yieldStats.happiness *= 2 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you put this in the duplicate if-statement above?
if (city.civ.getHappiness() < 0) // slotting Democracy specialists is an easy fix to happiness problems | ||
yieldStats.happiness *= 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to do something like this, look at line 57 for the food-related unique. Otherwise you are just guessing that we have the democracy policy unlocked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, we already have this implemented, line 61-63 accomplish this.
@@ -61,6 +61,9 @@ object Automation { | |||
for (unique in localUniqueCache.forCityGetMatchingUniques(city, UniqueType.UnhappinessFromPopulationTypePercentageChange)) | |||
if (unique.params[1] == "Specialists" && city.matchesFilter(unique.params[2])) | |||
yieldStats.happiness -= (unique.params[0].toFloat() / 100f) // relative val is negative, make positive | |||
yieldStats.science *= 1.5f // we want to be working scientists |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is more of a player preference, can we leave this out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The base value of science is pretty low. We could increase it to make the AI work scientist slots, but this would lead to them getting stuck working trade posts and Krakatoa. The 'cleanest' way to properly implement this, is to make the AI look up the abilities of the great person corresponding to the great person points and value the slots accordingly, but is a bit too complex for me to implement. It seems multiplying the value of science by 1.5 is approximately good enough to let the AI rank scientists as the highest of the specialists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good play shouldn't require a player preference. If Civilization VI is implemented, a more sophisticated algorithm needs to be in place, as there the specialist slots don't produce great person points. Also, in Civ VI, the value of a great person point is highly dependent on the specific great person you want to get, rather than the category of great person.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great scientists in the base game are generally regarded as the best great persons. In Rekmod, each type of great person is in their own gpp pool, while manufactories and customs houses are much better, You could argue engineer or merchant slots are the better slots, but when I visit the Lekmod discord, people there are obsessed with discussing scientist management, so I think it holds true across base rulesets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is more of a player preference, can we leave this out?
@tuvus, what's your proposal for letting the AI work the right specialist slots?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The prerequisite questions are:
- How do we figure out the best research slot?
- Do we want all the AI Civs to choose one specialist type?
- Do we want to choose a specific strategy that we deem best and try to get the AI and/or players to use it?
For the first question, if we want to dynamically determine this we'd need some sort of unique evaluation function that can rank the uniques together given the current game state and give us a value. It seems like we are having quite some trouble with this. Choose the best one for G&K or some other version would not play well with mods which could re-balance or completely change them.
For the second and third questions, each nation has their own personality (implemented in #10939), meaning we encourage them to be different from each-other. So why would we try and override that? Making decisions for players doesn't tend to go well, this PR for example was the result of a lighter version of that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the first question, if we want to dynamically determine this we'd need some sort of unique evaluation function that can rank the uniques together given the current game state and give us a value. It seems like we are having quite some trouble with this. Choose the best one for G&K or some other version would not play well with mods which could re-balance or completely change them.
True, and uniques also tend to get renamed quite a bit. The simplest (but not fool-proof) way to do this would be to adjust the evaluation of science, as the value of GS points is implicit in it.
For the second and third questions, each nation has their own personality (implemented in #10939), meaning we encourage them to be different from each-other. So why would we try and override that?
If I play test with the current implementation, a custom Default Civ does show to rank scientists as the highest of the specialists, but doesn't work all of them all the time. Songhai keeps prioritizing merchants, and India keeps prioritizing artists (I haven't tested for every civ).
Making decisions for players doesn't tend to go well, this PR for example was the result of a lighter version of that.
The default focus is currently not very good, so I've got to manually assign all my citizens. From playtesting, it appears this PR solves some of it, but I'll likely give it more fine-tuning in the future.
if (city.isPuppet) { | ||
// Puppets need to produce gold, but no great merchants | ||
yieldStats.gold *= 2 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also leave this out? Setting a the city focus is a bit different than hard coding some values behind the scenes.
@@ -39,7 +39,7 @@ object Automation { | |||
gpp = specialistInfo.greatPersonPoints.sumValues().toFloat() | |||
} | |||
gpp = gpp * (100 + city.currentGPPBonus) / 100 | |||
rank += gpp * 3 // GPP weight | |||
rank += gpp * 1 // GPP weight |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What exactly is the reasoning for this? The Automation doesn't use specialists very often in the first place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The AI currently doesn't distinguish between types of great person points, and doesn't know well how to use the ones they produce, which makes a calculation like this not very useful. I think it's best to set it to a low value, to act as a 'tiebreaker' between an engineer slot and an unimproved hill.
@@ -148,9 +148,9 @@ open class Stats( | |||
fun applyRankingWeights() { | |||
food *= 14 | |||
production *= 12 | |||
gold *= 8 // 3 gold worth about 2 production | |||
gold *= 6 // 2 gold worth about 1 production |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The AI generally has a problem with obtaining gold. This is partly because there aren't many gold opportunities early on. But reducing the value of gold wouldn't help.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not just the AI who uses AI citizen assignment, but also many humans do it. In the early game, the most efficient use of gold is via unit upgrades, which is a gold:production conversion of 2:1. Late in the game, with stock exchanges built, the conversion of base gold to base production is more like 2*(1+0.1+0.1+0.15+0.2) : 1*(1+0.25+0.25+0.25) = 1.77:1, or even 1.19:1 with Professional Army/Pentagon. It makes sense to scale the value of gold with era, but if I'm not mistaken the AI already takes modifiers from buildings into account.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason AI loses as much gold as it does, got more to do with how it picks city constructions, and by building roads without connecting cities. Improving their worker management might help quite a bit, but I'm not sure how to do so.
@tuvus I took your comments into consideration, is it good like this? (this won't be the last PR in the series, but I need more real-game playtesting for new additions) |
If we leave out the |
I removed it, is it better this way? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having gold be valued the lowest, even below faith probably isn't the best, but we can change that later if that is the case.
Otherwise I think this can go through now.
I prefer a point of faith over a point of excess gold, and a point of culture over a point of faith. As I said before, the conversion of gold to production is 2:1 via unit upgrades, while the conversion of faith to production is 2:1 via holy warriors. Holy warriors isn't the best faith faith sink, via e.g. religious buildings the conversion is closer to 1:1 (depending on how you do the math, but with an upfront investment into spreading the religion). I tend to prefer a point of culture to a point of faith, but the exact conversion depends on your policies, number of cities, and wether you're growing into good tiles. Science is harder to rate, as it's a non-substitutable yield, and over half the value of a scientist slot is in the scientist point generation. There are three ways in which to assign citizens, which are 1) regular tiles (farms, mines, pastures, unimproved tiles), 2) specialists (most notably scientists, but other types can be strong as well), 3) trade posts. If we make the value of scientist points implicit in the value of scientist slots (as is currently the case), we need to set it rather high to make the AI prioritise scientists over engineer slots, and over the lower-yield ones among the regular tiles. Doing so, however, will result in an over-evaluation of trade posts, which is bad. According to my sheets calculations, a value of 9 should just be enough to to strike the balance, but it isn't the ideal approach imo. Note that faith can be converted into science at a rate of approximately 1:10 by purchasing great scientists in late game, and culture is converted into science via the Rationalism tree. The value of gold is amplified by science advantage, as upgrade timings allow you to more effectively convert the advantage into a win. We could set the value of gold, faith and culture according to that of science, but for practical purposes of tile assignment, it's better to set it accoridng to the value of production. |
The best way to gain gold is to grow pop, connect trade routes and to build markets, banks, etc. not to keep stuck working merchants slots and plantations, which hurts the development of our empire. I think it's best to value yields differently for 1) citizens specialist assignement, 2) citizen non-specialist assignement, and 3) building construction assignement. Each one will also have to be weighed according to stage of the game for optimal performance, which is maybe a bit complicated due to mod-compatibily and which victory types are enabled. |
Reworks food prioritization, to become more 'gradual' instead of exactly +2 food surplus.
Reduces value of gold to 1/2 of production, as is applicable during most of the game
Increases value of science, as the great scientist pionts are implicit in their evaluation.
Increases value of Faith. Currently detrimental to AI (they spend faith on inquisitors preventing space victory), but more helpful to humans.