diff options
Diffstat (limited to 'apworld/player_logic.py')
-rw-r--r-- | apworld/player_logic.py | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/apworld/player_logic.py b/apworld/player_logic.py index d435bbc..8e2a523 100644 --- a/apworld/player_logic.py +++ b/apworld/player_logic.py | |||
@@ -45,6 +45,18 @@ class AccessRequirements: | |||
45 | self.complete_at = None | 45 | self.complete_at = None |
46 | self.possibilities = list() | 46 | self.possibilities = list() |
47 | 47 | ||
48 | def copy(self) -> "AccessRequirements": | ||
49 | reqs = AccessRequirements() | ||
50 | reqs.items = self.items.copy() | ||
51 | reqs.progressives = self.progressives.copy() | ||
52 | reqs.rooms = self.rooms.copy() | ||
53 | reqs.letters = self.letters.copy() | ||
54 | reqs.cyans = self.cyans | ||
55 | reqs.or_logic = [[other_req.copy() for other_req in disjunction] for disjunction in self.or_logic] | ||
56 | reqs.complete_at = self.complete_at | ||
57 | reqs.possibilities = self.possibilities.copy() | ||
58 | return reqs | ||
59 | |||
48 | def merge(self, other: "AccessRequirements"): | 60 | def merge(self, other: "AccessRequirements"): |
49 | for item in other.items: | 61 | for item in other.items: |
50 | self.items.add(item) | 62 | self.items.add(item) |
@@ -88,7 +100,44 @@ class AccessRequirements: | |||
88 | 100 | ||
89 | def is_empty(self) -> bool: | 101 | def is_empty(self) -> bool: |
90 | return (len(self.items) == 0 and len(self.progressives) == 0 and len(self.rooms) == 0 and len(self.letters) == 0 | 102 | return (len(self.items) == 0 and len(self.progressives) == 0 and len(self.rooms) == 0 and len(self.letters) == 0 |
91 | and not self.cyans and len(self.or_logic) == 0 and self.complete_at is not None) | 103 | and not self.cyans and len(self.or_logic) == 0 and self.complete_at is None) |
104 | |||
105 | def __eq__(self, other: "AccessRequirements"): | ||
106 | return (self.items == other.items and self.progressives == other.progressives and self.rooms == other.rooms and | ||
107 | self.letters == other.letters and self.cyans == other.cyans and self.or_logic == other.or_logic and | ||
108 | self.complete_at == other.complete_at and self.possibilities == other.possibilities) | ||
109 | |||
110 | def simplify(self): | ||
111 | resimplify = False | ||
112 | |||
113 | if len(self.or_logic) > 0: | ||
114 | old_or_logic = self.or_logic | ||
115 | |||
116 | def remove_redundant(sub_reqs: "AccessRequirements"): | ||
117 | sub_reqs.letters = {l: v for l, v in sub_reqs.letters.items() if self.letters.get(l, 0) < v} | ||
118 | |||
119 | self.or_logic = [] | ||
120 | for disjunction in old_or_logic: | ||
121 | new_disjunction = [] | ||
122 | for ssr in disjunction: | ||
123 | remove_redundant(ssr) | ||
124 | if not ssr.is_empty(): | ||
125 | new_disjunction.append(ssr) | ||
126 | else: | ||
127 | new_disjunction.clear() | ||
128 | break | ||
129 | if len(new_disjunction) == 1: | ||
130 | self.merge(new_disjunction[0]) | ||
131 | resimplify = True | ||
132 | elif len(new_disjunction) > 1: | ||
133 | if all(cjr == new_disjunction[0] for cjr in new_disjunction): | ||
134 | self.merge(new_disjunction[0]) | ||
135 | resimplify = True | ||
136 | else: | ||
137 | self.or_logic.append(new_disjunction) | ||
138 | |||
139 | if resimplify: | ||
140 | self.simplify() | ||
92 | 141 | ||
93 | def __repr__(self): | 142 | def __repr__(self): |
94 | parts = [] | 143 | parts = [] |
@@ -190,6 +239,9 @@ class Lingo2PlayerLogic: | |||
190 | not self.world.options.shuffle_control_center_colors): | 239 | not self.world.options.shuffle_control_center_colors): |
191 | continue | 240 | continue |
192 | 241 | ||
242 | if door.type == data_pb2.DoorType.GALLERY_PAINTING and not self.world.options.shuffle_gallery_paintings: | ||
243 | continue | ||
244 | |||
193 | door_item_name = self.world.static_logic.get_door_item_name(door) | 245 | door_item_name = self.world.static_logic.get_door_item_name(door) |
194 | self.item_by_door[door.id] = (door_item_name, 1) | 246 | self.item_by_door[door.id] = (door_item_name, 1) |
195 | self.real_items.append(door_item_name) | 247 | self.real_items.append(door_item_name) |
@@ -400,6 +452,8 @@ class Lingo2PlayerLogic: | |||
400 | sub_reqs = self.get_door_open_reqs(sub_door_id) | 452 | sub_reqs = self.get_door_open_reqs(sub_door_id) |
401 | reqs.merge(sub_reqs) | 453 | reqs.merge(sub_reqs) |
402 | 454 | ||
455 | reqs.simplify() | ||
456 | |||
403 | return reqs | 457 | return reqs |
404 | 458 | ||
405 | # This gets the requirements to open a door within the world. When a door is shuffled, this means having the item | 459 | # This gets the requirements to open a door within the world. When a door is shuffled, this means having the item |