-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_clues.py
80 lines (66 loc) · 2.15 KB
/
generate_clues.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import os
import sys
import random
START_CLUE = 2
LAST_CLUE = 12
CLUE_SPACE = 1000
#CLUE_SPACE = 1000
# should be consecutive digits of the form 1234...
FIRST_CLUE = 123
def zero_pad(clue):
l = len(str(clue))
m = len(str(CLUE_SPACE)) - 1
if l < m:
return "0"*(m-l) + str(clue)
else:
return str(clue)
def gen_clue_list(first, last, space, secret):
R = random.Random()
R.seed(secret)
clue_indexes = []
for i in range(first, last+1):
clue_indexes.append(R.randint(1, space))
clue_indexes[0] = FIRST_CLUE
return clue_indexes
if __name__ == "__main__":
if (len(sys.argv) != 2):
sys.exit("Need a secret number")
secret_number = int(sys.argv[1])
result = ""
try:
result = os.stat("clues")
except:
pass
if (result):
sys.exit("Clues folder already exists.")
if (not result):
os.mkdir("clues")
clue_indexes = gen_clue_list(START_CLUE, LAST_CLUE,
CLUE_SPACE, secret_number)
template_names = os.listdir(".clue-templates")
template_names.sort()
template_data = []
for t in template_names:
data = open(".clue-templates/" + t, "r").read()
template_data.append(data)
print("Hiding clues...")
for i in range(0, CLUE_SPACE):
dir_name = "clues/" + \
"0"*(len(str(CLUE_SPACE))-1 - len(str(i))) + str(i)
os.mkdir(dir_name)
file_name = open(dir_name + "/clue", "w")
if (i not in clue_indexes):
file_name.write("Nothing to see here.\n")
else:
template_index = clue_indexes.index(i)
if (template_index < len(template_data)):
if (template_index == 2):
#print template_index, clue_indexes[1]
file_name.write(template_data[template_index]
.format(zero_pad(clue_indexes[1]),
zero_pad(clue_indexes[0])))
else:
file_name.write(template_data[template_index])
else:
file_name.write("Clue: \n")
print("Done hiding clues.")