Advertisement
PapstJL4U

Comparng bodyshot vs headshot duel

Jun 6th, 2023 (edited)
750
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.15 KB | Source Code | 0 0
  1. """duels"""
  2. import random as r
  3.  
  4. DMG = 40
  5. GLOBAL_CTH = 1.0
  6. CTH_BODY = 1.0*GLOBAL_CTH
  7. CTH_HEAD = 0.25*GLOBAL_CTH
  8. ARMOUR = 50
  9. HP = 100+ARMOUR
  10.  
  11. def duel(sim=0):
  12.     player_4_body = HP
  13.     player_4_head = HP
  14.  
  15.     while(player_4_body > 0 and player_4_head > 0):
  16.    
  17.         #players shooting at the same time.
  18.         if sim==0:
  19.             player_4_head -= DMG*1 if r.random()<CTH_BODY else 0
  20.             player_4_body -= DMG*4 if r.random()<CTH_HEAD else 0
  21.             #print(f"{player_4_head=}, {player_4_body=}")
  22.  
  23.         #player going for body goes first
  24.         if sim==1:
  25.             player_4_head -= DMG*1 if r.random()<CTH_BODY else 0
  26.            
  27.             if player_4_head <= 0:
  28.                 break
  29.            
  30.             player_4_body -= DMG*4 if r.random()<CTH_HEAD else 0
  31.  
  32.         #player going for head goes first
  33.         if sim==2:
  34.             player_4_body -= DMG*4 if r.random()<CTH_HEAD else 0
  35.            
  36.             if player_4_body <= 0:
  37.                 break  
  38.            
  39.             player_4_head -= DMG*1 if r.random()<CTH_BODY else 0
  40.  
  41.     return  "Head" if player_4_body<=0  else "Body"
  42.  
  43.  
  44. if __name__ == "__main__":
  45.     stats = [duel(sim=1) for i in range(123456)]
  46.  
  47.     #print(stats)
  48.     heads = stats.count("Head")
  49.     total = len(stats)
  50.     print(f"{heads} of {total} is {round((heads/total)*100)}%")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement