## Thursday, September 27, 2018

### Dungeon Stocking Update and Program

I just finished writing a quick python program to spam my stocking method as much as I need, and after several runs, I've further tweaked the percentages I developed in my last post. As it turns out, I didn't plan for enough empty rooms. I won't claim to have arrived at the following numbers by any analytical method; I just plugged numbers in and hit run until the results looked good. Still, the initial analysis did get me in the ballpark.

So now, these are the percentages I'm running for each sort of encounter:

Monsters: 38%
Traps: 15%
Puzzles: 7%

These combine to yields the following probabilities:

Empty Room: 49.011%
Monster & Trap: 5.7%
Monster & Puzzle: 2.66%
Trap & Puzzle: 1.050%
All Three: 0.399%

I'm pretty happy with these results, so I'll probably move forward like this.

For those of you who might be interested, below is the code I used in python to create the generator. Please note that I am not a programmer, so I'm sure this is sloppy, doesn't conform to any standards, and probably can be written 1,000 times better. That said, it works, and I probably won't bother to improve on it for the foreseeable future.

# Version 1.0
# 9/26/2018
#
# This program will use a random number generator to randomly decide the contents of a room based on preset odds.

# Importing random for later use
import random

# defining the odds of any given event occurring. Integers represent the total percent chance of the even happening

odds_puzzle = 7
odds_trap = 15
odds_monster = 38

# defining the function for determining if an event is in the room
def roller(odds):
check = random.randint(1,100)
if check <= odds:
return 1
else:
return 0

# defining the main function

def main():
# initializing variables
monster_total = 0
trap_total = 0
puzzle_total = 0
empty_rooms = 0
monster_and_trap = 0
monster_and_puzzle = 0
trap_and_puzzle = 0
mtp = 0
# clearing output file 'output.txt'
# gathering inputs
# validating the input is not an exception

valid1 = False
while not
valid1:
try:
rooms = int(input("How many rooms would you like to generate? "))
except:
print("Please enter an integer greater than 0")
# Yay, it's an integer!
# Checking to see if the user asked for a Positive number of rooms. What the heck is a negative number of rooms anyway?

else:
if rooms <= 0:
print("Please enter an integer greater than 0")
else:
valid1 = True
# Okay. Moving on...

# Acquiring a file name to save the output to:

filename1 = str(input("What file name would you like to save the output as? "))

# opening a file with the name aquired above
file = open(filename1,"a+")

# Starting a for loop that will run once for each room desired.
for i in range(rooms):
# Checking for a monster event in the room by calling roller with the odds_monster input
monster = roller(odds_monster)
monster_total = monster_total + monster
# Checking for a trap event in the room by calling roller with the odds_trap input
trap = roller(odds_trap)
trap_total = trap_total + trap
# Checking for a puzzle event in the room by calling roller with the odds_puzzle input
puzzle = roller(odds_puzzle)
puzzle_total = puzzle_total + puzzle
# Assembling each room's contents in a single variable to be printed on the screen
contents = [i+1]
if monster == 1:
contents.append("Monster")
else:
contents.append(" ")
if trap == 1:
contents.append("Trap")
else:
contents.append(" ")
if puzzle == 1:
contents.append("Puzzle")
else:
contents.append(" ")

# Display room contents
# Commented out to avoid an info-dump into the command line
# print(contents)

# Writing room contents to output.txt

file.write("%d\t\t" % contents)
file.write(contents)
file.write(" ")
file.write(contents)
file.write(" ")
file.write(contents)
file.write("\n")

# Calculating a bunch data for a summary at the end of the room disgorge
# Calculating the total number of empty rooms
if ( monster + trap + puzzle ) == 0:
empty_rooms = empty_rooms + 1
# calculating rooms with monster and trap
if (monster + trap) == 2:
monster_and_trap = monster_and_trap + 1
# calculating rooms with monster and puzzle
if ( monster + puzzle ) == 2:
monster_and_puzzle = monster_and_puzzle + 1
# calculating rooms with trap and puzzle
if ( trap + puzzle ) == 2:
trap_and_puzzle = trap_and_puzzle + 1
# calculating rooms with monster, trap, and puzzle
if ( monster + trap + puzzle ) > 2:
mtp = mtp + 1
# Calculating the rate of occurrence for different room contents
monster_rate = monster_total / rooms
trap_rate = trap_total / rooms
puzzle_rate = puzzle_total / rooms
empty_rate = empty_rooms / rooms
mt_rate = monster_and_trap / rooms
mp_rate = monster_and_puzzle / rooms
tp_rate = trap_and_puzzle / rooms
mtp_rate = mtp / rooms

# returning totals from run, along with occurrence percentages listed parenthetically
print("\nTotal number of rooms with monsters: ",monster_total,"(",monster_rate,")")
print("Total number of rooms with traps: ",trap_total,"(",trap_rate,")")
print("Total number of rooms with puzzles: ",puzzle_total,"(",puzzle_rate,")")
print("Total number of empty rooms: ",empty_rooms,"(",empty_rate,")")
print("Total number of rooms with monsters and traps: ",monster_and_trap,"(",mt_rate,")")
print("Total number of rooms with monster and puzzle: ",monster_and_puzzle,"(",mp_rate,")")
print("Total number of rooms with traps and puzzles: ",trap_and_puzzle,"(",tp_rate,")")
print("Total number of rooms with monsters, traps, and puzzles: ",mtp,"(",mtp_rate,")")

# running the main function
main()