def randomize(self): vcr = VCR(self.seedName, 'rando') if self.vcr == True else None self.errorMsg = "" split = self.randoSettings.restrictions['MajorMinor'] graphBuilder = GraphBuilder(self.graphSettings) container = None i = 0 attempts = 500 if self.graphSettings.areaRando or self.graphSettings.doorsColorsRando or split == 'Scavenger' else 1 now = time.process_time() endDate = sys.maxsize if self.randoSettings.runtimeLimit_s < endDate: endDate = now + self.randoSettings.runtimeLimit_s self.updateLocationsClass(split) while container is None and i < attempts and now <= endDate: self.restrictions = Restrictions(self.randoSettings) if self.graphSettings.doorsColorsRando == True: DoorsManager.randomize(self.graphSettings.allowGreyDoors) self.areaGraph = graphBuilder.createGraph( self.randoSettings.maxDiff) services = RandoServices(self.areaGraph, self.restrictions) setup = RandoSetup(self.graphSettings, Logic.locations, services) container = setup.createItemLocContainer(endDate, vcr) if container is None: sys.stdout.write('*') sys.stdout.flush() i += 1 else: self.errorMsg += '\n'.join(setup.errorMsgs) now = time.process_time() if container is None: if self.graphSettings.areaRando: self.errorMsg += "Could not find an area layout with these settings\n" if self.graphSettings.doorsColorsRando: self.errorMsg += "Could not find a door color combination with these settings\n" if split == "Scavenger": self.errorMsg += "Scavenger seed generation timed out\n" if self.errorMsg == "": self.errorMsg += "Unable to process settings\n" return (True, [], []) self.areaGraph.printGraph() filler = self.createFiller(container, endDate) self.log.debug("ItemLocContainer dump before filling:\n" + container.dump()) ret = filler.generateItems(vcr=vcr) if not ret[0]: itemLocs, progItemLocs = (ret[1], ret[2]) escapeTrigger = ( itemLocs, progItemLocs, split ) if self.randoSettings.restrictions["EscapeTrigger"] else None escapeOk = graphBuilder.escapeGraph(container, self.areaGraph, self.randoSettings.maxDiff, escapeTrigger) if not escapeOk: self.errorMsg += "Could not find a solution for escape" ret = (True, ret[1], ret[2]) self.errorMsg += filler.errorMsg return ret
def __init__(self, rom, presetFileName, difficultyTarget, pickupStrategy, itemsForbidden=[], type='console', firstItemsLog=None, extStatsFilename=None, extStatsStep=None, displayGeneratedPath=False, outputFileName=None, magic=None, checkDuplicateMajor=False, vcr=False, runtimeLimit_s=0): self.interactive = False self.checkDuplicateMajor = checkDuplicateMajor if vcr == True: from utils.vcr import VCR self.vcr = VCR(rom, 'solver') else: self.vcr = None # for compatibility with some common methods of the interactive solver self.mode = 'standard' self.log = utils.log.get('Solver') self.setConf(difficultyTarget, pickupStrategy, itemsForbidden, displayGeneratedPath) self.firstLogFile = None if firstItemsLog is not None: self.firstLogFile = open(firstItemsLog, 'w') self.firstLogFile.write('Item;Location;Area\n') self.extStatsFilename = extStatsFilename self.extStatsStep = extStatsStep # can be called from command line (console) or from web site (web) self.type = type self.output = Out.factory(self.type, self) self.outputFileName = outputFileName self.loadRom(rom, magic=magic) self.presetFileName = presetFileName self.loadPreset(self.presetFileName) self.pickup = Pickup(Conf.itemsPickup) self.comeBack = ComeBack(self) self.runtimeLimit_s = runtimeLimit_s self.startTime = time.process_time()
def randomize(self): self.restrictions = Restrictions(self.randoSettings) self.errorMsg = "" graphBuilder = GraphBuilder(self.graphSettings) container = None i = 0 attempts = 500 if self.graphSettings.areaRando or self.graphSettings.doorsColorsRando else 1 now = time.process_time() endDate = sys.maxsize if self.randoSettings.runtimeLimit_s < endDate: endDate = now + self.randoSettings.runtimeLimit_s self.updateLocationsClass() while container is None and i < attempts and now <= endDate: if self.graphSettings.doorsColorsRando == True: DoorsManager.randomize(self.graphSettings.allowGreyDoors) self.areaGraph = graphBuilder.createGraph() services = RandoServices(self.areaGraph, self.restrictions) setup = RandoSetup(self.graphSettings, Logic.locations, services) container = setup.createItemLocContainer() if container is None: sys.stdout.write('*') sys.stdout.flush() i += 1 else: self.errorMsg += '\n'.join(setup.errorMsgs) now = time.process_time() if container is None: if self.graphSettings.areaRando: self.errorMsg += "Could not find an area layout with these settings" else: self.errorMsg += "Unable to process settings" return (True, [], []) graphBuilder.escapeGraph(container, self.areaGraph, self.randoSettings.maxDiff) self.areaGraph.printGraph() filler = self.createFiller(container, endDate) vcr = VCR(self.seedName, 'rando') if self.vcr == True else None self.log.debug("ItemLocContainer dump before filling:\n" + container.dump()) ret = filler.generateItems(vcr=vcr) self.errorMsg += filler.errorMsg return ret
def randomize(self): vcr = VCR(self.seedName, 'rando') if self.vcr == True else None self.errorMsg = "" split = self.randoSettings.restrictions['MajorMinor'] graphBuilder = GraphBuilder(self.graphSettings) container = None i = 0 attempts = 500 if self.graphSettings.areaRando or self.graphSettings.doorsColorsRando or split == 'Scavenger' else 1 now = time.process_time() endDate = sys.maxsize if self.randoSettings.runtimeLimit_s < endDate: endDate = now + self.randoSettings.runtimeLimit_s self.updateLocationsClass(split) while container is None and i < attempts and now <= endDate: self.restrictions = Restrictions(self.randoSettings) if self.graphSettings.doorsColorsRando == True: DoorsManager.randomize(self.graphSettings.allowGreyDoors, self.player) self.areaGraph = graphBuilder.createGraph() services = RandoServices(self.areaGraph, self.restrictions) setup = RandoSetup(self.graphSettings, Logic.locations, services, self.player) self.setup = setup container = setup.createItemLocContainer(endDate, vcr) if container is None: sys.stdout.write('*') sys.stdout.flush() i += 1 else: self.errorMsg += '\n'.join(setup.errorMsgs) now = time.process_time() if container is None: if self.graphSettings.areaRando: self.errorMsg += "Could not find an area layout with these settings" else: self.errorMsg += "Unable to process settings" self.areaGraph.printGraph() return container