fork download
  1. import random, math
  2.  
  3. def Shot_Result(acc, morale, power, armor):
  4. Morale = {1: 1., 2: 0.75, 3: 0.5, 4: 0.25}
  5. actual_acc = acc * Morale[morale]
  6. roll = random.random()
  7. if roll < actual_acc:
  8. dmg = max(0,math.floor((power-armor)/2))
  9. else:
  10. dmg = -1
  11.  
  12. return dmg
  13.  
  14.  
  15. def main(Red, Blue):
  16. red_rate, red_acc, red_armor, red_pow = Red
  17. blue_rate, blue_acc, blue_armor, blue_pow = Blue
  18.  
  19. red_health = blue_health = 10
  20. red_morale = blue_morale = 1
  21.  
  22. red_shots = [("Red", shot/100.) for shot in range(0,10000,int(red_rate*100))]
  23. blue_shots = [("Blue", shot/100.) for shot in range(0,10000,int(blue_rate*100))]
  24.  
  25. Shots = sorted(red_shots + blue_shots, key=lambda x: x[1])
  26.  
  27. print "{:^6}|{:^6}|{:^12}|{:^12}|{:^12}|{:^12}|".format("Shot","Time","Red Health","Blue Health","Red Morale","Blue Morale")
  28.  
  29. for shot in Shots:
  30. if shot[0] == "Red":
  31. dmg = Shot_Result(red_acc, red_morale, red_pow, blue_armor)
  32. if dmg >= 0:
  33. blue_health -= dmg
  34. blue_morale = min(blue_morale+1,4)
  35. else:
  36. blue_morale = max(blue_morale-1,1)
  37. else:
  38. dmg = Shot_Result(blue_acc, blue_morale, blue_pow, red_armor)
  39. if dmg >= 0:
  40. red_health -= dmg
  41. red_morale = min(red_morale+1,4)
  42. else:
  43. red_morale = max(red_morale-1,1)
  44.  
  45. print "{:^6}|{:^6}|{:^12}|{:^12}|{:^12}|{:^12}|".format(shot[0], shot[1], red_health, blue_health, red_morale, blue_morale)
  46.  
  47. if red_health <= 0:
  48. print "Blue tank is victorious!"
  49. break
  50. if blue_health <= 0:
  51. print "Red tank is victorious!"
  52. break
  53. else:
  54. print "It's a draw!"#
  55.  
  56. main((8.5,0.5,15,20),(6.5,.6,10,20)) #Fire Rate, accuracy, power, armor
  57.  
Success #stdin #stdout 0.02s 11448KB
stdin
Standard input is empty
stdout
 Shot | Time | Red Health |Blue Health | Red Morale |Blue Morale |
 Red  | 0.0  |     10     |     10     |     1      |     1      |
 Blue | 0.0  |     10     |     10     |     1      |     1      |
 Blue | 6.5  |     10     |     10     |     1      |     1      |
 Red  | 8.5  |     10     |    5.0     |     1      |     2      |
 Blue | 13.0 |    8.0     |    5.0     |     2      |     2      |
 Red  | 17.0 |    8.0     |    5.0     |     2      |     1      |
 Blue | 19.5 |    6.0     |    5.0     |     3      |     1      |
 Red  | 25.5 |    6.0     |    5.0     |     3      |     1      |
 Blue | 26.0 |    4.0     |    5.0     |     4      |     1      |
 Blue | 32.5 |    4.0     |    5.0     |     3      |     1      |
 Red  | 34.0 |    4.0     |    5.0     |     3      |     1      |
 Blue | 39.0 |    4.0     |    5.0     |     2      |     1      |
 Red  | 42.5 |    4.0     |    5.0     |     2      |     1      |
 Blue | 45.5 |    2.0     |    5.0     |     3      |     1      |
 Red  | 51.0 |    2.0     |    5.0     |     3      |     1      |
 Blue | 52.0 |    0.0     |    5.0     |     4      |     1      |
Blue tank is victorious!