Business, Economics, Accounting and Finance
I present to you, life simulation 1.0
I present to you, life simulation 1.0.
First, initialize an object with optional parameters. All arguments, including bankSavings, are optional and have reasonable default values.
1
>>> life_simulation = LifeSimulation(startAge = 18)
Copied!
objFn is the objective function to maximize:
1
>>> life_simulation.run(objFn = lambda state:
2
state.time.with(state.relationships.loved_ones))
3
Simulating life starting at age 18...
4
---------------
5
Died at 18.01 year(s) old due to <PhysicalError: Starvation>.
6
Traceback:
7
PhysicalError: Starvation
Copied!
Oops, we spent too much time with our parents and significant other that we forgot to eat! We need to remember eat and drink. Let's schedule that periodically:
1
>>> life_simulation.run(objFn = lambda state:
2
state.time.with(state.relationships.loved_ones),
3
schedule = {every('8h'): eatAndDrink})
4
Simulating life starting at age 18...
5
---------------
6
Died at 18.3 year(s) old due to <PhysicalError: Starvation>.
7
Traceback:
8
PhysicalError: Starvation
9
↖FinancialError: Bankrupt
Copied!
Turns out spending time eating and drinking with your loved ones without income is not very sustainable. Let's get employed and get paid:
1
>>> life_simulation.run(objFn = lambda state:
2
state.time.with(state.relationships.loved_ones),
3
schedule = {every('8h'): eatAndDrink,
4
every('1d'): work,
5
now () : jobHunt})
6
Simulating life starting at age 18...
7
---------------
8
Warning: `jobHunt` failed due to <SocialError: Insufficient education>.
9
Died at 18.3 year(s) old due to <PhysicalError: Starvation>.
10
Traceback:
11
PhysicalError: Starvation
12
↖FinancialError: Bankrupt
Copied!
Bummers. Let's fix that real quick (error message trimmed with <...>):
1
>>> life_simulation.run(objFn = lambda state:
2
state.time.with(state.relationships.loved_ones),
3
schedule = {every('8h'): eatAndDrink,
4
every('1d'): work,
5
now () : {'do': goSchool,
6
'callback': jobHunt}})
7
Simulating life starting at age 18...
8
---------------
9
Warning: `goSchool` failed due to <FinancialError: Insufficient fund>.
10
Warning: `jobHunt` <...>
Copied!
This is getting frustrating. Let's cheat a bit.
1
life_simulation = LifeSimulation(startAge = 18, bankSavings = 100000)
Copied!
Now this (finally) works as expected:
1
>>> %%
2
Simulating life starting at age 18...
3
---------------
4
21.7 year(s) old: <PhysicalWarning:Fatigue>
5
24.3 year(s) old: <PhysicalWarning:Fatigue>
6
25.6 year(s) old: <PhysicalWarning:Fatigue>
7
25.8 year(s) old: <PhysicalWarning:Fatigue>
8
...(96 warning(s) omitted)
9
Died at 26 year(s) old due to <PhysicalError: Heart attack>.
10
Traceback:
11
PhysicalError: Heart attack
12
↖PhysicalWarning:Fatigue
Copied!
Hooray! We got 8 years more out of our (simulated) life. In the next tutorial, I will demonstrate how holidays and vacations are implemented to extend our lifespan even further.
Hope you enjoyed this tutorial. Remember to take good care of your real life.
Last modified 2yr ago
Copy link