Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # =============================================================================
- # Copyright (c) 2020 luckytyphlosion
- # Permission to use, copy, modify, and/or distribute this software for any
- # purpose with or without fee is hereby granted.
- # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
- # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- # AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
- # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
- # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
- # OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- # PERFORMANCE OF THIS SOFTWARE.
- # =============================================================================
- import random
- NUM_TRIALS = 10000
- ENCOUNTER_COUNTS_SIZE = 20
- # RRRRRUU UUUUUU ULL2UUUU3UU
- def main():
- steps = "DDDDDLLLLLD UUULLLL DDDDLL" + " " + "RRRRRUU UUUUUU ULL2UUUU3UU"
- encounter_counts = [0] * (ENCOUNTER_COUNTS_SIZE + 1)
- for i in range(NUM_TRIALS):
- num_encounters = 0
- encounter_cooldown = 0
- facing_direction = steps[0]
- in_movement = True
- for step in steps:
- if step == " ":
- encounter_cooldown = 0
- elif "0" <= step <= "9":
- encounter_cooldown = max(encounter_cooldown - int(step), 0)
- elif facing_direction != " " and not ("0" <= step <= "9") and step != facing_direction and not in_movement:
- if encounter_cooldown == 0:
- raise RuntimeError("Bad assumption with encounter_cooldown!")
- encounter_cooldown -= 1
- if encounter_cooldown > 0:
- encounter_cooldown -= 1
- in_movement = True
- facing_direction = step
- if step == " " or "0" <= step <= "9":
- continue
- if encounter_cooldown == 0 and random.randint(0, 255) < 25:
- num_encounters += 1
- encounter_cooldown = 5
- in_movement = False
- if num_encounters > ENCOUNTER_COUNTS_SIZE:
- raise RuntimeError("Exceeded allocated number of encounters!")
- encounter_counts[num_encounters] += 1
- average_encounters = sum(x * i for i, x in enumerate(encounter_counts)) / NUM_TRIALS
- output = ""
- for i, encounter_count in enumerate(encounter_counts):
- output += f"{i}: {encounter_count}\n"
- output += f"\naverage_encounters: {average_encounters}\n"
- with open("r29_encounter_sims_out.txt", "w+") as f:
- f.write(output)
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement