mirror of
https://github.com/yairm210/Unciv.git
synced 2025-02-20 19:56:51 +01: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 incomplete branches have higher priorities than any newly adoptable branch,
|
||||||
if (maxAdoptablePriority <= maxIncompletePriority) {
|
if (maxAdoptablePriority <= maxIncompletePriority) {
|
||||||
// Prioritize finishing one of the unfinished branches
|
// Prioritize finishing one of the unfinished branches
|
||||||
incompleteBranches.filter {
|
incompleteBranches.filter { priorityMap[it] == maxIncompletePriority }.toSet()
|
||||||
priorityMap[it] == maxIncompletePriority
|
|
||||||
}.toSet()
|
|
||||||
}
|
}
|
||||||
// If newly adoptable branches have higher priorities than any incomplete branch,
|
// If newly adoptable branches have higher priorities than any incomplete branch,
|
||||||
else {
|
else {
|
||||||
// Prioritize adopting one of the new branches
|
// Prioritize adopting one of the new branches
|
||||||
adoptableBranches.filter {
|
adoptableBranches.filter { priorityMap[it] == maxAdoptablePriority }.toSet()
|
||||||
priorityMap[it] == maxAdoptablePriority
|
|
||||||
}.toSet()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// branchCompletionMap but keys are only candidates
|
// branchCompletionMap but keys are only candidates
|
||||||
val candidateCompletionMap: Map<PolicyBranch, Int> =
|
val candidateCompletionMap: Map<PolicyBranch, Int> =
|
||||||
civInfo.policies.branchCompletionMap.filterKeys { key ->
|
civInfo.policies.branchCompletionMap.filterKeys { key -> key in candidates }
|
||||||
key in candidates
|
|
||||||
}
|
|
||||||
|
|
||||||
// Choose the branch with the LEAST REMAINING policies, not the MOST ADOPTED ones
|
// 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 =
|
val policyToAdopt: Policy =
|
||||||
if (civInfo.policies.isAdoptable(targetBranch)) targetBranch
|
if (civInfo.policies.isAdoptable(targetBranch)) targetBranch
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ class UniqueDocsWriter {
|
||||||
// by their UniqueTarget.ordinal as well - source code order.
|
// by their UniqueTarget.ordinal as well - source code order.
|
||||||
val targetTypesToUniques: Map<UniqueTarget, List<UniqueType>> =
|
val targetTypesToUniques: Map<UniqueTarget, List<UniqueType>> =
|
||||||
if (showUniqueOnOneTarget)
|
if (showUniqueOnOneTarget)
|
||||||
UniqueType.entries.asSequence()
|
UniqueType.entries
|
||||||
.groupBy { it.targetTypes.minOrNull()!! }
|
.groupBy { it.targetTypes.minOrNull()!! }
|
||||||
.toSortedMap()
|
.toSortedMap()
|
||||||
else
|
else
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user