Domination-victory AI declare war on close civs even when having an advantage that isn't an absolute advantage,

and declare war on civs that are situated far away if they are weak enough and there's no one close by
This commit is contained in:
Yair Morgenstern 2019-07-02 00:00:41 +03:00
parent 275fa5842a
commit 4d5f3a51e3
4 changed files with 32 additions and 26 deletions

View File

@ -21,8 +21,8 @@ android {
applicationId "com.unciv.app"
minSdkVersion 14
targetSdkVersion 28
versionCode 264
versionName "2.17.11"
versionCode 266
versionName "2.17.12-patch1"
}
// Had to add this crap for Travis to build, it wanted to sign the app

View File

@ -261,7 +261,7 @@ class Automation {
fun square(x:Int) = x*x
val unitStrength = civInfo.getCivUnits().map { square(max(it.baseUnit().strength, it.baseUnit().rangedStrength)) }.sum()
val cityStrength = civInfo.cities.map { square(CityCombatant(it).getCityStrength()) }.sum()
return (sqrt(unitStrength.toDouble()) /*+ sqrt(cityStrength.toDouble())*/).toInt() + 1 //avoid 0
return (sqrt(unitStrength.toDouble()) /*+ sqrt(cityStrength.toDouble())*/).toInt() + 1 //avoid 0, becaus we divide by the result
}
fun threatAssessment(assessor:CivilizationInfo, assessed: CivilizationInfo): ThreatLevel {

View File

@ -329,30 +329,36 @@ class NextTurnAutomation{
private fun declareWar(civInfo: CivilizationInfo) {
if (civInfo.isCityState()) return
if (civInfo.victoryType()==VictoryType.Cultural)
return
if (civInfo.victoryType() == VictoryType.Cultural) return
if (civInfo.cities.isEmpty() || civInfo.diplomacy.isEmpty()) return
if (civInfo.isAtWar() || civInfo.getHappiness() <= 0) return
if (civInfo.cities.isNotEmpty() && civInfo.diplomacy.isNotEmpty()) {
val ourMilitaryUnits = civInfo.getCivUnits().filter { !it.type.isCivilian() }.size
if (!civInfo.isAtWar() && civInfo.getHappiness() > 0
&& ourMilitaryUnits >= civInfo.cities.size) { //evaluate war
val ourCombatStrength = Automation().evaluteCombatStrength(civInfo)
val enemyCivsByDistanceToOurs = civInfo.getKnownCivs()
.filterNot { it == civInfo || it.cities.isEmpty() || !civInfo.getDiplomacyManager(it).canDeclareWar() }
.groupBy { getMinDistanceBetweenCities(civInfo, it) }
.toSortedMap()
val ourMilitaryUnits = civInfo.getCivUnits().filter { !it.type.isCivilian() }.size
if (ourMilitaryUnits < civInfo.cities.size) return
for (group in enemyCivsByDistanceToOurs) {
if (group.key > 7) break
for (otherCiv in group.value) {
if (Automation().evaluteCombatStrength(otherCiv) * 2 < ourCombatStrength) {
civInfo.getDiplomacyManager(otherCiv).declareWar()
return
}
}
}
}
//evaluate war
val enemyCivs = civInfo.getKnownCivs()
.filterNot { it == civInfo || it.cities.isEmpty() || !civInfo.getDiplomacyManager(it).canDeclareWar() }
if (enemyCivs.isEmpty()) return
var enemyCivsToEvaluate = enemyCivs.filter { getMinDistanceBetweenCities(civInfo, it) <= 7 }
var isFightingFarAway = false
if (enemyCivsToEvaluate.isEmpty()) { // so, there ARE civs we can declare war on, just not close by
if (civInfo.victoryType() != VictoryType.Domination) return // No point in attacking civs that are too far away
enemyCivsToEvaluate = enemyCivs
isFightingFarAway = true
}
val weakestCloseCiv = enemyCivsToEvaluate.minBy { Automation().evaluteCombatStrength(it) }!!
val weakestCloseCivCombatStrength = Automation().evaluteCombatStrength(weakestCloseCiv)
val ourCombatStrength = Automation().evaluteCombatStrength(civInfo)
val amountWeNeedToBeStronger =
if (civInfo.victoryType() == VictoryType.Domination && !isFightingFarAway) 1.5f else 2f
if (weakestCloseCivCombatStrength * amountWeNeedToBeStronger < ourCombatStrength)
civInfo.getDiplomacyManager(weakestCloseCiv).declareWar()
}
private fun automateUnits(civInfo: CivilizationInfo) {

View File

@ -11,7 +11,7 @@ import com.badlogic.gdx.utils.Array
import com.unciv.UnCivGame
import com.unciv.models.gamebasics.GameBasics
import com.unciv.models.gamebasics.tr
import java.util.LinkedHashMap
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
import kotlin.collections.set
@ -26,7 +26,7 @@ class Tutorials{
fun displayTutorials(name: String, stage: Stage) {
if (UnCivGame.Current.settings.showTutorials) return
if (!UnCivGame.Current.settings.showTutorials) return
if (UnCivGame.Current.settings.tutorialsShown.contains(name)) return
val texts = getTutorials(name, UnCivGame.Current.settings.language)
tutorialTexts.add(Tutorial(name,texts))