-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgenerator.py
72 lines (55 loc) · 2.86 KB
/
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
62
63
64
65
66
67
68
69
70
71
from allocation import Allocation
from analyzer import Analyzer
from difficultyanalysis import DifficultyAnalysis
from utility import fail, print_ln
import time
class Generator(object):
def __init__(self, data, settings):
self.data = data
self.settings = settings
self.allocation = Allocation(data, settings)
def generate_seed(self):
MAX_ATTEMPTS = self.settings.max_attempts
success = False
start_time = time.time()
for attempts in range(MAX_ATTEMPTS):
self.shuffle()
analyzer = Analyzer(self.data, self.settings, self.allocation)
if analyzer.success:
if not self.settings.egg_goals:
success = True
else:
shift_success, goal_eggs = self.shift_eggs_to_hard_to_reach(analyzer.reachable, analyzer.hard_to_reach_items)
if shift_success:
analyzer = Analyzer(self.data, self.settings, self.allocation, goals=goal_eggs)
if analyzer.success:
success = True
if success:
difficulty_analysis = None
if not self.settings.hide_difficulty or self.settings.min_difficulty > 0 or self.settings.max_sequence_breakability != None:
# Run difficulty analysis
if self.settings.egg_goals: goals = analyzer.goals
else: goals = analyzer.hard_to_reach_items
difficulty_analysis = DifficultyAnalysis(self.data, analyzer, goals)
if self.settings.min_difficulty > 0:
if difficulty_analysis.difficulty_score < self.settings.min_difficulty:
success = False
if self.settings.max_sequence_breakability != None:
if difficulty_analysis.breakability_score > self.settings.max_sequence_breakability:
success = False
if success:
break
if not success:
fail('Unable to generate a valid seed after %d attempts.' % MAX_ATTEMPTS)
time_taken = time.time() - start_time
time_string = '%.2f seconds' % (time_taken)
print_ln('Seed generated after %d attempts in %s' % (attempts+1, time_string))
# Generate Visualization and Print Output:
if False:
Analyzer(self.data, self.settings, self.allocation, visualize=True)
self.allocation.print_important_item_locations()
return self.allocation, analyzer, difficulty_analysis
def shuffle(self):
self.allocation.shuffle(self.data, self.settings)
def shift_eggs_to_hard_to_reach(self, reachable_items, hard_to_reach_items):
return self.allocation.shift_eggs_to_hard_to_reach(self.data, self.settings, reachable_items, hard_to_reach_items)