AI: Better policy selection

This commit is contained in:
Yair Morgenstern 2023-08-10 16:20:01 +03:00
parent e406533ef0
commit 34fbe9e9a2
4 changed files with 13 additions and 19 deletions

View File

@ -72,11 +72,11 @@
"name": "Liberty",
"era": "Ancient era",
"priorities": {
"Neutral": 0,
"Cultural": 0,
"Diplomatic": 10,
"Domination": 10,
"Scientific": 10
"Neutral": 10,
"Cultural": 10,
"Diplomatic": 20,
"Domination": 20,
"Scientific": 20
},
"uniques": ["[+1 Culture] [in all cities]"],
"policies": [

View File

@ -72,11 +72,11 @@
"name": "Liberty",
"era": "Ancient era",
"priorities": {
"Neutral": 0,
"Cultural": 0,
"Diplomatic": 10,
"Domination": 10,
"Scientific": 0
"Neutral": 10,
"Cultural": 10,
"Diplomatic": 20,
"Domination": 20,
"Scientific": 20
},
"uniques": ["[+1 Culture] [in all cities]"],
"policies": [

View File

@ -581,13 +581,9 @@ object NextTurnAutomation {
civInfo.policies.branchCompletionMap.filterKeys { key ->
key in candidates
}
// The highest number of adopted child policies within a single candidate
val maxCompletion: Int =
candidateCompletionMap.maxOf { entry -> entry.value }
// The candidate closest to completion, hence the target branch
val targetBranch = candidateCompletionMap.filterValues { value ->
value == maxCompletion
}.keys.random()
// Choose the branch with the LEAST REMAINING policies, not the MOST ADOPTED ones
val targetBranch = candidateCompletionMap.minBy { it.key.policies.size - it.value }.key
val policyToAdopt: Policy =
if (civInfo.policies.isAdoptable(targetBranch)) targetBranch

View File

@ -28,8 +28,6 @@ class PolicyManager : IsPartOfGameInfoSerialization {
var freePolicies = 0
var storedCulture = 0
// TODO: 'adoptedPolicies' seems to be an internal API.
// Why is it HashSet<String> instead of HashSet<Policy>?
internal val adoptedPolicies = HashSet<String>()
var numberOfAdoptedPolicies = 0
var shouldOpenPolicyPicker = false