def __init__(self, options, *, seed=None): self.seed = seed if self.seed is None: self.seed = os.urandom(16) self.rnd = random.Random(self.seed) if options.race: self.rnd.random() # Just pull 1 random number so race seeds are different then from normal seeds but still stable. if options.multiworld: self.__logic = logic.MultiworldLogic(options, self.rnd) else: self.__logic = logic.Logic(options, self.rnd) if not options.keysanity or options.forwardfactor: item_placer = ForwardItemPlacer(self.__logic, options.forwardfactor) else: item_placer = RandomItemPlacer(self.__logic) if options.plan: assert options.multiworld is None self.readPlan(options.plan) for item, count in self.readItemPool(options, item_placer).items(): if count > 0: item_placer.addItem(item, count) item_placer.run(self.rnd) if options.goal == "random": options.goal = self.rnd.randint(-1, 8) if options.multiworld: z = None if options.output_filename is not None: z = zipfile.ZipFile(options.output_filename, "w") for n in range(options.multiworld): rom = generator.generateRom(options.multiworld_options[n], self.seed, self.__logic, multiworld=n) fname = "LADXR_Multiworld_%d_%d.gbc" % (options.multiworld, n + 1) if z: handle = z.open(fname, "w") rom.save(handle, name="LADXR") handle.close() else: rom.save(fname, name="LADXR") if options.spoilerformat != "none" and not options.race: extension = "json" if options.spoilerformat == "json" else "txt" sfname = "LADXR_Multiworld_%d_%d.%s" % (options.multiworld, n + 1, extension) log = spoilerLog.SpoilerLog(options, rom) log.output(sfname, z) else: rom = generator.generateRom(options, self.seed, self.__logic) filename = options.output_filename if filename is None: filename = "LADXR_%s.gbc" % (binascii.hexlify(self.seed).decode("ascii").upper()) rom.save(filename, name="LADXR") if options.spoilerformat != "none" and not options.race: log = spoilerLog.SpoilerLog(options, rom) log.output(options.spoiler_filename)
def __init__(self, args, roms): for rom in roms: if rom.banks[0][7] == 0x01: raise RaceRomException() self.seed = roms[0].readHexSeed() self.testOnly = args.test self.accessibleItems = [] self.inaccessibleItems = None self.outputFormat = args.spoilerformat self.args = vars(args) # Assume the broadest settings if we're dumping a seed we didn't just create if args.dump: # The witch flag causes trouble if we blindly turn it on if patches.witch.witchIsPatched(roms[0]): args.witch = True args.boomerang = "gift" args.heartpiece = True args.seashells = True args.heartcontainers = True args.owlstatues = "both" if len(roms) > 1: args.multiworld = len(roms) if not hasattr(args, "multiworld_options"): args.multiworld_options = [args] * args.multiworld world_setups = [] for rom in roms: world_setup = WorldSetup() world_setup.loadFromRom(rom) world_setups.append(world_setup) if len(world_setups) == 1: self.logic = logic.Logic(args, world_setup=world_setups[0]) else: self.logic = logic.MultiworldLogic(args, world_setups=world_setups) self._loadItems(args, roms)
def __init__(self, options, *, seed=None): self.seed = seed self.plan = None if self.seed is None: self.seed = os.urandom(16) self.rnd = random.Random(self.seed) if options.race: self.rnd.random( ) # Just pull 1 random number so race seeds are different then from normal seeds but still stable. if isinstance(options.goal, range): options.goal = self.rnd.randint(min(options.goal), max(options.goal)) if options.plan: assert options.multiworld is None self.plan = Plan(options.plan) if options.multiworld: self.__logic = logic.MultiworldLogic(options, self.rnd) else: for n in range( 1000 ): # Try the world setup in case entrance randomization generates unsolvable logic world_setup = WorldSetup() world_setup.randomize(options, self.rnd) self.__logic = logic.Logic(options, world_setup=world_setup) if options.entranceshuffle not in ( "advanced", "expert", "insanity") or len( self.__logic.iteminfo_list) == sum( itempool.ItemPool(options, self.rnd).toDict().values()): break if self.plan: for ii in self.__logic.iteminfo_list: item = self.plan.forced_items.get(ii.nameId.upper(), None) if isinstance(item, list): ii.OPTIONS = item else: ii.forced_item = item if options.multiworld: item_placer = MultiworldItemPlacer( self.__logic, options.forwardfactor if options.forwardfactor else 0.5, options.accessibility_rule, options.multiworld) elif options.dungeon_items in ('standard', 'localkeys') or options.forwardfactor: item_placer = ForwardItemPlacer(self.__logic, options.forwardfactor, options.accessibility_rule) else: item_placer = RandomItemPlacer(self.__logic, options.accessibility_rule) for item, count in self.readItemPool(options, item_placer).items(): if count > 0: item_placer.addItem(item, count) item_placer.run(self.rnd) if options.multiworld: z = None if options.output_filename is not None: z = zipfile.ZipFile(options.output_filename, "w") z.write( os.path.join(os.path.dirname(__file__), "multiworld/bizhawkConnector.lua"), "bizhawkConnector.lua") z.write( os.path.join(os.path.dirname(__file__), "multiworld/socket.dll"), "socket.dll") roms = [] for n in range(options.multiworld): rom = generator.generateRom(options.multiworld_options[n], self.seed, self.__logic, rnd=self.rnd, multiworld=n) fname = "LADXR_Multiworld_%d_%d.gbc" % (options.multiworld, n + 1) if z: handle = z.open(fname, "w") rom.save(handle, name="LADXR") handle.close() else: rom.save(fname, name="LADXR") roms.append(rom) if (options.spoilerformat != "none" or options.log_directory) and not options.race: log = spoilerLog.SpoilerLog(options, roms) if options.log_directory: filename = "LADXR_Multiworld_%d_%s_%s.json" % ( options.multiworld, datetime.now().strftime("%Y-%m-%d_%H-%M-%S"), log.seed) log_path = os.path.join(options.log_directory, filename) log.outputJson(log_path) if options.spoilerformat != "none": extension = "json" if options.spoilerformat == "json" else "txt" sfname = "LADXR_Multiworld_%d.%s" % (options.multiworld, extension) log.output(sfname, z) else: rom = generator.generateRom(options, self.seed, self.__logic, rnd=self.rnd) filename = options.output_filename if filename is None: filename = "LADXR_%s.gbc" % (binascii.hexlify( self.seed).decode("ascii").upper()) rom.save(filename, name="LADXR") if (options.spoilerformat != "none" or options.log_directory) and not options.race: log = spoilerLog.SpoilerLog(options, [rom]) if options.log_directory: filename = "LADXR_%s_%s.json" % ( datetime.now().strftime("%Y-%m-%d_%H-%M-%S"), log.seed) log_path = os.path.join(options.log_directory, filename) log.outputJson(log_path) if options.spoilerformat != "none": log.output(options.spoiler_filename)
def __init__(self, options, *, seed=None): self.seed = seed self.plan = None if self.seed is None: self.seed = os.urandom(16) self.rnd = random.Random(self.seed) if options.race: self.rnd.random( ) # Just pull 1 random number so race seeds are different then from normal seeds but still stable. if options.goal == "random": options.goal = self.rnd.randint(-1, 8) if options.plan: assert options.multiworld is None self.plan = Plan(options.plan) if options.multiworld: self.__logic = logic.MultiworldLogic(options, self.rnd) else: world_setup = WorldSetup() world_setup.randomize(options, self.rnd) self.__logic = logic.Logic(options, world_setup=world_setup) if self.plan: for ii in self.__logic.iteminfo_list: item = self.plan.forced_items.get(ii.nameId.upper(), None) if isinstance(item, list): ii.OPTIONS = item else: ii.forced_item = item if not options.keysanity or options.forwardfactor: item_placer = ForwardItemPlacer(self.__logic, options.forwardfactor, options.accessibility_rule) else: item_placer = RandomItemPlacer(self.__logic, options.accessibility_rule) for item, count in self.readItemPool(options, item_placer).items(): if count > 0: item_placer.addItem(item, count) item_placer.run(self.rnd) if options.multiworld: z = None if options.output_filename is not None: z = zipfile.ZipFile(options.output_filename, "w") for n in range(options.multiworld): rom = generator.generateRom(options.multiworld_options[n], self.seed, self.__logic, multiworld=n) fname = "LADXR_Multiworld_%d_%d.gbc" % (options.multiworld, n + 1) if z: handle = z.open(fname, "w") rom.save(handle, name="LADXR") handle.close() else: rom.save(fname, name="LADXR") if (options.spoilerformat != "none" or options.log_directory) and not options.race: log = spoilerLog.SpoilerLog(options, rom) if options.log_directory: filename = "LADXR_Multiworld_%d_%d_%s_%s.json" % ( options.multiworld, n + 1, datetime.now().strftime("%Y-%m-%d_%H-%M-%S"), log.seed) log_path = os.path.join(options.log_directory, filename) log.outputJson(log_path) if options.spoilerformat != "none": extension = "json" if options.spoilerformat == "json" else "txt" sfname = "LADXR_Multiworld_%d_%d.%s" % ( options.multiworld, n + 1, extension) log.output(sfname, z) else: rom = generator.generateRom(options, self.seed, self.__logic) filename = options.output_filename if filename is None: filename = "LADXR_%s.gbc" % (binascii.hexlify( self.seed).decode("ascii").upper()) rom.save(filename, name="LADXR") if (options.spoilerformat != "none" or options.log_directory) and not options.race: log = spoilerLog.SpoilerLog(options, rom) if options.log_directory: filename = "LADXR_%s_%s.json" % ( datetime.now().strftime("%Y-%m-%d_%H-%M-%S"), log.seed) log_path = os.path.join(options.log_directory, filename) log.outputJson(log_path) if options.spoilerformat != "none": log.output(options.spoiler_filename)