mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-28 22:37:02 -04:00
AIs trade techs. Also modified AI tech choose strategy.
This commit is contained in:
parent
1a6089ead1
commit
d11cb4779b
@ -58,11 +58,11 @@ class GameInfo {
|
|||||||
|
|
||||||
while(thisPlayer.playerType==PlayerType.AI){
|
while(thisPlayer.playerType==PlayerType.AI){
|
||||||
NextTurnAutomation().automateCivMoves(thisPlayer)
|
NextTurnAutomation().automateCivMoves(thisPlayer)
|
||||||
if (thisPlayer.tech.techsToResearch.isEmpty()) { // should belong in automation? yes/no?
|
// if (thisPlayer.tech.techsToResearch.isEmpty()) { // should belong in automation? yes/no?
|
||||||
val researchableTechs = GameBasics.Technologies.values
|
// val researchableTechs = GameBasics.Technologies.values
|
||||||
.filter { !thisPlayer.tech.isResearched(it.name) && thisPlayer.tech.canBeResearched(it.name) }
|
// .filter { !thisPlayer.tech.isResearched(it.name) && thisPlayer.tech.canBeResearched(it.name) }
|
||||||
thisPlayer.tech.techsToResearch.add(researchableTechs.minBy { it.cost }!!.name)
|
// thisPlayer.tech.techsToResearch.add(researchableTechs.minBy { it.cost }!!.name)
|
||||||
}
|
// }
|
||||||
switchTurn()
|
switchTurn()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,16 +2,19 @@ package com.unciv.logic.automation
|
|||||||
|
|
||||||
import com.unciv.logic.city.CityInfo
|
import com.unciv.logic.city.CityInfo
|
||||||
import com.unciv.logic.civilization.CivilizationInfo
|
import com.unciv.logic.civilization.CivilizationInfo
|
||||||
|
import com.unciv.logic.civilization.PlayerType
|
||||||
import com.unciv.logic.map.MapUnit
|
import com.unciv.logic.map.MapUnit
|
||||||
import com.unciv.logic.trade.TradeLogic
|
import com.unciv.logic.trade.TradeLogic
|
||||||
import com.unciv.logic.trade.TradeType
|
import com.unciv.logic.trade.TradeType
|
||||||
import com.unciv.models.gamebasics.GameBasics
|
import com.unciv.models.gamebasics.GameBasics
|
||||||
|
import com.unciv.models.gamebasics.tech.Technology
|
||||||
import com.unciv.ui.utils.getRandom
|
import com.unciv.ui.utils.getRandom
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
||||||
class NextTurnAutomation{
|
class NextTurnAutomation{
|
||||||
|
|
||||||
fun automateCivMoves(civInfo: CivilizationInfo) {
|
fun automateCivMoves(civInfo: CivilizationInfo) {
|
||||||
|
exchangeTechs(civInfo)
|
||||||
chooseTechToResearch(civInfo)
|
chooseTechToResearch(civInfo)
|
||||||
adoptPolicy(civInfo)
|
adoptPolicy(civInfo)
|
||||||
exchangeLuxuries(civInfo)
|
exchangeLuxuries(civInfo)
|
||||||
@ -22,11 +25,43 @@ class NextTurnAutomation{
|
|||||||
trainSettler(civInfo)
|
trainSettler(civInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun exchangeTechs(civInfo: CivilizationInfo) {
|
||||||
|
for (otherCiv in civInfo.diplomacy.values.map { it.otherCiv() }.filter { it.playerType == PlayerType.AI }.sortedBy { it.tech.techsResearched.size }) {
|
||||||
|
val tradeLogic = TradeLogic(civInfo, otherCiv)
|
||||||
|
val ourTradableTechs = tradeLogic.ourAvailableOffers
|
||||||
|
.filter { it.type == TradeType.Technology }
|
||||||
|
val theirTradableTechs = tradeLogic.theirAvailableOffers
|
||||||
|
.filter { it.type == TradeType.Technology }
|
||||||
|
|
||||||
|
for (ourOffer in ourTradableTechs) {
|
||||||
|
val theirOfferList = theirTradableTechs.filter{
|
||||||
|
tradeLogic.evaluateOffer(ourOffer, false) >= tradeLogic.evaluateOffer(it, false)
|
||||||
|
&& !tradeLogic.currentTrade.theirOffers.contains(it) }
|
||||||
|
if (theirOfferList.isNotEmpty()) {
|
||||||
|
tradeLogic.currentTrade.ourOffers.add(ourOffer)
|
||||||
|
tradeLogic.currentTrade.theirOffers.add(theirOfferList.getRandom())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tradeLogic.currentTrade.theirOffers.isNotEmpty()) {
|
||||||
|
tradeLogic.acceptTrade()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun chooseTechToResearch(civInfo: CivilizationInfo) {
|
private fun chooseTechToResearch(civInfo: CivilizationInfo) {
|
||||||
if (civInfo.tech.techsToResearch.isEmpty()) {
|
if (civInfo.tech.techsToResearch.isEmpty()) {
|
||||||
val researchableTechs = GameBasics.Technologies.values.filter { civInfo.tech.canBeResearched(it.name) }
|
val researchableTechs = GameBasics.Technologies.values.filter { !civInfo.tech.isResearched(it.name) && civInfo.tech.canBeResearched(it.name) }
|
||||||
val techToResearch = researchableTechs.groupBy { it.cost }.minBy { it.key }!!.value.getRandom()
|
val techsGroups = researchableTechs.groupBy { it.cost }
|
||||||
civInfo.tech.techsResearched.add(techToResearch.name)
|
val costs = techsGroups.keys.sorted()
|
||||||
|
|
||||||
|
val tech: Technology
|
||||||
|
if (techsGroups[costs[0]]!!.size == 1 || costs.size == 1) {
|
||||||
|
tech = techsGroups[costs[0]]!!.getRandom()
|
||||||
|
} else {
|
||||||
|
tech = (techsGroups[costs[0]]!! + techsGroups[costs[1]]!!).getRandom()
|
||||||
|
}
|
||||||
|
civInfo.tech.techsToResearch.add(tech.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user