Skip to content

Instantly share code, notes, and snippets.

@dubik
Created August 15, 2016 12:53
Show Gist options
  • Save dubik/0fa390624afefb37859b4861966b2f7b to your computer and use it in GitHub Desktop.
Save dubik/0fa390624afefb37859b4861966b2f7b to your computer and use it in GitHub Desktop.
// Start with 20 civ and 8 mil factories
val civ_fact_init = 20
val mil_fact_init = 8
// Simulate for 2 years
val time = 356 * 2
// Consts of factories in work-days, one civ produces 1 work per day
val mil_fact_cost = 720
// Civ is twice the mil
val civ_fact_cost = mil_fact_cost * 2
println("Mil fact cost " + mil_fact_cost)
println("Civ fact cost " + civ_fact_cost)
def calculate_mil_work(day_to_stop_civ: Int, time: Int) = {
var civ_fact = civ_fact_init
var mil_fact = mil_fact_init
var civ_fact_work = 0
var mil_fact_work = 0
for (x <- 0 to time) {
civ_fact_work += civ_fact
if (x < day_to_stop_civ) {
if (civ_fact_work > civ_fact_cost) {
val built_civ_fact: Int = civ_fact_work / civ_fact_cost
if (built_civ_fact > 0) {
civ_fact += built_civ_fact
civ_fact_work -= civ_fact_cost * built_civ_fact
}
}
} else {
val built_mil_fact: Int = civ_fact_work / mil_fact_cost
if (built_mil_fact > 0) {
mil_fact += built_mil_fact
civ_fact_work -= mil_fact_cost * built_mil_fact
}
}
mil_fact_work += mil_fact
}
(mil_fact_work, civ_fact, mil_fact)
}
(1 to time - 1).map(calculate_mil_work(_, time)).sortBy(-_._1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment