We compute next year's state from this year's state, the ruler's decisions we have parsed, and some formulas that make the game interesting.
# Input
let state = { year:1, population:100, immigrants:5, plague:0, starved:0, storage:2800, harvest:3000, yield:3, loss:200, estate:1000, market:19 }
let want = { feed:"2000", plant:"1000", buy:-20 }
# Influence
We transcribe rules from Suller. github
const rn = Math.random const fl = Math.floor const mx = Math.max
let year = state.year + 1 let market = fl(rn() * 7) + 17 let estate = state.estate + want.buy let storage = state.storage - want.buy * market let plague = rn()<0.15 ? fl(state.population/2) : 0 let population = state.population - plague let starved = mx(0, population - fl(want.feed / 20)) population -= starved storage -= want.feed let immigrants = starved ? 0 : fl((20*estate + storage) / (100*population)) + 1 population += immigrants let yielz = fl(rn() * 8) + 1 let harvest = yielz * want.plant storage += harvest - want.plant let loss = rn()<0.4 ? fl((rn()*.2+.1)*storage) : 0 storage -= loss
# Output
state = { year, population, immigrants, plague, starved, storage, harvest, yield: yielz, loss, estate, market }
//wiki.ralfbarkow.ch/assets/pages/snippet-template/basicjs.html?snippet-template HEIGHT 200
We show the chain of influences - blue decisions - beige consequences - gold resources - green chance
digraph { layout=neato; overlap = false node [style=filled] node [fillcolor=gold] storage; population; estate; node [fillcolor=lightblue] feed; buy; plant; node [fillcolor=palegreen] plague; starved; market; node [fillcolor=bisque] immigrants; deaths; harvest; yield; loss; buy -> estate buy -> market -> storage; plague -> population feed -> starved -> population feed -> storage estate -> immigrants -> population storage -> immigrants starved -> immigrants plant -> yield -> harvest -> storage plant -> storage loss -> storage plague -> deaths starved -> deaths }