Module 14 · In Studio · challenge 2 of 3 in this lesson
expectedValue computes the probability-weighted sum of outcomes
A test in Studio grades it and prints a pass code.
Open
Level 3, Professional
Challenge
Implement the 30-day economy simulator and target-band validator in challenges/work/economy_sim.luau. The written solution is challenges/solutions/economy-design.md. In Play on the server, run game.ServerScriptService.RunGameTests:Invoke("economy-design", "economy-design-sim") and paste the pass code here.
- Start from
- The game at milestone m14 (download)
- Grade it
- In Studio, press Play, then run
game.ServerScriptService.RunGameTests:Invoke("economy-design", "economy-design-sim")in the server command bar. Copy the pass code from Output.
Done means
- expectedValue computes the probability-weighted sum of outcomes
- dailySource computes one day of pad, survival and crawler coin income using eventMultiplier on pads
- simulateDays advances day by day, pays upkeep up to available balance, buys affordable upgrades in order, and returns totalEarned, totalSpent, balance, upgradesBought, sinkRatio and upkeepSpent
- inTargetBands returns (ok, reason) in this order: inflation below minSinkRatio, balance-high over maxBalance, starved when upkeepSpent / totalEarned is above maxUpkeepShare, balance-low under minBalance, otherwise ok
- A 0.98 Sink Ratio with low upkeep passes, because there is no maximum Sink Ratio: spending what you earn is the target
- challenges/economy-design.luau prints TEST PASS for every check