Advertisement
luckytyphlosion

R29 + R30 Num Encounter Script

Oct 29th, 2020 (edited)
3,147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.69 KB | None | 0 0
  1. # =============================================================================
  2. # Copyright (c) 2020 luckytyphlosion
  3.  
  4. # Permission to use, copy, modify, and/or distribute this software for any
  5. # purpose with or without fee is hereby granted.
  6.  
  7. # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  8. # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. # AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  12. # OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. # PERFORMANCE OF THIS SOFTWARE.
  14. # =============================================================================
  15.  
  16. import random
  17.  
  18. NUM_TRIALS = 10000
  19. ENCOUNTER_COUNTS_SIZE = 20
  20.  
  21. # RRRRRUU UUUUUU ULL2UUUU3UU
  22. def main():
  23.     steps = "DDDDDLLLLLD UUULLLL DDDDLL" + " " + "RRRRRUU UUUUUU ULL2UUUU3UU"
  24.     encounter_counts = [0] * (ENCOUNTER_COUNTS_SIZE + 1)
  25.  
  26.     for i in range(NUM_TRIALS):
  27.         num_encounters = 0
  28.         encounter_cooldown = 0
  29.         facing_direction = steps[0]
  30.         in_movement = True
  31.         for step in steps:
  32.             if step == " ":
  33.                 encounter_cooldown = 0
  34.             elif "0" <= step <= "9":
  35.                 encounter_cooldown = max(encounter_cooldown - int(step), 0)
  36.             elif facing_direction != " " and not ("0" <= step <= "9") and step != facing_direction and not in_movement:
  37.                 if encounter_cooldown == 0:
  38.                     raise RuntimeError("Bad assumption with encounter_cooldown!")
  39.  
  40.                 encounter_cooldown -= 1
  41.  
  42.             if encounter_cooldown > 0:
  43.                 encounter_cooldown -= 1
  44.  
  45.             in_movement = True
  46.             facing_direction = step
  47.  
  48.             if step == " " or "0" <= step <= "9":
  49.                 continue
  50.  
  51.             if encounter_cooldown == 0 and random.randint(0, 255) < 25:
  52.                 num_encounters += 1
  53.                 encounter_cooldown = 5
  54.                 in_movement = False
  55.  
  56.         if num_encounters > ENCOUNTER_COUNTS_SIZE:
  57.             raise RuntimeError("Exceeded allocated number of encounters!")
  58.  
  59.         encounter_counts[num_encounters] += 1
  60.  
  61.     average_encounters = sum(x * i for i, x in enumerate(encounter_counts)) / NUM_TRIALS
  62.     output = ""
  63.     for i, encounter_count in enumerate(encounter_counts):
  64.         output += f"{i}: {encounter_count}\n"
  65.  
  66.     output += f"\naverage_encounters: {average_encounters}\n"
  67.  
  68.     with open("r29_encounter_sims_out.txt", "w+") as f:
  69.         f.write(output)
  70.  
  71. if __name__ == "__main__":
  72.     main()
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement