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", "name": "Liberty",
"era": "Ancient era", "era": "Ancient era",
"priorities": { "priorities": {
"Neutral": 0, "Neutral": 10,
"Cultural": 0, "Cultural": 10,
"Diplomatic": 10, "Diplomatic": 20,
"Domination": 10, "Domination": 20,
"Scientific": 10 "Scientific": 20
}, },
"uniques": ["[+1 Culture] [in all cities]"], "uniques": ["[+1 Culture] [in all cities]"],
"policies": [ "policies": [

View File

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

View File

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

View File

@ -28,8 +28,6 @@ class PolicyManager : IsPartOfGameInfoSerialization {
var freePolicies = 0 var freePolicies = 0
var storedCulture = 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>() internal val adoptedPolicies = HashSet<String>()
var numberOfAdoptedPolicies = 0 var numberOfAdoptedPolicies = 0
var shouldOpenPolicyPicker = false var shouldOpenPolicyPicker = false