-
Notifications
You must be signed in to change notification settings - Fork 0
/
random-adventure-plot-generator.py
61 lines (43 loc) · 1.59 KB
/
random-adventure-plot-generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Simple Python script that generates random plot seeds for an adventure
# by Alberto Tonda, <alberto.tonda@gmail.com>
import os
import pandas as pd
import random
import sys
def load_all_csv_from_folder(folder) :
csv_files = [ os.path.join(folder, f) for f in os.listdir(folder) if f.endswith(".csv") ]
pd_list = []
for csv_file in csv_files :
df = pd.read_csv(csv_file)
pd_list.append(df)
return pd.concat(pd_list)
def main() :
tropes_folder = "tropes"
monsters_folder = "monsters"
print("Loading tropes...")
pd_tropes = load_all_csv_from_folder(tropes_folder)
print("Loding monsters...")
pd_monsters = load_all_csv_from_folder(monsters_folder)
# let's extract 5 random tropes
random_indexes = []
while len(random_indexes) < 5 :
index = random.randint(0, len(pd_tropes))
if index not in random_indexes :
random_indexes.append(index)
tropes = [ pd_tropes.iloc[i].values for i in random_indexes ]
print("%d random tropes:" % len(tropes))
for trope in tropes :
print("\t\"%s\" -> %s" % (trope[0], trope[1]))
# let's extract 5 random D&D monsters
random_indexes = []
while len(random_indexes) < 5 :
index = random.randint(0, len(pd_monsters))
if index not in random_indexes :
random_indexes.append(index)
monsters = [ pd_monsters.iloc[i].values for i in random_indexes ]
print("%d random monsters:" % len(monsters))
for monster in monsters :
print("\t\"%s\"" % monster[0])
return
if __name__ == "__main__" :
sys.exit( main() )