mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-22 19:08:48 -04:00
AI: choose policy branch at random between those with the least remaining policies
This commit is contained in:
parent
76320bdc44
commit
6d278bc2fe
@ -328,26 +328,22 @@ object NextTurnAutomation {
|
||||
// If incomplete branches have higher priorities than any newly adoptable branch,
|
||||
if (maxAdoptablePriority <= maxIncompletePriority) {
|
||||
// Prioritize finishing one of the unfinished branches
|
||||
incompleteBranches.filter {
|
||||
priorityMap[it] == maxIncompletePriority
|
||||
}.toSet()
|
||||
incompleteBranches.filter { priorityMap[it] == maxIncompletePriority }.toSet()
|
||||
}
|
||||
// If newly adoptable branches have higher priorities than any incomplete branch,
|
||||
else {
|
||||
// Prioritize adopting one of the new branches
|
||||
adoptableBranches.filter {
|
||||
priorityMap[it] == maxAdoptablePriority
|
||||
}.toSet()
|
||||
adoptableBranches.filter { priorityMap[it] == maxAdoptablePriority }.toSet()
|
||||
}
|
||||
|
||||
// branchCompletionMap but keys are only candidates
|
||||
val candidateCompletionMap: Map<PolicyBranch, Int> =
|
||||
civInfo.policies.branchCompletionMap.filterKeys { key ->
|
||||
key in candidates
|
||||
}
|
||||
civInfo.policies.branchCompletionMap.filterKeys { key -> key in candidates }
|
||||
|
||||
// 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 targetBranch = candidateCompletionMap.asIterable()
|
||||
.groupBy { it.key.policies.size - it.value }
|
||||
.minByOrNull { it.key }!!.value.random().key
|
||||
|
||||
val policyToAdopt: Policy =
|
||||
if (civInfo.policies.isAdoptable(targetBranch)) targetBranch
|
||||
|
@ -42,7 +42,7 @@ class UniqueDocsWriter {
|
||||
// by their UniqueTarget.ordinal as well - source code order.
|
||||
val targetTypesToUniques: Map<UniqueTarget, List<UniqueType>> =
|
||||
if (showUniqueOnOneTarget)
|
||||
UniqueType.entries.asSequence()
|
||||
UniqueType.entries
|
||||
.groupBy { it.targetTypes.minOrNull()!! }
|
||||
.toSortedMap()
|
||||
else
|
||||
|
Loading…
x
Reference in New Issue
Block a user