mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-29 15:01:09 -04:00
Better construction picking AI
This commit is contained in:
parent
e1884768fd
commit
dda38c5cd1
@ -5,6 +5,7 @@ import com.unciv.Constants
|
|||||||
import com.unciv.logic.battle.CityCombatant
|
import com.unciv.logic.battle.CityCombatant
|
||||||
import com.unciv.logic.city.CityConstructions
|
import com.unciv.logic.city.CityConstructions
|
||||||
import com.unciv.logic.city.CityInfo
|
import com.unciv.logic.city.CityInfo
|
||||||
|
import com.unciv.logic.city.SpecialConstruction
|
||||||
import com.unciv.logic.civilization.CityAction
|
import com.unciv.logic.civilization.CityAction
|
||||||
import com.unciv.logic.civilization.CivilizationInfo
|
import com.unciv.logic.civilization.CivilizationInfo
|
||||||
import com.unciv.logic.map.TileInfo
|
import com.unciv.logic.map.TileInfo
|
||||||
@ -37,7 +38,7 @@ class Automation {
|
|||||||
|
|
||||||
fun rankStatsValue(stats: Stats, civInfo: CivilizationInfo): Float {
|
fun rankStatsValue(stats: Stats, civInfo: CivilizationInfo): Float {
|
||||||
var rank = 0.0f
|
var rank = 0.0f
|
||||||
if (stats.food <= 2) rank += (stats.food * 1.2f) //food get more value to kepp city growing
|
if (stats.food <= 2) rank += (stats.food * 1.2f) //food get more value to keep city growing
|
||||||
else rank += (2.4f + (stats.food - 2) / 2) // 1.2 point for each food up to 2, from there on half a point
|
else rank += (2.4f + (stats.food - 2) / 2) // 1.2 point for each food up to 2, from there on half a point
|
||||||
|
|
||||||
if (civInfo.gold < 0 && civInfo.getStatsForNextTurn().gold <= 0) rank += stats.gold
|
if (civInfo.gold < 0 && civInfo.getStatsForNextTurn().gold <= 0) rank += stats.gold
|
||||||
@ -123,7 +124,7 @@ class Automation {
|
|||||||
relativeCostEffectiveness.add(choice)
|
relativeCostEffectiveness.add(choice)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Science
|
//Science buildings
|
||||||
val scienceBuilding = buildableNotWonders.filter { it.isStatRelated(Stat.Science) }
|
val scienceBuilding = buildableNotWonders.filter { it.isStatRelated(Stat.Science) }
|
||||||
.minBy{it.cost}
|
.minBy{it.cost}
|
||||||
if (scienceBuilding!=null) {
|
if (scienceBuilding!=null) {
|
||||||
@ -197,25 +198,34 @@ class Automation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Army
|
//Army
|
||||||
val militaryUnit = chooseMilitaryUnit(cityInfo)
|
if(cityInfo.civInfo.getStatsForNextTurn().gold>0 || (isAtWar && cityInfo.civInfo.gold > -50)) {
|
||||||
val unitsToCitiesRatio = cities.toFloat() / (militaryUnits + 1)
|
val militaryUnit = chooseMilitaryUnit(cityInfo)
|
||||||
// most buildings and civ units contribute the the civ's growth, military units are anti-growth
|
val unitsToCitiesRatio = cities.toFloat() / (militaryUnits + 1)
|
||||||
val militaryChoice = ConstructionChoice(militaryUnit,unitsToCitiesRatio/2)
|
// most buildings and civ units contribute the the civ's growth, military units are anti-growth
|
||||||
if (isAtWar) {
|
val militaryChoice = ConstructionChoice(militaryUnit, unitsToCitiesRatio / 2)
|
||||||
militaryChoice.choiceModifier=unitsToCitiesRatio*2
|
if (isAtWar) militaryChoice.choiceModifier = unitsToCitiesRatio * 2
|
||||||
|
else if (preferredVictoryType == VictoryType.Domination) militaryChoice.choiceModifier = unitsToCitiesRatio * 1.5f
|
||||||
|
relativeCostEffectiveness.add(militaryChoice)
|
||||||
}
|
}
|
||||||
relativeCostEffectiveness.add(militaryChoice)
|
|
||||||
|
|
||||||
val production = cityInfo.cityStats.currentCityStats.production
|
val production = cityInfo.cityStats.currentCityStats.production
|
||||||
|
|
||||||
// Nobody can plan 30 turns ahead, I don't care how cost-efficient you are.
|
|
||||||
|
|
||||||
val theChosenOne:String
|
val theChosenOne:String
|
||||||
if(relativeCostEffectiveness.any { it.remainingWork < production*30 }) { // it's possible that this is a new city and EVERYTHING is way expensive.
|
if(relativeCostEffectiveness.isEmpty()){ // choose one of the special constructions instead
|
||||||
|
// add science!
|
||||||
|
if(SpecialConstruction.science.isBuildable(cityConstructions))
|
||||||
|
theChosenOne="Science"
|
||||||
|
else if(SpecialConstruction.gold.isBuildable(cityConstructions))
|
||||||
|
theChosenOne="Gold"
|
||||||
|
else theChosenOne = "Nothing"
|
||||||
|
}
|
||||||
|
else if(relativeCostEffectiveness.any { it.remainingWork < production*30 }) {
|
||||||
relativeCostEffectiveness.removeAll { it.remainingWork >= production * 30 }
|
relativeCostEffectiveness.removeAll { it.remainingWork >= production * 30 }
|
||||||
theChosenOne = relativeCostEffectiveness.minBy { it.remainingWork/it.choiceModifier }!!.choice
|
theChosenOne = relativeCostEffectiveness.minBy { it.remainingWork/it.choiceModifier }!!.choice
|
||||||
}
|
}
|
||||||
else theChosenOne = relativeCostEffectiveness.minBy { it.remainingWork }!!.choice // ignore modifiers, go for the cheapest.
|
// it's possible that this is a new city and EVERYTHING is way expensive - ignore modifiers, go for the cheapest.
|
||||||
|
// Nobody can plan 30 turns ahead, I don't care how cost-efficient you are.
|
||||||
|
else theChosenOne = relativeCostEffectiveness.minBy { it.remainingWork }!!.choice
|
||||||
|
|
||||||
currentConstruction = theChosenOne
|
currentConstruction = theChosenOne
|
||||||
cityInfo.civInfo.addNotification("Work has started on [$currentConstruction]", Color.BROWN, CityAction(cityInfo.location))
|
cityInfo.civInfo.addNotification("Work has started on [$currentConstruction]", Color.BROWN, CityAction(cityInfo.location))
|
||||||
|
@ -21,22 +21,22 @@ open class SpecialConstruction(override var name: String, override val descripti
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
val science = object:SpecialConstruction("Science", "Convert production to science at a rate of 4 to 1"){
|
||||||
|
override fun isBuildable(construction: CityConstructions): Boolean {
|
||||||
|
return construction.cityInfo.civInfo.tech.getTechUniques().contains("Enables conversion of city production to science")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val gold = object:SpecialConstruction("Gold", "Convert production to gold at a rate of 4 to 1"){
|
||||||
|
override fun isBuildable(construction: CityConstructions): Boolean {
|
||||||
|
return construction.cityInfo.civInfo.tech.getTechUniques().contains("Enables conversion of city production to gold")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val idle = object:SpecialConstruction("Nothing", "The city will not produce anything."){
|
||||||
|
override fun isBuildable(construction: CityConstructions): Boolean {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
fun getSpecialConstructions(): List<SpecialConstruction> {
|
fun getSpecialConstructions(): List<SpecialConstruction> {
|
||||||
val science = object:SpecialConstruction("Science", "Convert production to science at a rate of 4 to 1"){
|
|
||||||
override fun isBuildable(construction: CityConstructions): Boolean {
|
|
||||||
return construction.cityInfo.civInfo.tech.getTechUniques().contains("Enables conversion of city production to science")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val gold = object:SpecialConstruction("Gold", "Convert production to gold at a rate of 4 to 1"){
|
|
||||||
override fun isBuildable(construction: CityConstructions): Boolean {
|
|
||||||
return construction.cityInfo.civInfo.tech.getTechUniques().contains("Enables conversion of city production to gold")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val idle = object:SpecialConstruction("Nothing", "The city will not produce anything."){
|
|
||||||
override fun isBuildable(construction: CityConstructions): Boolean {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return listOf(science,gold,idle)
|
return listOf(science,gold,idle)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user