From 7aa76846c69988584195063ea4c192d569779568 Mon Sep 17 00:00:00 2001 From: Asriel Camora Date: Thu, 14 Mar 2024 00:50:46 -0700 Subject: [PATCH] Possible stackoverflow inlining fix --- Solver/MCTS.cs | 32 ++------------------------------ Test/Simulator/Simulator.cs | 9 ++------- 2 files changed, 4 insertions(+), 37 deletions(-) diff --git a/Solver/MCTS.cs b/Solver/MCTS.cs index 56106b1..472909e 100644 --- a/Solver/MCTS.cs +++ b/Solver/MCTS.cs @@ -177,6 +177,8 @@ public sealed class MCTS } } + [MethodImpl(MethodImplOptions.NoInlining)] + [SkipLocalsInit] private (Node ExpandedNode, float Score) ExpandAndRollout(Random random, Simulator simulator, Node initialNode) { ref var initialState = ref initialNode.State; @@ -235,26 +237,6 @@ public sealed class MCTS } } - private void ShowAllNodes() - { - static void ShowNodes(StringBuilder b, Node node, Stack path) - { - path.Push(node); - b.AppendLine($"{new string(' ', path.Count)}{node.State.Action}"); - { - for (var i = 0; i < node.Children.Count; ++i) - { - var n = node.ChildAt((i >> 3, i & 7))!; - ShowNodes(b, n, path); - } - path.Pop(); - } - } - var b = new StringBuilder(); - ShowNodes(b, rootNode, new()); - Console.WriteLine(b.ToString()); - } - private bool AllNodesComplete() { static bool NodesIncomplete(Node node, Stack path) @@ -301,11 +283,7 @@ public sealed class MCTS { staleCounter = 0; if (AllNodesComplete()) - { - //Console.WriteLine("All nodes solved for. Can't find a valid solution."); - //ShowAllNodes(); return; - } } } else @@ -334,12 +312,6 @@ public sealed class MCTS actions.Add(node.State.Action.Value); } - //var at = node.ChildIdx; - //ref var sum = ref node.ParentScores!.Value.Data[at.arrayIdx].ScoreSum.Span[at.subIdx]; - //ref var max = ref node.ParentScores!.Value.Data[at.arrayIdx].MaxScore.Span[at.subIdx]; - //ref var visits = ref node.ParentScores!.Value.Data[at.arrayIdx].Visits.Span[at.subIdx]; - //Console.WriteLine($"{sum} {max} {visits}"); - return new(actions, node.State.State); } } diff --git a/Test/Simulator/Simulator.cs b/Test/Simulator/Simulator.cs index 9356348..83939f0 100644 --- a/Test/Simulator/Simulator.cs +++ b/Test/Simulator/Simulator.cs @@ -1,5 +1,3 @@ -using Craftimizer.Simulator.Actions; - namespace Craftimizer.Test.Simulator; [TestClass] @@ -34,7 +32,6 @@ public class SimulatorTests ProgressDivider = 130 }); - // Conflicting Info: // https://craftingway.app/rotation/sandy-fafnir-doVCs // Classical Longsword private static SimulationInput Input2 { get; } = @@ -222,10 +219,8 @@ public class SimulatorTests ActionType.GreatStrides, ActionType.ByregotsBlessing }, - // Conflicting Info: - // TC https://ffxivteamcraft.com/simulator/35020/34800/4PTlwTV6w1aGCUdO2BRl - 3549, 10932, 5, 7); + // TC https://ffxivteamcraft.com/simulator/35020/34800/4PTlwTV6w1aGCUdO2BRl // Craftingway https://craftingway.app/rotation/sandy-fafnir-doVCs - //3548, 10931, 5, 7); + 3549, 10932, 5, 7); } }