SHOW:
|
|
- or go back to the newest paste.
| 1 | - | def simulateBattle(troop1, troop2, inc=0, inc2=0, nsim=100): |
| 1 | + | def simulateBattle(troop1, troop2, inc=0, inc2=0, nsim=1000): |
| 2 | res = range(nsim) | |
| 3 | for i in range(nsim): | |
| 4 | p1 = troop1; p2 = troop2; t = 1 | |
| 5 | while p1 < p2 and p1 > 0: | |
| 6 | if t > 1: | |
| 7 | p1 = p1 + inc | |
| 8 | p2 = p2 + inc2 | |
| 9 | else: | |
| 10 | t += 1 | |
| 11 | tp1 = p1 | |
| 12 | p1 = p1 - sum([random.random() < 0.6 for _ in range(p2)]) | |
| 13 | p2 = p2 - sum([random.random() < 0.7 for _ in range(tp1)]) | |
| 14 | res[i] = p1 <= 0 and p2 > 0 | |
| 15 | return sum(res)/(nsim*1.0) |