mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-08 23:08:35 +07:00
Better simulation automation
This commit is contained in:
@ -353,6 +353,7 @@ class Civilization : IsPartOfGameInfoSerialization {
|
|||||||
fun isAI() = playerType == PlayerType.AI
|
fun isAI() = playerType == PlayerType.AI
|
||||||
fun isAIOrAutoPlaying(): Boolean {
|
fun isAIOrAutoPlaying(): Boolean {
|
||||||
if (playerType == PlayerType.AI) return true
|
if (playerType == PlayerType.AI) return true
|
||||||
|
if (gameInfo.isSimulation()) return true
|
||||||
val worldScreen = UncivGame.Current.worldScreen ?: return false
|
val worldScreen = UncivGame.Current.worldScreen ?: return false
|
||||||
return worldScreen.viewingCiv == this && worldScreen.autoPlay.isAutoPlaying()
|
return worldScreen.viewingCiv == this && worldScreen.autoPlay.isAutoPlaying()
|
||||||
}
|
}
|
||||||
|
@ -17,8 +17,7 @@ import kotlin.time.ExperimentalTime
|
|||||||
@ExperimentalTime
|
@ExperimentalTime
|
||||||
class Simulation(
|
class Simulation(
|
||||||
private val newGameInfo: GameInfo,
|
private val newGameInfo: GameInfo,
|
||||||
val simulationsPerThread: Int = 1
|
val simulationsPerThread: Int = 1,
|
||||||
,
|
|
||||||
private val threadsNumber: Int = 1,
|
private val threadsNumber: Int = 1,
|
||||||
private val maxTurns: Int = 500
|
private val maxTurns: Int = 500
|
||||||
) {
|
) {
|
||||||
@ -67,7 +66,6 @@ class Simulation(
|
|||||||
}
|
}
|
||||||
else println("Max simulation ${step.turns} turns reached: Draw")
|
else println("Max simulation ${step.turns} turns reached: Draw")
|
||||||
|
|
||||||
print(gameInfo)
|
|
||||||
updateCounter(threadId)
|
updateCounter(threadId)
|
||||||
add(step)
|
add(step)
|
||||||
}
|
}
|
||||||
@ -80,14 +78,12 @@ class Simulation(
|
|||||||
|
|
||||||
@Suppress("UNUSED_PARAMETER") // used when activating debug output
|
@Suppress("UNUSED_PARAMETER") // used when activating debug output
|
||||||
@Synchronized fun add(step: SimulationStep, threadId: Int = 1) {
|
@Synchronized fun add(step: SimulationStep, threadId: Int = 1) {
|
||||||
// println("Thread $threadId: End simulation ($stepCounter/$maxSimulations)")
|
|
||||||
steps.add(step)
|
steps.add(step)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UNUSED_PARAMETER") // used when activating debug output
|
@Suppress("UNUSED_PARAMETER") // used when activating debug output
|
||||||
@Synchronized fun updateCounter(threadId: Int = 1) {
|
@Synchronized fun updateCounter(threadId: Int = 1) {
|
||||||
stepCounter++
|
stepCounter++
|
||||||
// println("Thread $threadId: Start simulation ($stepCounter/$maxSimulations)")
|
|
||||||
println("Simulation step ($stepCounter/$maxSimulations)")
|
println("Simulation step ($stepCounter/$maxSimulations)")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@ class SimulationStep (gameInfo: GameInfo) {
|
|||||||
var victoryType = gameInfo.getCurrentPlayerCivilization().victoryManager.getVictoryTypeAchieved()
|
var victoryType = gameInfo.getCurrentPlayerCivilization().victoryManager.getVictoryTypeAchieved()
|
||||||
var winner: String? = null
|
var winner: String? = null
|
||||||
val currentPlayer = gameInfo.currentPlayer
|
val currentPlayer = gameInfo.currentPlayer
|
||||||
// val durationString: String = formatDuration(Duration.ofMillis(System.currentTimeMillis() - startTime))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user