From 299635c49cb2a5410f996500b3b0d011e95ef67e Mon Sep 17 00:00:00 2001 From: 21aslade <21aslade@go.dsdmail.net> Date: Mon, 1 Jul 2019 19:20:02 -0600 Subject: [PATCH] Fix shuffling, logic bugs, remove messy debug prints --- README.md | 2 +- Randomizer/Dependency.cs | 8 ++------ Randomizer/Location.cs | 18 ++++++++++++++---- Randomizer/Shuffler.cs | 28 +++++++++++++++++++++++----- Resources/default.logic | 24 ++++++++++++++++-------- UI/MainWindow.cs | 9 ++++++++- 6 files changed, 64 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 1879d431..d76afe82 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ This program aims to randomize the item locations in such a way that all items are be available. This works sometimes, but currently is rather bugged. -It's currently in early development; it likely will silently fail randomization and be broken until you reload the ROM. +It's currently in early development; it likely will fail randomization and be broken until you reload the ROM. When it's finished to the point that it can randomize the entire game without failing often, it'll be set up on a website similar to other popular randomizers. Logic only goes up to the Cave of Flames currently; in the future it'll be extended to cover the whole game. diff --git a/Randomizer/Dependency.cs b/Randomizer/Dependency.cs index cf695a6a..bd916cb0 100644 --- a/Randomizer/Dependency.cs +++ b/Randomizer/Dependency.cs @@ -42,7 +42,6 @@ public static List GetDependencies(string logic) default: string[] splitSequence = sequence.Split(':'); string requirement = splitSequence[0]; - Console.WriteLine($"It's {requirement}"); string dungeon = ""; int count = 1; @@ -60,8 +59,6 @@ public static List GetDependencies(string logic) string[] dependencyParts = requirement.Split('.'); - Console.WriteLine($"It's also {dependencyParts[1]}"); - if (dependencyParts.Length < 2) { break; @@ -123,6 +120,7 @@ public override bool DependencyFulfilled(List availableItems, List availableItems, List availableItems, List unplacedItems = MajorItems.ToList(); List dungeonSpecificItems = DungeonItems.ToList(); @@ -180,7 +186,7 @@ public void RandomizeLocations() if (unfilledLocations.Count != 0) { - Console.WriteLine("Not all locations filled!"); + throw new ShuffleException($"There are {unfilledLocations.Count} unfilled locations!"); } using (MemoryStream ms = new MemoryStream(ROM.Instance.romData)) @@ -195,6 +201,16 @@ public void RandomizeLocations() File.WriteAllBytes(OutputDirectory + "/mcrando.gba", ROM.Instance.romData); } + private void ResetLocations() + { + foreach (Location location in Locations) + { + location.SetDefaultContents(); + location.InvalidateCache(); + location.Filled = false; + } + } + // Based off of the RandomAssumed ALttPR filler private List FillLocations(List items, List locations, List assumedItems = null, List previousLocations = null) { @@ -217,6 +233,10 @@ private List FillLocations(List items, List locations, int itemIndex = RNG.Next(items.Count); Item item = items[itemIndex]; Console.WriteLine($"Placing: {item.Type.ToString()}"); + if (item.Dungeon != "") + { + Console.WriteLine($"Dungeon: {item.Dungeon}"); + } items.RemoveAt(itemIndex); @@ -233,9 +253,7 @@ private List FillLocations(List items, List locations, if (availableLocations.Count <= 0) { - Console.WriteLine($"Could not place {item.Type.ToString()}!"); - return null; - //throw new Exception($"Could not place {item.Type.ToString()}!"); + throw new ShuffleException($"Could not place {item.Type}"); } int locationIndex = RNG.Next(availableLocations.Count); diff --git a/Resources/default.logic b/Resources/default.logic index 2ebed8fd..351f13ac 100644 --- a/Resources/default.logic +++ b/Resources/default.logic @@ -22,18 +22,18 @@ IntroItem1; Major; F252B;; Items.SmithSword IntroItem2; Major; F253B;; Items.Shield SouthKeeseCave; Minor; 32-13-00; Items.BombBag HyruleWellRight; Minor; 41-00-04 -SwiftbladeFirst; ScrollItem; 110D7B; +SwiftbladeFirst; ScrollItem; 110D7B; Helpers.HasSword -BottleScrub; PurchaseItem; 0CC0C0; Items.Shield, Items.BombBag, Helpers.HasSword#, Items.SpinAttack +BottleScrub; PurchaseItem; 0CC0C0; Items.Shield, Items.BombBag, Helpers.HasSword, Items.SpinAttack # Minish Woods Locations AccessMinishWoods; Helper;; (|Helpers.HasSword, Items.BombBag) -JabberNut; JabberNonsense; 09498C; Locations.AccessMinishWoods +JabberNut; Split; 09498C; Locations.AccessMinishWoods BelariBombs; Major; 00A00C; Locations.AccessMinishWoods # Mount Crenel Locations -AccessCrenel; Helper;; Helpers.HasBottle, (|Items.BombBag, Items.GripRing), Helpers.HasSword#, Items.SpinAttack -CrenelLowerScrub; PurchaseItem; 0CC09C; Helpers.HasBottle, Items.Shield # Technically a Crenel item, but doesn't need bombs +AccessCrenel; Helper;; Helpers.HasBottle, (|Items.BombBag, Items.GripRing), Helpers.HasSword, Items.SpinAttack +#CrenelLowerScrub; PurchaseItem; 0CC09C; Helpers.HasBottle, Items.Shield # Technically a Crenel item, but doesn't need bombs CrenelVineHole; Minor; 35-00-00; Locations.AccessCrenel, (|Items.GustJar, Items.BombBag) CrenelMinishHouse; Minor; 27-03-00; Locations.AccessCrenel, (|Items.GustJar, Items.BombBag) CrenelCaveDownstairs; Minor; 26-07-00; Locations.AccessCrenel, Items.BombBag @@ -41,6 +41,10 @@ CrenelHeartCaveLeft; Minor; 26-08-00; Locations.AccessCrenel, Items.BombBag CrenelHeartCaveRight; Minor; 26-08-01; Locations.AccessCrenel, Items.BombBag CrenelGripScrub; PurchaseItem; 0CC0A8; Locations.AccessCrenel, Items.Shield, Items.BombBag CrenelBlockChest; Minor; 26-03-00; Locations.AccessCrenel, (|Items.PacciCane, (&Items.GripRing, (|Items.GustJar, Items.LightArrow))) +Melari; Major; 00D26E; Locations.CompleteCoF + +# Castor Wilds Locations +AccessWilds; Helper;; # Deepwood locations DeepwoodAccess:Deepwood; Helper;; Locations.AccessMinishWoods, Items.JabberNut @@ -52,8 +56,8 @@ DeepwoodStatueRoom:Deepwood; DungeonItem; 48-04-01; Locations.DeepwoodAccess, It DeepwoodWestWing:Deepwood; DungeonItem; 48-05-01; Locations.DeepwoodAccess, Items.SmallKey:Deepwood DeepwoodPreBarrel:Deepwood; Minor; 48-06-01; Locations.DeepwoodAccess, (|Items.GustJar, Items.BombBag), Items.SmallKey:Deepwood DeepwoodSlugTorches:Deepwood; DungeonItem; 48-10-01; Locations.DeepwoodAccess -DeepwoodBasementNorth:Deepwood; DungeonItem; 48-11-01; Locations.DeepwoodAccess, (|Items.GustJar, (&Items.Flippers, Helpers.HasSword)), Items.SmallKey:Deepwood:3 -DeepwoodBasementSwitch:Deepwood; DungeonItem; 48-12-01; Locations.DeepwoodAccess, (|(&Items.GustJar, Items.SmallKey:Deepwood), (&Items.SmallKey:Deepwood:2, (|Items.Flippers, Items.RocsCape))) +DeepwoodBasementNorth:Deepwood; DungeonItem; 48-11-01; Locations.DeepwoodAccess, Items.GustJar, Items.SmallKey:Deepwood:3 +DeepwoodBasementSwitch:Deepwood; DungeonItem; 48-12-01; Locations.DeepwoodAccess, (|(&Items.GustJar, Items.SmallKey:Deepwood), (&Items.SmallKey:Deepwood:2, Items.RocsCape)) DeepwoodBasementEast:Deepwood; DungeonItem; 48-12-02; Locations.DeepwoodAccess, (|(&Items.GustJar, Items.SmallKey:Deepwood), Items.SmallKey:Deepwood:2) DeepwoodUpstairsChest:Deepwood; Minor; 48-17-01; Locations.DeepwoodAccess, (|Items.GustJar, Items.LanternOff) CompleteDeepwood:Deepwood; Helper;; Locations.DeepwoodAccess, Items.GustJar, Helpers.HasSword, Items.BigKey:Deepwood @@ -73,4 +77,8 @@ CoFSpinies:FlameCave; DungeonItem; 50-15-00; Locations.CoFAccess CoFBasementLava1:FlameCave; Minor; 50-17-00; Locations.CoFAccess, Items.PacciCane, Items.SmallKey:FlameCave:2 CoFBasementLava2:FlameCave; Minor; 50-17-01; Locations.CoFAccess, Items.PacciCane, Items.SmallKey:FlameCave:2 CoFBasementLavaBig:FlameCave; DungeonItem; 50-17-02; Locations.CoFAccess, Items.PacciCane, Items.SmallKey:FlameCave:2 -CompleteCoF:FlameCave; Helper;; Locations.CoFAccess, Items.PacciCane, Items.SmallKey:FlameCave:2, Items.BigKey:FlameCave \ No newline at end of file +CompleteCoF:FlameCave; Helper;; Locations.CoFAccess, Items.PacciCane, Items.SmallKey:FlameCave:2, Items.BigKey:FlameCave + +# Fortress of Winds Locations +#FortressAccess:Fortress; Helper;; Locations.AccessWilds +#FortressPrize:Prizes; Major; 09C9E6 \ No newline at end of file diff --git a/UI/MainWindow.cs b/UI/MainWindow.cs index 83b0d670..d495f135 100644 --- a/UI/MainWindow.cs +++ b/UI/MainWindow.cs @@ -41,7 +41,14 @@ private void Randomize_Click(object sender, EventArgs e) return; } - shuffler.RandomizeLocations(); + try + { + shuffler.RandomizeLocations(); + } + catch (ShuffleException error) + { + MessageBox.Show(error.Message); + } } private void LoadRom()