mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-04 15:27:50 +07:00
Console mode for multiple game automation (#2777)
* Remove ruleset from GameSetupInfo class * Remove dependency from Gdx for file IO: - load Ruleset - save/init in GameSettings - get settings in GameSaver * Remove simulation logging from GameInfo class * MapGenerator: add switch for RNG seed verbose * PlayerPickerTable small refactor * Basic console mode * Add multithreading to console mode and refactoring. * Merge branch 'master' into console * Small refactor
This commit is contained in:

committed by
GitHub

parent
0271fdead2
commit
4bcae5f664
88
desktop/src/com/unciv/app/desktop/ConsoleLauncher.kt
Normal file
88
desktop/src/com/unciv/app/desktop/ConsoleLauncher.kt
Normal file
@ -0,0 +1,88 @@
|
||||
package com.unciv.app.desktop
|
||||
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.UncivGameParameters
|
||||
import com.unciv.logic.GameStarter
|
||||
import com.unciv.logic.civilization.PlayerType
|
||||
import com.unciv.logic.map.MapParameters
|
||||
import com.unciv.logic.map.MapSize
|
||||
import com.unciv.models.metadata.GameParameters
|
||||
import com.unciv.models.metadata.GameSettings
|
||||
import com.unciv.models.metadata.GameSpeed
|
||||
import com.unciv.models.metadata.Player
|
||||
import com.unciv.models.ruleset.RulesetCache
|
||||
import com.unciv.models.simulation.Simulation
|
||||
import com.unciv.models.simulation.SimulationStep
|
||||
import com.unciv.models.simulation.formatDuration
|
||||
import com.unciv.ui.newgamescreen.GameSetupInfo
|
||||
import java.time.Duration
|
||||
import kotlin.concurrent.thread
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
internal object ConsoleLauncher {
|
||||
@JvmStatic
|
||||
fun main(arg: Array<String>) {
|
||||
|
||||
val version = "0.1"
|
||||
val consoleParameters = UncivGameParameters(
|
||||
version,
|
||||
null,
|
||||
{ exitProcess(0) },
|
||||
null,
|
||||
null,
|
||||
true
|
||||
)
|
||||
val game = UncivGame(consoleParameters)
|
||||
|
||||
UncivGame.Current = game
|
||||
UncivGame.Current.settings = GameSettings().apply { showTutorials = false }
|
||||
UncivGame.Current.simulateMaxTurns = 1000
|
||||
UncivGame.Current.simulateUntilWin = true
|
||||
|
||||
RulesetCache.loadRulesets()
|
||||
|
||||
val gameParameters = getGameParameters("China", "Greece")
|
||||
val mapParameters = getMapParameters()
|
||||
val gameSetupInfo = GameSetupInfo(gameParameters, mapParameters)
|
||||
val newGame = GameStarter.startNewGame(gameSetupInfo)
|
||||
UncivGame.Current.gameInfo = newGame
|
||||
|
||||
var simulation = Simulation(newGame,25,4)
|
||||
|
||||
simulation.start()
|
||||
|
||||
simulation.getStats()
|
||||
println(simulation)
|
||||
}
|
||||
|
||||
private fun getMapParameters(): MapParameters {
|
||||
return MapParameters().apply {
|
||||
size = MapSize.Tiny
|
||||
noRuins = true
|
||||
noNaturalWonders = true
|
||||
}
|
||||
}
|
||||
|
||||
private fun getGameParameters(civilization1: String, civilization2: String): GameParameters {
|
||||
return GameParameters().apply {
|
||||
difficulty = "Chieftain"
|
||||
gameSpeed = GameSpeed.Quick
|
||||
noBarbarians = true
|
||||
players = ArrayList<Player>().apply {
|
||||
add(Player().apply {
|
||||
playerType = PlayerType.AI
|
||||
chosenCiv = civilization1
|
||||
})
|
||||
add(Player().apply {
|
||||
playerType = PlayerType.AI
|
||||
chosenCiv = civilization2
|
||||
})
|
||||
add(Player().apply {
|
||||
playerType = PlayerType.Human
|
||||
chosenCiv = "Spectator"
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user