| 
									
										
										
										
											2020-03-16 17:39:54 +11:00
										 |  |  | import unittest | 
					
						
							| 
									
										
										
										
											2021-07-04 16:18:21 +02:00
										 |  |  | from argparse import Namespace | 
					
						
							| 
									
										
										
										
											2020-03-16 17:39:54 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-17 03:23:27 +02:00
										 |  |  | from BaseClasses import MultiWorld, CollectionState, ItemClassification | 
					
						
							| 
									
										
										
										
											2020-10-24 05:38:56 +02:00
										 |  |  | from worlds.alttp.Dungeons import create_dungeons, get_dungeon_item_pool | 
					
						
							|  |  |  | from worlds.alttp.EntranceShuffle import mandatory_connections, connect_simple | 
					
						
							|  |  |  | from worlds.alttp.ItemPool import difficulties, generate_itempool | 
					
						
							|  |  |  | from worlds.alttp.Items import ItemFactory | 
					
						
							| 
									
										
										
										
											2021-01-30 23:29:32 +01:00
										 |  |  | from worlds.alttp.Regions import create_regions | 
					
						
							| 
									
										
										
										
											2021-01-30 23:43:15 +01:00
										 |  |  | from worlds.alttp.Shops import create_shops | 
					
						
							| 
									
										
										
										
											2020-10-24 05:38:56 +02:00
										 |  |  | from worlds.alttp.Rules import set_rules | 
					
						
							| 
									
										
										
										
											2021-07-04 16:18:21 +02:00
										 |  |  | from worlds import AutoWorld | 
					
						
							| 
									
										
										
										
											2020-03-16 17:39:54 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class TestDungeon(unittest.TestCase): | 
					
						
							|  |  |  |     def setUp(self): | 
					
						
							| 
									
										
										
										
											2021-03-14 08:38:02 +01:00
										 |  |  |         self.world = MultiWorld(1) | 
					
						
							| 
									
										
										
										
											2021-07-04 16:18:21 +02:00
										 |  |  |         args = Namespace() | 
					
						
							| 
									
										
										
										
											2022-08-15 16:46:59 -05:00
										 |  |  |         for name, option in AutoWorld.AutoWorldRegister.world_types["A Link to the Past"].option_definitions.items(): | 
					
						
							| 
									
										
										
										
											2021-07-04 16:18:21 +02:00
										 |  |  |             setattr(args, name, {1: option.from_any(option.default)}) | 
					
						
							|  |  |  |         self.world.set_options(args) | 
					
						
							| 
									
										
										
										
											2021-09-17 00:17:54 +02:00
										 |  |  |         self.world.set_default_common_options() | 
					
						
							| 
									
										
										
										
											2020-05-10 19:54:40 +10:00
										 |  |  |         self.starting_regions = []  # Where to start exploring | 
					
						
							|  |  |  |         self.remove_exits = []      # Block dungeon exits | 
					
						
							| 
									
										
										
										
											2020-04-29 01:34:30 +10:00
										 |  |  |         self.world.difficulty_requirements[1] = difficulties['normal'] | 
					
						
							| 
									
										
										
										
											2020-03-16 17:39:54 +11:00
										 |  |  |         create_regions(self.world, 1) | 
					
						
							|  |  |  |         create_dungeons(self.world, 1) | 
					
						
							| 
									
										
										
										
											2020-04-29 01:34:30 +10:00
										 |  |  |         create_shops(self.world, 1) | 
					
						
							| 
									
										
										
										
											2020-03-16 17:39:54 +11:00
										 |  |  |         for exitname, regionname in mandatory_connections: | 
					
						
							|  |  |  |             connect_simple(self.world, exitname, regionname, 1) | 
					
						
							| 
									
										
										
										
											2020-04-29 01:34:30 +10:00
										 |  |  |         connect_simple(self.world, 'Big Bomb Shop', 'Big Bomb Shop', 1) | 
					
						
							| 
									
										
										
										
											2020-05-10 19:54:40 +10:00
										 |  |  |         self.world.get_region('Menu', 1).exits = [] | 
					
						
							| 
									
										
										
										
											2020-03-16 17:39:54 +11:00
										 |  |  |         self.world.swamp_patch_required[1] = True | 
					
						
							| 
									
										
										
										
											2021-07-22 15:59:37 +02:00
										 |  |  |         self.world.worlds[1].set_rules() | 
					
						
							|  |  |  |         self.world.worlds[1].create_items() | 
					
						
							| 
									
										
										
										
											2020-03-16 17:39:54 +11:00
										 |  |  |         self.world.itempool.extend(get_dungeon_item_pool(self.world)) | 
					
						
							|  |  |  |         self.world.itempool.extend(ItemFactory(['Green Pendant', 'Red Pendant', 'Blue Pendant', 'Beat Agahnim 1', 'Beat Agahnim 2', 'Crystal 1', 'Crystal 2', 'Crystal 3', 'Crystal 4', 'Crystal 5', 'Crystal 6', 'Crystal 7'], 1)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def run_tests(self, access_pool): | 
					
						
							| 
									
										
										
										
											2020-05-10 19:54:40 +10:00
										 |  |  |         for exit in self.remove_exits: | 
					
						
							|  |  |  |             self.world.get_entrance(exit, 1).connected_region = self.world.get_region('Menu', 1) | 
					
						
							| 
									
										
										
										
											2020-03-16 17:39:54 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  |         for location, access, *item_pool in access_pool: | 
					
						
							|  |  |  |             items = item_pool[0] | 
					
						
							|  |  |  |             all_except = item_pool[1] if len(item_pool) > 1 else None | 
					
						
							|  |  |  |             with self.subTest(location=location, access=access, items=items, all_except=all_except): | 
					
						
							|  |  |  |                 if all_except and len(all_except) > 0: | 
					
						
							|  |  |  |                     items = self.world.itempool[:] | 
					
						
							|  |  |  |                     items = [item for item in items if item.name not in all_except and not ("Bottle" in item.name and "AnyBottle" in all_except)] | 
					
						
							|  |  |  |                     items.extend(ItemFactory(item_pool[0], 1)) | 
					
						
							|  |  |  |                 else: | 
					
						
							|  |  |  |                     items = ItemFactory(items, 1) | 
					
						
							|  |  |  |                 state = CollectionState(self.world) | 
					
						
							| 
									
										
										
										
											2020-05-10 19:54:40 +10:00
										 |  |  |                 state.reachable_regions[1].add(self.world.get_region('Menu', 1)) | 
					
						
							|  |  |  |                 for region_name in self.starting_regions: | 
					
						
							|  |  |  |                     region = self.world.get_region(region_name, 1) | 
					
						
							|  |  |  |                     state.reachable_regions[1].add(region) | 
					
						
							|  |  |  |                     for exit in region.exits: | 
					
						
							|  |  |  |                         if exit.connected_region is not None: | 
					
						
							|  |  |  |                             state.blocked_connections[1].add(exit) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-16 17:39:54 +11:00
										 |  |  |                 for item in items: | 
					
						
							| 
									
										
										
										
											2022-06-17 03:23:27 +02:00
										 |  |  |                     item.classification = ItemClassification.progression | 
					
						
							| 
									
										
										
										
											2020-03-16 17:39:54 +11:00
										 |  |  |                     state.collect(item) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 self.assertEqual(self.world.get_location(location, 1).can_reach(state), access) |