-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtester.py
executable file
·96 lines (67 loc) · 1.91 KB
/
tester.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/python
import sys
import random
from econ_sim.Simulation import Simulation
from econ_sim.Resources import Brick, Wool, Ore, Wood
from econ_sim.Inventory import Inventory
import numpy as np
def example1():
sim = Simulation()
b = Brick(sim)
# Show depreciation
for _ in range(10):
print "{} o'clock -- My {} is worth {}".format(sim.now, b, b.value)
sim.ticktock()
# Test comment by Robbie on 2016-09-16
def example2():
sim = Simulation()
inv = Inventory()
inv.deposit(Brick(sim))
inv.deposit(Brick(sim))
inv.deposit(Brick(sim))
inv.deposit(Wool(sim))
inv.print_net_worth()
sim.ticktock()
inv.deposit(Brick(sim))
inv.deposit(Wool(sim))
inv.deposit(Ore(sim))
inv.print_net_worth()
sim.ticktock()
inv.withdraw('Brick', n=3)
inv.withdraw('Wool')
inv.deposit(Brick(sim))
inv.deposit(Brick(sim))
inv.deposit(Ore(sim))
inv.print_net_worth()
sim.ticktock()
for _ in range(10):
sim.ticktock(20)
inv.print_net_worth()
print "============="
inv.plot_balance_history()
def example3():
sim = Simulation()
inv = Inventory()
for n in range(10000):
n_in = random.randint(0, 15)
n_out = random.randint(0, 15)
# Acquire new resources
resources = [ Brick, Wool, Ore, Wood ]
for _ in range(n_in):
res = random.choice(resources)
inv.deposit( res(sim) )
# Ditch some old resources
resources = inv.inventory.keys()
if len(resources) > 0:
withdraw = { r: 0 for r in resources }
for _ in range(n_out):
res = random.choice(resources)
withdraw[res] += 1
inv.withdraw(withdraw)
inv.update_balance()
sim.ticktock()
inv.plot_balance_history()
if __name__ == '__main__':
#example1()
#example2()
example3()