4
fortune = pexpect.spawn("python fortune.py")
5
fortune.logfile_read = sys.stdout
6
fortune.dont_wait = False
9
fortune.sendline("buy max land")
10
response = fortune.expect([" >","max = 0.00", "max = -0.00"])
14
fortune.sendline("end")
20
fortune.sendline("sell all land")
21
# fortune.expect(" >")
22
# fortune.sendline("show wealth")
26
fortune.sendline("buy spices")
27
fortune.expect("max = (\d+)")
28
max_to_buy = fortune.match.groups()[0]
29
fortune.sendline(str(int(max_to_buy) / 2))
32
# if not fortune.dont_wait:
33
# fortune.expect(" >")
34
# fortune.dont_wait = False
36
fortune.sendline("end")
40
fortune.sendline("sell all spices")
41
fortune.sendline(["end",""][fortune.expect([" >","max"])])
45
fortune.sendline("show wealth")
54
After 2 years, buy all land
57
- buy spices for half the cash
63
sequence = [ (4*2,[buy_land]),(4*7,[sell_land,buy_spices]),(4*9,[sell_spices,buy_land]) ]
65
modulo = sequence[i][0]
66
for x in xrange(1,4*64): # 64 years
68
# print "%d pourcent %d = %d" % (x,modulo, x%modulo)
69
for action in sequence[i][1]:
71
i = (i + 1) % len(sequence)
72
modulo = sequence[i][0]