fork download
  1. careening = 1
  2. foehn = 4
  3.  
  4. bonus = {}
  5. bonus['atk'] = .1*foehn
  6. bonus['fire'] = bonus['atk']
  7. bonus['hp'] = .2*careening + .1*foehn
  8.  
  9. trials = 1000
  10.  
  11. navy = {
  12. 'Galley': {'n': 0, 'atk': 150, 'hp': 2000, 'fire': 0, 'chains': 0},
  13. 'Galleon': {'n': 4, 'atk': 500, 'hp': 15000, 'fire': 0, 'chains': 0},
  14. 'Fireship': {'n': 1, 'atk': 0, 'hp': 4000, 'fire': 100, 'chains': 0},
  15. 'Caravel': {'n': 7, 'atk': 200, 'hp': 6000, 'fire': 0, 'chains': 75}
  16. }
  17. enemies = {
  18. 'Boat': {'n': 0, 'atk': 50, 'hp': 300, 'fire': 0, 'chains': 0},
  19. 'Trireme': {'n': 26, 'atk': 200, 'hp': 3000, 'fire': 0, 'chains': 0},
  20. 'Turtle Ship': {'n': 13, 'atk': 150, 'hp': 10000, 'fire': 0, 'chains': 0},
  21. 'Blast Ship': {'n': 7, 'atk': 800, 'hp': 8000, 'fire': 0, 'chains': 0}
  22. }
  23.  
  24. A = ['atk', 'hp', 'fire', 'chains']
  25. enemy_totals = {}
  26. for a in A: enemy_totals[a] = 0
  27. for unit in enemies:
  28. for a in A: enemy_totals[a] += enemies[unit]['n'] * enemies[unit][a]
  29. #print enemy_totals
  30. navy_totals = {}
  31. for a in A: navy_totals[a] = 0
  32. for unit in navy:
  33. for a in A: navy_totals[a] += navy[unit]['n'] * navy[unit][a] * (1+bonus[a] if a in bonus else 1)
  34. #print navy_totals
  35. from numpy.random import rand
  36. def randomize(n): return n * (1 + 1.0/3 * (rand() - rand()))
  37. def fight(d):
  38. my_hp = navy_totals['hp']
  39. enemy_hp = enemy_totals['hp']
  40. fire, chains = 0, 0
  41. i = 0
  42. while enemy_hp > 0 and i < 50:
  43. i += 1
  44. fire += randomize(navy_totals['fire'])
  45. atk = randomize(navy_totals['atk'])
  46. my_dmg = (fire + atk)
  47. enemy_dmg = max(randomize(enemy_totals['atk']) - chains, 0)
  48. enemy_hp -= my_dmg
  49. my_hp -= enemy_dmg
  50. chains += randomize(navy_totals['chains'])
  51. return my_hp > 0 and i < 50
  52. print sum(map(fight, range(trials))), "/", trials
Success #stdin #stdout 0.22s 23760KB
stdin
Standard input is empty
stdout
690 / 1000