-
Notifications
You must be signed in to change notification settings - Fork 2
/
clueGenerator.py
78 lines (65 loc) · 2.55 KB
/
clueGenerator.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
from clue_gen.clueChanger import changeClue
'''
Changing original clue of the whole Puzzle
:param clues - the original clues of the puzzle
'''
def changePuzzle(clues, trace = False):
across_clues = clues['across']
down_clues = clues['down']
print("\n----Generating across clues----\n")
changed_across_clues = []
for ac_clue in across_clues:
clue = ac_clue['clue']
word = ac_clue['answer']
num = ac_clue['number']
print("\n----------------------------------")
print("*** Searching clue for \"" + str(word) + "\" ***\n")
found = False
for i in range(4):
if i == 0: print("\t---Looking for definitions---\n")
elif i == 1: print("\t---Looking for synonyms---\n")
elif i == 2: print("\t---Looking for antonyms---\n")
elif i == 3: print("\t---Looking for examples---\n")
new_clue = changeClue(word, clue, i, trace)
if new_clue['new_clue'] is not None:
print("\n*** New clue for \"" + str(word) + "\" is found from " + str(new_clue['source']) + " ***")
changed_across_clues.append({'clue': new_clue['new_clue'], 'answer': word, 'number': num})
print("----------------------------------\n")
found = True
break
# No new clue cannot be found
if found is False:
print("\n*** No new clue can be found for \"" + str(word) + "\" ***")
print("----------------------------------\n")
changed_across_clues.append(ac_clue)
print("\n----Generating down clues----\n")
changed_down_clues = []
for down_clue in down_clues:
clue = down_clue['clue']
word = down_clue['answer']
num = down_clue['number']
print("\n----------------------------------")
print("*** Searching clue for \"" + str(word) + "\" ***\n")
found = False
for i in range(4):
if i == 0: print("\t---Looking for definitions---\n")
elif i == 1: print("\t---Looking for synonyms---\n")
elif i == 2: print("\t---Looking for antonyms---\n")
elif i == 3: print("\t---Looking for examples---\n")
new_clue = changeClue(word, clue, i, trace)
if new_clue['new_clue'] is not None:
print("\n*** New clue for \"" + str(word) + "\" is found from " + str(new_clue['source']) + " ***")
print("----------------------------------\n")
changed_down_clues.append({'clue': new_clue['new_clue'], 'answer': word, 'number': num})
found = True
break
# No new clue cannot be found
if found is False:
print("\n*** No new clue can be found for \"" + str(word) + "\" ***")
print("----------------------------------\n")
changed_down_clues.append(down_clue)
# Returning
return {
'across': changed_across_clues,
'down': changed_down_clues
}