diff --git a/RandomizerCore/CharmNotchCosts.cs b/RandomizerCore/CharmNotchCosts.cs index fc39f87..e9b9589 100644 --- a/RandomizerCore/CharmNotchCosts.cs +++ b/RandomizerCore/CharmNotchCosts.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace RandomizerCore +namespace RandomizerCore { public static class CharmNotchCosts { diff --git a/RandomizerCore/Collections/HashQueue.cs b/RandomizerCore/Collections/HashQueue.cs index 53eb7a5..2c8969e 100644 --- a/RandomizerCore/Collections/HashQueue.cs +++ b/RandomizerCore/Collections/HashQueue.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Collections; using RandomizerCore.Extensions; namespace RandomizerCore.Logic diff --git a/RandomizerCore/Collections/PriorityQueue.cs b/RandomizerCore/Collections/PriorityQueue.cs index b1743ac..e3ab2ec 100644 --- a/RandomizerCore/Collections/PriorityQueue.cs +++ b/RandomizerCore/Collections/PriorityQueue.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Runtime.CompilerServices; +using System.Runtime.CompilerServices; namespace RandomizerCore.Collections { diff --git a/RandomizerCore/Collections/SortedArrayList.cs b/RandomizerCore/Collections/SortedArrayList.cs index c099577..4b8d4c6 100644 --- a/RandomizerCore/Collections/SortedArrayList.cs +++ b/RandomizerCore/Collections/SortedArrayList.cs @@ -1,13 +1,11 @@ using RandomizerCore.Extensions; -using System; using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace RandomizerCore.Collections { + /// + /// A sorted list which maintains its sort through binary search during list operations. + /// public class SortedArrayList : IReadOnlyList, ICollection where T : IComparable { private readonly List ts; diff --git a/RandomizerCore/Exceptions/OutOfLocationsException.cs b/RandomizerCore/Exceptions/OutOfLocationsException.cs index 867d1ac..c2be2a8 100644 --- a/RandomizerCore/Exceptions/OutOfLocationsException.cs +++ b/RandomizerCore/Exceptions/OutOfLocationsException.cs @@ -1,6 +1,4 @@ -using System; - -namespace RandomizerCore.Exceptions +namespace RandomizerCore.Exceptions { public class OutOfLocationsException : Exception { diff --git a/RandomizerCore/Exceptions/ValidationException.cs b/RandomizerCore/Exceptions/ValidationException.cs index 515c5cd..a1cf63c 100644 --- a/RandomizerCore/Exceptions/ValidationException.cs +++ b/RandomizerCore/Exceptions/ValidationException.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace RandomizerCore.Exceptions +namespace RandomizerCore.Exceptions { public class ValidationException : Exception { diff --git a/RandomizerCore/Extensions/CollectionExtensions.cs b/RandomizerCore/Extensions/CollectionExtensions.cs index 2fa0ab9..845a019 100644 --- a/RandomizerCore/Extensions/CollectionExtensions.cs +++ b/RandomizerCore/Extensions/CollectionExtensions.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace RandomizerCore.Extensions +namespace RandomizerCore.Extensions { public static class CollectionExtensions { diff --git a/RandomizerCore/Extensions/RandomExtensions.cs b/RandomizerCore/Extensions/RandomExtensions.cs index efa6eb5..de32308 100644 --- a/RandomizerCore/Extensions/RandomExtensions.cs +++ b/RandomizerCore/Extensions/RandomExtensions.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace RandomizerCore.Extensions +namespace RandomizerCore.Extensions { public static class RandomExtensions { diff --git a/RandomizerCore/Extensions/StringExtensions.cs b/RandomizerCore/Extensions/StringExtensions.cs index fe1bae7..cfefec9 100644 --- a/RandomizerCore/Extensions/StringExtensions.cs +++ b/RandomizerCore/Extensions/StringExtensions.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Text; namespace RandomizerCore.Extensions { diff --git a/RandomizerCore/GeneralizedPlacement.cs b/RandomizerCore/GeneralizedPlacement.cs index 769304e..c4e3ff3 100644 --- a/RandomizerCore/GeneralizedPlacement.cs +++ b/RandomizerCore/GeneralizedPlacement.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using RandomizerCore.Logic; +using RandomizerCore.Logic; namespace RandomizerCore { diff --git a/RandomizerCore/IPriorityModifier.cs b/RandomizerCore/IPriorityModifier.cs deleted file mode 100644 index 2e09a6b..0000000 --- a/RandomizerCore/IPriorityModifier.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using RandomizerCore.Logic; - -namespace RandomizerCore -{ - [Obsolete] - public class PriorityModifierArgs - { - public T item; - public int index; - public int priority; - public int total; - public Random rng; - - } - - [Obsolete] - public interface IPriorityModifier - { - void Modify(T item, int index, int total, Random rng, ref int priority); - } - - /* - public class ShopPriorityModifier : IPriorityModifier - { - bool first = false; - - public void Modify(RandoLocation item, int index, int total, Random rng, ref int priority) - { - if (item.multi) - { - if (!first) first = true; - else priority = total; - } - } - } - - public class DupePriorityModifier : IPriorityModifier - { - public void Modify(LogicItem item, int index, int total, Random rng, ref int priority) - { - if (item.Name == "Dupe") priority = 0; - } - } - */ -} diff --git a/RandomizerCore/Json/JsonUtil.cs b/RandomizerCore/Json/JsonUtil.cs index 58543ec..f4fe36e 100644 --- a/RandomizerCore/Json/JsonUtil.cs +++ b/RandomizerCore/Json/JsonUtil.cs @@ -1,12 +1,8 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Reflection; +using System.Reflection; using Newtonsoft.Json; using Newtonsoft.Json.Converters; using Newtonsoft.Json.Linq; using RandomizerCore.Logic; -using static RandomizerCore.LogHelper; namespace RandomizerCore.Json { diff --git a/RandomizerCore/Json/LMConverter.cs b/RandomizerCore/Json/LMConverter.cs new file mode 100644 index 0000000..2d7529f --- /dev/null +++ b/RandomizerCore/Json/LMConverter.cs @@ -0,0 +1,64 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using RandomizerCore.Logic; +using RandomizerCore.StringLogic; + +namespace RandomizerCore.Json +{ + public class LMConverter : JsonConverter + { + public override LogicManager ReadJson(JsonReader reader, Type objectType, LogicManager existingValue, bool hasExistingValue, JsonSerializer serializer) + { + LogicManagerBuilder lmb = new(); + JObject lm = JObject.Load(reader); + lmb.LP = lm[nameof(LogicManager.LP)].ToObject(); + lmb.VariableResolver = lm[nameof(LogicManager.VariableResolver)].ToObject(); + + lmb.DeserializeJson(LogicManagerBuilder.JsonType.Terms, lm["Terms"]); + lmb.DeserializeJson(LogicManagerBuilder.JsonType.Waypoints, lm["Waypoints"]); + lmb.DeserializeJson(LogicManagerBuilder.JsonType.Transitions, lm["Transitions"]); + lmb.DeserializeJson(LogicManagerBuilder.JsonType.Locations, lm["Logic"]); + lmb.DeserializeJson(LogicManagerBuilder.JsonType.Items, lm["Items"]); + + return new(lmb); + } + + public override void WriteJson(JsonWriter writer, LogicManager value, JsonSerializer serializer) + { + writer.WriteStartObject(); + + TermConverter tc = new() { LM = value }; + LogicDefConverter ldc = new() { LM = value }; + serializer.Converters.Add(tc); + serializer.Converters.Add(ldc); + + writer.WritePropertyName("Terms"); + serializer.Serialize(writer, value.Terms); + + writer.WritePropertyName("Variables"); + serializer.Serialize(writer, value.Variables); + + writer.WritePropertyName("Logic"); + serializer.Serialize(writer, value.LogicLookup.Values.Select(l => new RawLogicDef(l.Name, l.ToInfix()))); + + writer.WritePropertyName("Items"); + serializer.Serialize(writer, value.ItemLookup.Values); + + writer.WritePropertyName("Transitions"); + serializer.Serialize(writer, value.TransitionLookup.Values.Select(t => t.ToRaw())); + + writer.WritePropertyName("Waypoints"); + serializer.Serialize(writer, value.Waypoints.Select(w => new RawLogicDef(w.Name, w.logic.ToInfix()))); + + writer.WritePropertyName(nameof(value.LP)); + serializer.Serialize(writer, value.LP); + + writer.WritePropertyName(nameof(value.VariableResolver)); + serializer.Serialize(writer, value.VariableResolver); + + writer.WriteEndObject(); + serializer.Converters.Remove(ldc); + serializer.Converters.Remove(tc); + } + } +} diff --git a/RandomizerCore/Json/LogicDefConverter.cs b/RandomizerCore/Json/LogicDefConverter.cs index f94b084..c14ecdb 100644 --- a/RandomizerCore/Json/LogicDefConverter.cs +++ b/RandomizerCore/Json/LogicDefConverter.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Newtonsoft.Json; +using Newtonsoft.Json; using RandomizerCore.Logic; namespace RandomizerCore.Json diff --git a/RandomizerCore/Json/TermConverter.cs b/RandomizerCore/Json/TermConverter.cs index 05c7c0e..eedea3e 100644 --- a/RandomizerCore/Json/TermConverter.cs +++ b/RandomizerCore/Json/TermConverter.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Newtonsoft.Json; +using Newtonsoft.Json; using RandomizerCore.Logic; namespace RandomizerCore.Json diff --git a/RandomizerCore/LogHelper.cs b/RandomizerCore/LogHelper.cs index 02de7ed..7845893 100644 --- a/RandomizerCore/LogHelper.cs +++ b/RandomizerCore/LogHelper.cs @@ -1,5 +1,4 @@ -using System; -using System.Diagnostics; +using System.Diagnostics; namespace RandomizerCore { diff --git a/RandomizerCore/Logic/ILogicDef.cs b/RandomizerCore/Logic/ILogicDef.cs index c2e7baf..2d762f3 100644 --- a/RandomizerCore/Logic/ILogicDef.cs +++ b/RandomizerCore/Logic/ILogicDef.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; - -namespace RandomizerCore.Logic +namespace RandomizerCore.Logic { public interface ILogicDef { diff --git a/RandomizerCore/Logic/ILogicProcessor.cs b/RandomizerCore/Logic/ILogicProcessor.cs deleted file mode 100644 index 91cec98..0000000 --- a/RandomizerCore/Logic/ILogicProcessor.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Collections.Generic; - -namespace RandomizerCore.Logic -{ - public interface ILogicProcessor - { - IList Shunt(string infix); - } -} diff --git a/RandomizerCore/Logic/LogicCost.cs b/RandomizerCore/Logic/LogicCost.cs index 9acb1bb..d8b6952 100644 --- a/RandomizerCore/Logic/LogicCost.cs +++ b/RandomizerCore/Logic/LogicCost.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace RandomizerCore.Logic +namespace RandomizerCore.Logic { public abstract class LogicCost { diff --git a/RandomizerCore/Logic/LogicInt.cs b/RandomizerCore/Logic/LogicInt.cs index 1f24475..339bf75 100644 --- a/RandomizerCore/Logic/LogicInt.cs +++ b/RandomizerCore/Logic/LogicInt.cs @@ -1,12 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Text.RegularExpressions; -using System.Threading.Tasks; -using static RandomizerCore.LogHelper; - -namespace RandomizerCore.Logic +namespace RandomizerCore.Logic { public abstract class LogicInt { diff --git a/RandomizerCore/Logic/LogicManager.cs b/RandomizerCore/Logic/LogicManager.cs index 6e2a777..e3da322 100644 --- a/RandomizerCore/Logic/LogicManager.cs +++ b/RandomizerCore/Logic/LogicManager.cs @@ -1,72 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; +using Newtonsoft.Json; using RandomizerCore.Json; using RandomizerCore.StringLogic; -using static RandomizerCore.LogHelper; +using System.Collections.ObjectModel; namespace RandomizerCore.Logic { - public class LMConverter : JsonConverter - { - public override LogicManager ReadJson(JsonReader reader, Type objectType, LogicManager existingValue, bool hasExistingValue, JsonSerializer serializer) - { - LogicManagerBuilder lmb = new(); - JObject lm = JObject.Load(reader); - lmb.LP = lm[nameof(LogicManager.LP)].ToObject(); - lmb.VariableResolver = lm[nameof(LogicManager.VariableResolver)].ToObject(); - - lmb.DeserializeJson(LogicManagerBuilder.JsonType.Terms, lm["Terms"]); - lmb.DeserializeJson(LogicManagerBuilder.JsonType.Waypoints, lm["Waypoints"]); - lmb.DeserializeJson(LogicManagerBuilder.JsonType.Transitions, lm["Transitions"]); - lmb.DeserializeJson(LogicManagerBuilder.JsonType.Locations, lm["Logic"]); - lmb.DeserializeJson(LogicManagerBuilder.JsonType.Items, lm["Items"]); - - return new(lmb); - } - - public override void WriteJson(JsonWriter writer, LogicManager value, JsonSerializer serializer) - { - writer.WriteStartObject(); - - TermConverter tc = new() { LM = value }; - LogicDefConverter ldc = new() { LM = value }; - serializer.Converters.Add(tc); - serializer.Converters.Add(ldc); - - writer.WritePropertyName("Terms"); - serializer.Serialize(writer, value.Terms); - - writer.WritePropertyName("Variables"); - serializer.Serialize(writer, value.Variables); - - writer.WritePropertyName("Logic"); - serializer.Serialize(writer, value.LogicLookup.Values.Select(l => new RawLogicDef(l.Name, l.ToInfix()))); - - writer.WritePropertyName("Items"); - serializer.Serialize(writer, value.ItemLookup.Values); - - writer.WritePropertyName("Transitions"); - serializer.Serialize(writer, value.TransitionLookup.Values.Select(t => t.ToRaw())); - - writer.WritePropertyName("Waypoints"); - serializer.Serialize(writer, value.Waypoints.Select(w => new RawLogicDef(w.Name, w.logic.ToInfix()))); - - writer.WritePropertyName(nameof(value.LP)); - serializer.Serialize(writer, value.LP); - - writer.WritePropertyName(nameof(value.VariableResolver)); - serializer.Serialize(writer, value.VariableResolver); - - writer.WriteEndObject(); - serializer.Converters.Remove(ldc); - serializer.Converters.Remove(tc); - } - } - [JsonConverter(typeof(LMConverter))] public class LogicManager : ILogicManager { diff --git a/RandomizerCore/Logic/LogicManagerBuilder.cs b/RandomizerCore/Logic/LogicManagerBuilder.cs index e8f35e6..dc8b389 100644 --- a/RandomizerCore/Logic/LogicManagerBuilder.cs +++ b/RandomizerCore/Logic/LogicManagerBuilder.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using Newtonsoft.Json; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; using RandomizerCore.Json; using RandomizerCore.StringLogic; diff --git a/RandomizerCore/Logic/LogicOperatorRef.cs b/RandomizerCore/Logic/LogicOperatorRef.cs new file mode 100644 index 0000000..5ebc3f3 --- /dev/null +++ b/RandomizerCore/Logic/LogicOperatorRef.cs @@ -0,0 +1,25 @@ +namespace RandomizerCore.Logic +{ + public static class LogicOperatorRef + { + private static readonly Dictionary operators = new() + { + { "NONE", (int)LogicOperators.NONE }, + { "FALSE", (int)LogicOperators.NONE }, + { "ANY", (int)LogicOperators.ANY }, + { "TRUE", (int)LogicOperators.ANY }, + + { "+", (int)LogicOperators.AND }, + { "|", (int)LogicOperators.OR }, + + { ">", (int)LogicOperators.GT }, + { "<", (int)LogicOperators.LT }, + { "=", (int)LogicOperators.EQ }, + }; + + public static bool TryGetOperator(string op, out int index) + { + return operators.TryGetValue(op, out index); + } + } +} diff --git a/RandomizerCore/Logic/LogicOperators.cs b/RandomizerCore/Logic/LogicOperators.cs index 3b6ea41..7b101fa 100644 --- a/RandomizerCore/Logic/LogicOperators.cs +++ b/RandomizerCore/Logic/LogicOperators.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace RandomizerCore.Logic +namespace RandomizerCore.Logic { public enum LogicOperators { @@ -16,27 +10,4 @@ public enum LogicOperators LT = -6, EQ = -7, } - - public static class LogicOperatorRef - { - private static readonly Dictionary operators = new() - { - { "NONE", (int)LogicOperators.NONE }, - { "FALSE", (int)LogicOperators.NONE }, - { "ANY", (int)LogicOperators.ANY }, - { "TRUE", (int)LogicOperators.ANY }, - - { "+", (int)LogicOperators.AND }, - { "|", (int)LogicOperators.OR }, - - { ">", (int)LogicOperators.GT }, - { "<", (int)LogicOperators.LT }, - { "=", (int)LogicOperators.EQ }, - }; - - public static bool TryGetOperator(string op, out int index) - { - return operators.TryGetValue(op, out index); - } - } } diff --git a/RandomizerCore/Logic/LogicTransition.cs b/RandomizerCore/Logic/LogicTransition.cs index 457dbb0..6c248bf 100644 --- a/RandomizerCore/Logic/LogicTransition.cs +++ b/RandomizerCore/Logic/LogicTransition.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace RandomizerCore.Logic { diff --git a/RandomizerCore/Logic/LogicWaypoint.cs b/RandomizerCore/Logic/LogicWaypoint.cs index 07c7f70..b8d5efb 100644 --- a/RandomizerCore/Logic/LogicWaypoint.cs +++ b/RandomizerCore/Logic/LogicWaypoint.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; - -namespace RandomizerCore.Logic +namespace RandomizerCore.Logic { public class LogicWaypoint : ILogicDef, ILogicItem { diff --git a/RandomizerCore/Logic/OptimizedLogicDef.cs b/RandomizerCore/Logic/OptimizedLogicDef.cs index c8af23a..ab5cd4c 100644 --- a/RandomizerCore/Logic/OptimizedLogicDef.cs +++ b/RandomizerCore/Logic/OptimizedLogicDef.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using RandomizerCore.StringLogic; +using RandomizerCore.StringLogic; namespace RandomizerCore.Logic { diff --git a/RandomizerCore/Logic/ProgressionManager.cs b/RandomizerCore/Logic/ProgressionManager.cs index 30a88d2..b32c0a5 100644 --- a/RandomizerCore/Logic/ProgressionManager.cs +++ b/RandomizerCore/Logic/ProgressionManager.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Runtime.CompilerServices; using System.Text; -using System.Diagnostics; -using System.Runtime.CompilerServices; namespace RandomizerCore.Logic { @@ -196,18 +192,16 @@ public void SaveTempItems() AfterEndTemp?.Invoke(true); } - public ProgressionSnapshot GetSnapshot() - { - return new(lm, obtained); - } - + /// + /// Converts the ProgressionManager to a JSON-serialized dictionary with keys given by term names and values given by the integer values of the ProgressionManager for each term. + /// public override string ToString() { - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new(); sb.AppendLine("{"); for (int i = 0; i < lm.TermCount; i++) { - sb.AppendLine($" {lm.GetTerm(i)}: {obtained[i]}"); + sb.AppendLine($" \"{lm.GetTerm(i)}\": {obtained[i]},"); } sb.AppendLine("}"); return sb.ToString(); diff --git a/RandomizerCore/Logic/ProgressionSnapshot.cs b/RandomizerCore/Logic/ProgressionSnapshot.cs deleted file mode 100644 index 59dce31..0000000 --- a/RandomizerCore/Logic/ProgressionSnapshot.cs +++ /dev/null @@ -1,84 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.CompilerServices; -using System.Text; -using System.Threading.Tasks; - -namespace RandomizerCore.Logic -{ - /// - /// Immutable progression manager. - /// - public class ProgressionSnapshot - { - private readonly int[] obtained; - public LogicManager lm { get; } - - - public ProgressionSnapshot(LogicManager lm, int[] obtained) - { - this.lm = lm; - this.obtained = (int[])obtained.Clone(); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int Get(int index) - { - return obtained[index]; - } - - public int Get(string id) - { - return obtained[lm.GetTerm(id).Id]; - } - - /// - /// /// Returns true if the value at the index is greater than or equal to 0. - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Has(int index) - { - return obtained[index] > 0; - } - - /// - /// Returns true if the value at the index is greater than or equal to the threshold. - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Has(int index, int threshold) - { - return obtained[index] >= threshold; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Gt(int index, int threshold) - { - return obtained[index] > threshold; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Lt(int index, int threshold) - { - return obtained[index] < threshold; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Eq(int index, int threshold) - { - return obtained[index] == threshold; - } - - public override string ToString() - { - StringBuilder sb = new StringBuilder(); - sb.AppendLine("{"); - for (int i = 0; i < lm.TermCount; i++) - { - sb.AppendLine($" {lm.GetTerm(i)}: {obtained[i]}"); - } - sb.AppendLine("}"); - return sb.ToString(); - } - } -} diff --git a/RandomizerCore/Logic/RawLogicTransition.cs b/RandomizerCore/Logic/RawLogicTransition.cs index feef572..57414ea 100644 --- a/RandomizerCore/Logic/RawLogicTransition.cs +++ b/RandomizerCore/Logic/RawLogicTransition.cs @@ -1,8 +1,7 @@ using Newtonsoft.Json; namespace RandomizerCore.Logic -{ - +{ public readonly record struct LogicTransitionData(string SceneName, string GateName, OneWayType OneWayType) { public string Name => $"{SceneName}[{GateName}]"; diff --git a/RandomizerCore/Logic/SimpleCost.cs b/RandomizerCore/Logic/SimpleCost.cs index 16f88e8..b82ff6c 100644 --- a/RandomizerCore/Logic/SimpleCost.cs +++ b/RandomizerCore/Logic/SimpleCost.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; - -namespace RandomizerCore.Logic +namespace RandomizerCore.Logic { public class SimpleCost : LogicCost { diff --git a/RandomizerCore/Logic/Term.cs b/RandomizerCore/Logic/Term.cs index efb01d5..933575e 100644 --- a/RandomizerCore/Logic/Term.cs +++ b/RandomizerCore/Logic/Term.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace RandomizerCore.Logic +namespace RandomizerCore.Logic { public class Term { diff --git a/RandomizerCore/Logic/VariableResolver.cs b/RandomizerCore/Logic/VariableResolver.cs index 5393aee..6651e52 100644 --- a/RandomizerCore/Logic/VariableResolver.cs +++ b/RandomizerCore/Logic/VariableResolver.cs @@ -1,5 +1,4 @@ -using System.Linq; -using System.Text.RegularExpressions; +using System.Text.RegularExpressions; namespace RandomizerCore.Logic { diff --git a/RandomizerCore/LogicItem.cs b/RandomizerCore/LogicItem.cs index 41980a8..7bd29c8 100644 --- a/RandomizerCore/LogicItem.cs +++ b/RandomizerCore/LogicItem.cs @@ -1,12 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using RandomizerCore.Logic; +using RandomizerCore.Logic; namespace RandomizerCore { - /// /// Interface used by items and itemlikes (transitions, waypoints). /// diff --git a/RandomizerCore/LogicItems/BranchedItem.cs b/RandomizerCore/LogicItems/BranchedItem.cs index 899b576..d93355c 100644 --- a/RandomizerCore/LogicItems/BranchedItem.cs +++ b/RandomizerCore/LogicItems/BranchedItem.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using RandomizerCore.Logic; +using RandomizerCore.Logic; namespace RandomizerCore.LogicItems { diff --git a/RandomizerCore/LogicItems/CappedItem.cs b/RandomizerCore/LogicItems/CappedItem.cs index 6c3b889..7139fdd 100644 --- a/RandomizerCore/LogicItems/CappedItem.cs +++ b/RandomizerCore/LogicItems/CappedItem.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using RandomizerCore.Logic; +using RandomizerCore.Logic; namespace RandomizerCore.LogicItems { diff --git a/RandomizerCore/LogicItems/EmptyItem.cs b/RandomizerCore/LogicItems/EmptyItem.cs index 4e3bb17..b2392a4 100644 --- a/RandomizerCore/LogicItems/EmptyItem.cs +++ b/RandomizerCore/LogicItems/EmptyItem.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using RandomizerCore.Logic; +using RandomizerCore.Logic; namespace RandomizerCore.LogicItems { diff --git a/RandomizerCore/LogicItems/MultiItem.cs b/RandomizerCore/LogicItems/MultiItem.cs index 3e06f43..88ff367 100644 --- a/RandomizerCore/LogicItems/MultiItem.cs +++ b/RandomizerCore/LogicItems/MultiItem.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using RandomizerCore.Logic; +using RandomizerCore.Logic; namespace RandomizerCore.LogicItems { diff --git a/RandomizerCore/LogicItems/SingleItem.cs b/RandomizerCore/LogicItems/SingleItem.cs index c4fcac0..26a691a 100644 --- a/RandomizerCore/LogicItems/SingleItem.cs +++ b/RandomizerCore/LogicItems/SingleItem.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using RandomizerCore.Logic; +using RandomizerCore.Logic; namespace RandomizerCore.LogicItems { diff --git a/RandomizerCore/Properties/AssemblyInfo.cs b/RandomizerCore/Properties/AssemblyInfo.cs index 3ed84a0..5ae76c9 100644 --- a/RandomizerCore/Properties/AssemblyInfo.cs +++ b/RandomizerCore/Properties/AssemblyInfo.cs @@ -1,6 +1,4 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; +using System.Runtime.InteropServices; // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from diff --git a/RandomizerCore/RandoContext.cs b/RandomizerCore/RandoContext.cs index 5bf0c71..7059e19 100644 --- a/RandomizerCore/RandoContext.cs +++ b/RandomizerCore/RandoContext.cs @@ -1,12 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Threading.Tasks; -using Newtonsoft.Json; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using Newtonsoft.Json.Serialization; using RandomizerCore.Json; using RandomizerCore.Logic; diff --git a/RandomizerCore/RandoItem.cs b/RandomizerCore/RandoItem.cs index 9b8236d..e7454dd 100644 --- a/RandomizerCore/RandoItem.cs +++ b/RandomizerCore/RandoItem.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using RandomizerCore.Logic; +using RandomizerCore.Logic; namespace RandomizerCore { diff --git a/RandomizerCore/RandoLocation.cs b/RandomizerCore/RandoLocation.cs index 1a21b2f..51df2d9 100644 --- a/RandomizerCore/RandoLocation.cs +++ b/RandomizerCore/RandoLocation.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using static RandomizerCore.LogHelper; -using RandomizerCore.Logic; +using RandomizerCore.Logic; using Newtonsoft.Json; namespace RandomizerCore diff --git a/RandomizerCore/RandoMonitor.cs b/RandomizerCore/RandoMonitor.cs index 54f30b1..43a7936 100644 --- a/RandomizerCore/RandoMonitor.cs +++ b/RandomizerCore/RandoMonitor.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace RandomizerCore +namespace RandomizerCore { public enum RandoEventType { diff --git a/RandomizerCore/RandoPlacement.cs b/RandomizerCore/RandoPlacement.cs index d394ffa..4938047 100644 --- a/RandomizerCore/RandoPlacement.cs +++ b/RandomizerCore/RandoPlacement.cs @@ -1,5 +1,4 @@ namespace RandomizerCore { public readonly record struct RandoPlacement(IRandoItem Item, IRandoLocation Location); - } diff --git a/RandomizerCore/Randomization/CombinedItemSelector.cs b/RandomizerCore/Randomization/CombinedItemSelector.cs index 57c02f1..6511b3d 100644 --- a/RandomizerCore/Randomization/CombinedItemSelector.cs +++ b/RandomizerCore/Randomization/CombinedItemSelector.cs @@ -1,5 +1,4 @@ using RandomizerCore.Collections; -using RandomizerCore.Exceptions; using RandomizerCore.Extensions; namespace RandomizerCore.Randomization diff --git a/RandomizerCore/Randomization/DefaultGroupPlacementStrategy.cs b/RandomizerCore/Randomization/DefaultGroupPlacementStrategy.cs index bdf74b9..d0aad00 100644 --- a/RandomizerCore/Randomization/DefaultGroupPlacementStrategy.cs +++ b/RandomizerCore/Randomization/DefaultGroupPlacementStrategy.cs @@ -1,10 +1,5 @@ using RandomizerCore.Collections; using RandomizerCore.Exceptions; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace RandomizerCore.Randomization { @@ -201,7 +196,6 @@ public IRandoLocation SelectNext(Sphere s, List> if (!constraintSatisfied) { InvokeOnConstraintViolated(item, location); - // Log($"Available locations were: {string.Join(", ", locations.SelectMany(l => l.Select(rl => rl.Name)))}"); } locations[depth].RemoveAt(index); diff --git a/RandomizerCore/Randomization/GroupPlacementStrategy.cs b/RandomizerCore/Randomization/GroupPlacementStrategy.cs index 106d181..8896c05 100644 --- a/RandomizerCore/Randomization/GroupPlacementStrategy.cs +++ b/RandomizerCore/Randomization/GroupPlacementStrategy.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace RandomizerCore.Randomization +namespace RandomizerCore.Randomization { /// /// Base class for creating placements for a group. diff --git a/RandomizerCore/Randomization/PriorityTransformUtil.cs b/RandomizerCore/Randomization/PriorityTransformUtil.cs index 2df8a58..f3eafed 100644 --- a/RandomizerCore/Randomization/PriorityTransformUtil.cs +++ b/RandomizerCore/Randomization/PriorityTransformUtil.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace RandomizerCore.Randomization +namespace RandomizerCore.Randomization { /// /// Utility class for creating Depth Priority Transforms that do simple mathematical operations. diff --git a/RandomizerCore/Randomization/Randomizer.cs b/RandomizerCore/Randomization/Randomizer.cs index fed43a4..c1091be 100644 --- a/RandomizerCore/Randomization/Randomizer.cs +++ b/RandomizerCore/Randomization/Randomizer.cs @@ -6,13 +6,13 @@ namespace RandomizerCore.Randomization { public class Randomizer { - readonly LogicManager lm; - readonly RandomizationStage[] stages; - readonly RandoContext ctx; + public readonly LogicManager lm; + public readonly RandomizationStage[] stages; + public readonly RandoContext ctx; readonly ProgressionManager pm; - readonly Random rng; - readonly RandoMonitor rm; - readonly List[]> stagedPlacements; + public readonly Random rng; + public readonly RandoMonitor rm; + public readonly List[]> stagedPlacements; public Randomizer(Random rng, RandoContext ctx, RandomizationStage[] stages, RandoMonitor rm = null) { @@ -30,7 +30,6 @@ public Randomizer(Random rng, RandoContext ctx, RandomizationStage[] stages, Ran if (group.Items.Length != group.Locations.Length) throw new ArgumentException($"Group {group.Label} in stage {stage.label} has nonmatching arrays!"); } } - } public List[]> Run() @@ -199,8 +198,6 @@ public void Reset() /// public void Validate() { - Log("Beginning validation."); - // First, check that each RandomizationGroup matches the output, by checking that the counts of items and locations by name match. Dictionary nameCounts = new(); for (int i = 0; i < stages.Length; i++) @@ -273,8 +270,7 @@ public void Validate() if (!e.obtained) throw new ValidationException($"Unreachable item placement detected: {e.item.Name} at {e.location.Name}"); } - Log("Validation completed successfully!"); - + #if DEBUG Log(); Log("Placements:"); foreach (var l in stagedPlacements) @@ -287,8 +283,8 @@ public void Validate() } } } - Log(); + #endif } } } diff --git a/RandomizerCore/Randomization/SphereBuilder.cs b/RandomizerCore/Randomization/SphereBuilder.cs index 56fb5d8..173cf7f 100644 --- a/RandomizerCore/Randomization/SphereBuilder.cs +++ b/RandomizerCore/Randomization/SphereBuilder.cs @@ -1,5 +1,6 @@ using RandomizerCore.Exceptions; using RandomizerCore.Logic; +using System.Diagnostics; namespace RandomizerCore.Randomization { @@ -123,6 +124,7 @@ public void AddNextSphere() selector.UpdateCaps(next); } + [Conditional("DEBUG")] internal void LogSpheres() { Log(); diff --git a/RandomizerCore/Randomization/StagePlacementStrategy.cs b/RandomizerCore/Randomization/StagePlacementStrategy.cs index 38db363..bc5d64f 100644 --- a/RandomizerCore/Randomization/StagePlacementStrategy.cs +++ b/RandomizerCore/Randomization/StagePlacementStrategy.cs @@ -1,7 +1,4 @@ -using RandomizerCore.Collections; -using RandomizerCore.Exceptions; - -namespace RandomizerCore.Randomization +namespace RandomizerCore.Randomization { /// /// Base class for stage-level placement strategy. Manages the placement of each group. diff --git a/RandomizerCore/State.cs b/RandomizerCore/State.cs index 5cb4e0e..dee1a6d 100644 --- a/RandomizerCore/State.cs +++ b/RandomizerCore/State.cs @@ -6,5 +6,4 @@ public enum State Temporary, Permanent } - } diff --git a/RandomizerCore/StringLogic/DictPM.cs b/RandomizerCore/StringLogic/DictPM.cs index d74261c..aba471e 100644 --- a/RandomizerCore/StringLogic/DictPM.cs +++ b/RandomizerCore/StringLogic/DictPM.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; - -namespace RandomizerCore.StringLogic +namespace RandomizerCore.StringLogic { /// /// Object which evaluates tokenized logic using a dictionary of recognized terms and their values. diff --git a/RandomizerCore/StringLogic/Infix.cs b/RandomizerCore/StringLogic/Infix.cs index 31a482d..58738e1 100644 --- a/RandomizerCore/StringLogic/Infix.cs +++ b/RandomizerCore/StringLogic/Infix.cs @@ -1,11 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using RandomizerCore.Extensions; - -namespace RandomizerCore.StringLogic +namespace RandomizerCore.StringLogic { public static class Infix { diff --git a/RandomizerCore/StringLogic/LogicClause.cs b/RandomizerCore/StringLogic/LogicClause.cs index f3fb52d..abf1bf8 100644 --- a/RandomizerCore/StringLogic/LogicClause.cs +++ b/RandomizerCore/StringLogic/LogicClause.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Collections.ObjectModel; namespace RandomizerCore.StringLogic { diff --git a/RandomizerCore/StringLogic/LogicClauseBuilder.cs b/RandomizerCore/StringLogic/LogicClauseBuilder.cs index 34163f3..326fa32 100644 --- a/RandomizerCore/StringLogic/LogicClauseBuilder.cs +++ b/RandomizerCore/StringLogic/LogicClauseBuilder.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; +using System.Collections.ObjectModel; namespace RandomizerCore.StringLogic { diff --git a/RandomizerCore/StringLogic/LogicProcessor.cs b/RandomizerCore/StringLogic/LogicProcessor.cs index 781098d..79e12ca 100644 --- a/RandomizerCore/StringLogic/LogicProcessor.cs +++ b/RandomizerCore/StringLogic/LogicProcessor.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using static RandomizerCore.LogHelper; - -namespace RandomizerCore.StringLogic +namespace RandomizerCore.StringLogic { public class LogicProcessor : ITokenSource, IMacroSource { diff --git a/RandomizerCore/StringLogic/LogicToken.cs b/RandomizerCore/StringLogic/LogicToken.cs index 44cc52d..8a6d7cd 100644 --- a/RandomizerCore/StringLogic/LogicToken.cs +++ b/RandomizerCore/StringLogic/LogicToken.cs @@ -1,22 +1,30 @@ -using System; - -namespace RandomizerCore.StringLogic +namespace RandomizerCore.StringLogic { + /// + /// The fundamental unit of tokenized logic, used throughout the StringLogic namespace. + /// public abstract record LogicToken; - public enum OperatorType - { - OR, - AND, - } + + /// + /// LogicToken representing one of the binary boolean operators, | or +. + /// public record OperatorToken(OperatorType OperatorType, int Precedence, string Symbol) : LogicToken { public static readonly OperatorToken AND = new(OperatorType.AND, 1, "+"); public static readonly OperatorToken OR = new(OperatorType.OR, 0, "|"); } + public enum OperatorType + { + OR, + AND, + } + + /// + /// LogicToken which evaluates to a bool. + /// public abstract record TermToken : LogicToken { public abstract string Write(); - public static LogicClause operator|(TermToken t, TermToken u) { @@ -27,16 +35,18 @@ public abstract record TermToken : LogicToken return new(t, u, OperatorToken.AND); } } + + /// + /// TermToken which represents a simple named variable. + /// public record SimpleToken(string Name) : TermToken { public override string Write() => Name; } - public enum ComparisonType - { - EQ, - LT, - GT, - } + + /// + /// TermToken which represents a simple comparison of two named integer variables. + /// public record ComparisonToken(ComparisonType ComparisonType, string Left, string Right) : TermToken { public override string Write() @@ -51,12 +61,25 @@ public override string Write() return $"{Left}{symbol}{Right}"; } } + public enum ComparisonType + { + EQ, + LT, + GT, + } + /// + /// TermToken which represents a nested LogicClause, provided through the IMacroSource, usually a LogicProcessor. + /// public record MacroToken(string Name, IMacroSource Source) : TermToken { public override string Write() => Name; public LogicClause Value => Source.GetMacro(Name); } + + /// + /// TermToken which represents a constant bool. + /// public record ConstToken(bool Value) : TermToken { public override string Write() => Value.ToString().ToUpper(); diff --git a/RandomizerCore/StringLogic/RPN.cs b/RandomizerCore/StringLogic/RPN.cs index 7912696..03f195e 100644 --- a/RandomizerCore/StringLogic/RPN.cs +++ b/RandomizerCore/StringLogic/RPN.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace RandomizerCore.StringLogic +namespace RandomizerCore.StringLogic { public static class RPN { diff --git a/RandomizerCore/StringLogic/StringPM.cs b/RandomizerCore/StringLogic/StringPM.cs index f966ef3..1899890 100644 --- a/RandomizerCore/StringLogic/StringPM.cs +++ b/RandomizerCore/StringLogic/StringPM.cs @@ -1,9 +1,4 @@ -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace RandomizerCore.StringLogic +namespace RandomizerCore.StringLogic { /// /// Base class for an object which can evaluate tokenized logic. diff --git a/RandomizerCore/TransitionPlacement.cs b/RandomizerCore/TransitionPlacement.cs index ec56696..aaa5988 100644 --- a/RandomizerCore/TransitionPlacement.cs +++ b/RandomizerCore/TransitionPlacement.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace RandomizerCore +namespace RandomizerCore { public readonly struct TransitionPlacement { diff --git a/RandomizerCore/Updater/MainUpdater.cs b/RandomizerCore/Updater/MainUpdater.cs index 452277f..ec6a3c0 100644 --- a/RandomizerCore/Updater/MainUpdater.cs +++ b/RandomizerCore/Updater/MainUpdater.cs @@ -1,11 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using static RandomizerCore.LogHelper; - -namespace RandomizerCore.Logic +namespace RandomizerCore.Logic { public class MainUpdater { @@ -112,7 +105,6 @@ public void DoUpdates() public void DoUpdate(int term) { - //Log("Doing update for term: " + lm.GetTerm(term)); foreach (var entry in entriesByTerm[term]) { DoUpdateEntry(entry); @@ -146,8 +138,6 @@ public void DoUpdateAll() public void OnRemove() { - //Log("Beginning OnRemove with " + temp.Count); - for (int i = 0; i < temp.Count; i++) { var entry = temp[i]; @@ -166,8 +156,8 @@ public void DoRecalculate() updated = false; for (int i = 0; i < temp.Count; i++) { - var entry = temp[i]; - //Log(entry.ToString() + $" {entry.obtained}, {entry.CanGet(pm)}"); + UpdateEntry entry = temp[i]; + if (!entry.obtained && entry.CanGet(pm)) { updated = true; @@ -178,9 +168,7 @@ public void DoRecalculate() } while (updated); - //Log("Almost finished recalculate with " + temp.Count); temp.RemoveAll(e => !e.obtained); - //Log("Finished recalculate with " + temp.Count); OnEndRecalculuate?.Invoke(); } diff --git a/RandomizerCore/Updater/PrePlacedItemUpdateEntry.cs b/RandomizerCore/Updater/PrePlacedItemUpdateEntry.cs index 9540632..274e0f4 100644 --- a/RandomizerCore/Updater/PrePlacedItemUpdateEntry.cs +++ b/RandomizerCore/Updater/PrePlacedItemUpdateEntry.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; - -namespace RandomizerCore.Logic +namespace RandomizerCore.Logic { public class PrePlacedItemUpdateEntry : UpdateEntry {