Implement ActionPool (backend only)

This commit is contained in:
Asriel Camora
2024-02-29 00:01:55 -08:00
parent 44ae3791f1
commit ecabc24517
8 changed files with 204 additions and 134 deletions
+110
View File
@@ -0,0 +1,110 @@
using Craftimizer.Simulator.Actions;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Craftimizer.Solver;
[StructLayout(LayoutKind.Auto)]
public readonly struct ActionPool
{
public static ActionPool Default { get; } = new(new[]
{
ActionType.StandardTouchCombo,
ActionType.AdvancedTouchCombo,
ActionType.FocusedTouchCombo,
ActionType.FocusedSynthesisCombo,
ActionType.TrainedFinesse,
ActionType.PrudentSynthesis,
ActionType.Groundwork,
ActionType.AdvancedTouch,
ActionType.CarefulSynthesis,
ActionType.TrainedEye,
ActionType.DelicateSynthesis,
ActionType.PreparatoryTouch,
ActionType.Reflect,
ActionType.PrudentTouch,
ActionType.Manipulation,
ActionType.MuscleMemory,
ActionType.ByregotsBlessing,
ActionType.WasteNot2,
ActionType.BasicSynthesis,
ActionType.Innovation,
ActionType.GreatStrides,
ActionType.StandardTouch,
ActionType.Veneration,
ActionType.WasteNot,
ActionType.MastersMend,
ActionType.BasicTouch,
});
public const int MaskSize = 32;
public const int EnumSize = 37;
private unsafe struct EnumBuffer
{
public fixed byte Data[MaskSize];
public ref ActionType this[int index] => ref Unsafe.As<byte, ActionType>(ref Data[index]);
public Span<ActionType> AsSpan() => new(Unsafe.AsPointer(ref this[0]), MaskSize);
}
private unsafe struct LUTBuffer
{
public fixed byte Data[EnumSize];
public ref byte this[ActionType index] => ref Data[(byte)index];
#pragma warning disable MA0099
public Span<byte> AsSpan() => new(Unsafe.AsPointer(ref this[0]), EnumSize);
#pragma warning restore MA0099
}
// List of accepted actions (max 32)
private readonly EnumBuffer acceptedActions;
// Lookup table for accepted actions (ActionType as idx -> idx in acceptedActions)
private readonly LUTBuffer acceptedActionsLUT;
private readonly byte size;
internal ReadOnlySpan<ActionType> AcceptedActions => acceptedActions.AsSpan().Slice(0, size);
public ActionPool(ReadOnlySpan<ActionType> actions)
{
if (actions.Length > MaskSize)
throw new ArgumentOutOfRangeException(nameof(actions), actions.Length, $"ActionPool only supports up to {MaskSize} actions");
size = (byte)actions.Length;
acceptedActions.AsSpan().Fill((ActionType)0xFF);
acceptedActionsLUT.AsSpan().Fill(0xFF);
actions.CopyTo(acceptedActions.AsSpan());
for (var i = 0; i < size; i++)
acceptedActionsLUT[acceptedActions[i]] = (byte)i;
}
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal byte FromAction(ActionType action)
{
var ret = acceptedActionsLUT[action];
if (ret == 0xFF)
throw new ArgumentOutOfRangeException(nameof(action), action, $"Action {action} is unsupported in this pool.");
return ret;
}
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal ActionType ToAction(byte index)
{
if (index < 0 || index >= size)
throw new ArgumentOutOfRangeException(nameof(index), index, $"Index {index} is out of range for this pool.");
return acceptedActions[index];
}
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal uint ToMask(ActionType action) => 1u << (FromAction(action) + 1);
}
+18 -80
View File
@@ -7,75 +7,13 @@ namespace Craftimizer.Solver;
public struct ActionSet public struct ActionSet
{ {
private uint bits; internal uint bits;
internal static ReadOnlySpan<ActionType> AcceptedActions => new[]
{
ActionType.StandardTouchCombo,
ActionType.AdvancedTouchCombo,
ActionType.FocusedTouchCombo,
ActionType.FocusedSynthesisCombo,
ActionType.TrainedFinesse,
ActionType.PrudentSynthesis,
ActionType.Groundwork,
ActionType.AdvancedTouch,
ActionType.CarefulSynthesis,
ActionType.TrainedEye,
ActionType.DelicateSynthesis,
ActionType.PreparatoryTouch,
ActionType.Reflect,
ActionType.PrudentTouch,
ActionType.Manipulation,
ActionType.MuscleMemory,
ActionType.ByregotsBlessing,
ActionType.WasteNot2,
ActionType.BasicSynthesis,
ActionType.Innovation,
ActionType.GreatStrides,
ActionType.StandardTouch,
ActionType.Veneration,
ActionType.WasteNot,
ActionType.MastersMend,
ActionType.BasicTouch,
};
public static readonly int[] AcceptedActionsLUT;
static ActionSet()
{
AcceptedActionsLUT = new int[Enum.GetValues<ActionType>().Length];
for (var i = 0; i < AcceptedActionsLUT.Length; i++)
AcceptedActionsLUT[i] = -1;
for (var i = 0; i < AcceptedActions.Length; i++)
AcceptedActionsLUT[(byte)AcceptedActions[i]] = i;
}
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static int FromAction(ActionType action)
{
var ret = AcceptedActionsLUT[(byte)action];
if (ret == -1)
throw new ArgumentOutOfRangeException(nameof(action), action, $"Action {action} is unsupported in {nameof(ActionSet)}.");
return ret;
}
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static ActionType ToAction(int index)
{
if (index < 0 || index >= AcceptedActions.Length)
throw new ArgumentOutOfRangeException(nameof(index), index, $"Index {index} is out of range for {nameof(ActionSet)}.");
return AcceptedActions[index];
}
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static uint ToMask(ActionType action) => 1u << (FromAction(action) + 1);
// Return true if action was newly added and not there before. // Return true if action was newly added and not there before.
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool AddAction(ActionType action) public bool AddAction(in ActionPool pool, ActionType action)
{ {
var mask = ToMask(action); var mask = pool.ToMask(action);
var old = bits; var old = bits;
bits |= mask; bits |= mask;
return (old & mask) == 0; return (old & mask) == 0;
@@ -83,9 +21,9 @@ public struct ActionSet
// Return true if action was newly removed and not already gone. // Return true if action was newly removed and not already gone.
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool RemoveAction(ActionType action) public bool RemoveAction(in ActionPool pool, ActionType action)
{ {
var mask = ToMask(action); var mask = pool.ToMask(action);
var old = bits; var old = bits;
bits &= ~mask; bits &= ~mask;
return (old & mask) != 0; return (old & mask) != 0;
@@ -93,10 +31,10 @@ public struct ActionSet
[Pure] [Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly bool HasAction(ActionType action) => (bits & ToMask(action)) != 0; public readonly bool HasAction(in ActionPool pool, ActionType action) => (bits & pool.ToMask(action)) != 0;
[Pure] [Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly ActionType ElementAt(int index) => ToAction(Intrinsics.NthBitSet(bits, index) - 1); public readonly ActionType ElementAt(in ActionPool pool, int index) => pool.ToAction((byte)(Intrinsics.NthBitSet(bits, index) - 1));
[Pure] [Pure]
public readonly int Count => BitOperations.PopCount(bits); public readonly int Count => BitOperations.PopCount(bits);
@@ -105,38 +43,38 @@ public struct ActionSet
public readonly bool IsEmpty => bits == 0; public readonly bool IsEmpty => bits == 0;
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly ActionType SelectRandom(Random random) public readonly ActionType SelectRandom(in ActionPool pool, Random random)
{ {
#if IS_DETERMINISTIC #if IS_DETERMINISTIC
return First(); return First(in pool);
#else #else
return ElementAt(random.Next(Count)); return ElementAt(in pool, random.Next(Count));
#endif #endif
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public ActionType PopRandom(Random random) public ActionType PopRandom(in ActionPool pool, Random random)
{ {
#if IS_DETERMINISTIC #if IS_DETERMINISTIC
return PopFirst(); return PopFirst(in pool);
#else #else
var action = ElementAt(random.Next(Count)); var action = ElementAt(in pool, random.Next(Count));
RemoveAction(action); RemoveAction(in pool, action);
return action; return action;
#endif #endif
} }
#if IS_DETERMINISTIC #if IS_DETERMINISTIC
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private ActionType PopFirst() private ActionType PopFirst(in pool)
{ {
var action = First(); var action = First(in pool);
RemoveAction(action); RemoveAction(in pool, action);
return action; return action;
} }
[Pure] [Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private readonly ActionType First() => ElementAt(0); private readonly ActionType First(in pool) => ElementAt(in pool, 0);
#endif #endif
} }
+6 -6
View File
@@ -23,7 +23,7 @@ public sealed class MCTS
public MCTS(in MCTSConfig config, in SimulationState state) public MCTS(in MCTSConfig config, in SimulationState state)
{ {
this.config = config; this.config = config;
var sim = new Simulator(config.MaxStepCount) { State = state }; var sim = new Simulator(config.ActionPool, config.MaxStepCount) { State = state };
rootNode = new(new( rootNode = new(new(
state, state,
null, null,
@@ -52,9 +52,9 @@ public sealed class MCTS
if (state.IsComplete) if (state.IsComplete)
return startNode; return startNode;
if (!state.AvailableActions.HasAction(action)) if (!state.AvailableActions.HasAction(in simulator.Pool, action))
return startNode; return startNode;
state.AvailableActions.RemoveAction(action); state.AvailableActions.RemoveAction(in simulator.Pool, action);
startNode = startNode.Add(Execute(simulator, state.State, action, strict)); startNode = startNode.Add(Execute(simulator, state.State, action, strict));
} }
@@ -184,7 +184,7 @@ public sealed class MCTS
if (initialState.IsComplete) if (initialState.IsComplete)
return (initialNode, initialState.CalculateScore(config) ?? 0); return (initialNode, initialState.CalculateScore(config) ?? 0);
var poppedAction = initialState.AvailableActions.PopRandom(random); var poppedAction = initialState.AvailableActions.PopRandom(in simulator.Pool, random);
var expandedNode = initialNode.Add(Execute(simulator, initialState.State, poppedAction, true)); var expandedNode = initialNode.Add(Execute(simulator, initialState.State, poppedAction, true));
// playout to a terminal state // playout to a terminal state
@@ -198,7 +198,7 @@ public sealed class MCTS
while (SimulationNode.GetCompletionState(currentCompletionState, currentActions) == CompletionState.Incomplete && while (SimulationNode.GetCompletionState(currentCompletionState, currentActions) == CompletionState.Incomplete &&
actionCount < actions.Length) actionCount < actions.Length)
{ {
var nextAction = currentActions.SelectRandom(random); var nextAction = currentActions.SelectRandom(in simulator.Pool, random);
actions[actionCount++] = nextAction; actions[actionCount++] = nextAction;
(_, currentState) = simulator.Execute(currentState, nextAction); (_, currentState) = simulator.Execute(currentState, nextAction);
currentCompletionState = simulator.CompletionState; currentCompletionState = simulator.CompletionState;
@@ -283,7 +283,7 @@ public sealed class MCTS
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Search(int iterations, ref int progress, CancellationToken token) public void Search(int iterations, ref int progress, CancellationToken token)
{ {
Simulator simulator = new(config.MaxStepCount); Simulator simulator = new(config.ActionPool, config.MaxStepCount);
var random = rootNode.State.State.Input.Random; var random = rootNode.State.State.Input.Random;
var staleCounter = 0; var staleCounter = 0;
var i = 0; var i = 0;
+4
View File
@@ -21,6 +21,8 @@ public readonly record struct MCTSConfig
public float ScoreCP { get; init; } public float ScoreCP { get; init; }
public float ScoreSteps { get; init; } public float ScoreSteps { get; init; }
public ActionPool ActionPool { get; init; }
public MCTSConfig(in SolverConfig config) public MCTSConfig(in SolverConfig config)
{ {
MaxStepCount = config.MaxStepCount; MaxStepCount = config.MaxStepCount;
@@ -36,5 +38,7 @@ public readonly record struct MCTSConfig
ScoreDurability = config.ScoreDurability; ScoreDurability = config.ScoreDurability;
ScoreCP = config.ScoreCP; ScoreCP = config.ScoreCP;
ScoreSteps = config.ScoreSteps; ScoreSteps = config.ScoreSteps;
ActionPool = config.ActionPool;
} }
} }
+5 -3
View File
@@ -7,6 +7,7 @@ namespace Craftimizer.Solver;
internal sealed class Simulator : SimulatorNoRandom internal sealed class Simulator : SimulatorNoRandom
{ {
public readonly ActionPool Pool;
private readonly int maxStepCount; private readonly int maxStepCount;
public override CompletionState CompletionState public override CompletionState CompletionState
@@ -20,8 +21,9 @@ internal sealed class Simulator : SimulatorNoRandom
} }
} }
public Simulator(int maxStepCount) public Simulator(in ActionPool pool, int maxStepCount)
{ {
Pool = pool;
this.maxStepCount = maxStepCount; this.maxStepCount = maxStepCount;
} }
@@ -133,9 +135,9 @@ internal sealed class Simulator : SimulatorNoRandom
return new(); return new();
var ret = new ActionSet(); var ret = new ActionSet();
foreach (var action in ActionSet.AcceptedActions) foreach (var action in Pool.AcceptedActions)
if (CanUseAction(action, strict)) if (CanUseAction(action, strict))
ret.AddAction(action); ret.AddAction(in Pool, action);
return ret; return ret;
} }
+3 -3
View File
@@ -145,7 +145,7 @@ public sealed class Solver : IDisposable
var bestSims = new List<(float Score, SolverSolution Result)>(); var bestSims = new List<(float Score, SolverSolution Result)>();
var state = State; var state = State;
var sim = new Simulator(Config.MaxStepCount); var sim = new Simulator(Config.ActionPool, Config.MaxStepCount);
var activeStates = new List<SolverSolution>() { new(Array.Empty<ActionType>(), state) }; var activeStates = new List<SolverSolution>() { new(Array.Empty<ActionType>(), state) };
@@ -272,7 +272,7 @@ public sealed class Solver : IDisposable
var actions = new List<ActionType>(); var actions = new List<ActionType>();
var state = State; var state = State;
var sim = new Simulator(Config.MaxStepCount) { State = state }; var sim = new Simulator(Config.ActionPool, Config.MaxStepCount) { State = state };
while (true) while (true)
{ {
Token.ThrowIfCancellationRequested(); Token.ThrowIfCancellationRequested();
@@ -338,7 +338,7 @@ public sealed class Solver : IDisposable
var actions = new List<ActionType>(); var actions = new List<ActionType>();
var state = State; var state = State;
var sim = new Simulator(Config.MaxStepCount) { State = state }; var sim = new Simulator(Config.ActionPool, Config.MaxStepCount) { State = state };
while (true) while (true)
{ {
Token.ThrowIfCancellationRequested(); Token.ThrowIfCancellationRequested();
+2
View File
@@ -31,6 +31,7 @@ public readonly record struct SolverConfig
public float ScoreCP { get; init; } public float ScoreCP { get; init; }
public float ScoreSteps { get; init; } public float ScoreSteps { get; init; }
public ActionPool ActionPool { get; init; }
public SolverAlgorithm Algorithm { get; init; } public SolverAlgorithm Algorithm { get; init; }
public SolverConfig() public SolverConfig()
@@ -54,6 +55,7 @@ public readonly record struct SolverConfig
ScoreCP = .05f; ScoreCP = .05f;
ScoreSteps = .05f; ScoreSteps = .05f;
ActionPool = ActionPool.Default;
Algorithm = SolverAlgorithm.StepwiseFurcated; Algorithm = SolverAlgorithm.StepwiseFurcated;
} }
+56 -42
View File
@@ -1,20 +1,34 @@
using System.Runtime.CompilerServices;
namespace Craftimizer.Test.Solver; namespace Craftimizer.Test.Solver;
[TestClass] [TestClass]
public class ActionSetTests public class ActionSetTests
{ {
private readonly ActionPool pool = ActionPool.Default;
[TestMethod]
public void TestActionPoolSize()
{
Assert.AreEqual(ActionPool.EnumSize, Enum.GetValues<ActionType>().Length);
Assert.AreEqual(ActionPool.MaskSize, Unsafe.SizeOf<ActionSet>() * 8);
}
[TestMethod] [TestMethod]
public void TestAcceptedActions() public void TestAcceptedActions()
{ {
var actions = ActionSet.AcceptedActions;
var lut = ActionSet.AcceptedActionsLUT;
Assert.IsTrue(actions.Length <= 32);
foreach (var i in Enum.GetValues<ActionType>()) foreach (var i in Enum.GetValues<ActionType>())
{ {
var idx = lut[(byte)i]; byte idx;
if (idx != -1) try
Assert.AreEqual(i, actions[idx]); {
idx = pool.FromAction(i);
}
catch (ArgumentOutOfRangeException)
{
continue;
}
Assert.AreEqual(i, pool.ToAction(idx));
} }
} }
@@ -25,14 +39,14 @@ public class ActionSetTests
Assert.IsTrue(set.IsEmpty); Assert.IsTrue(set.IsEmpty);
Assert.AreEqual(0, set.Count); Assert.AreEqual(0, set.Count);
set.AddAction(ActionType.BasicSynthesis); set.AddAction(in pool, ActionType.BasicSynthesis);
set.AddAction(ActionType.WasteNot2); set.AddAction(in pool, ActionType.WasteNot2);
Assert.AreEqual(2, set.Count); Assert.AreEqual(2, set.Count);
Assert.IsFalse(set.IsEmpty); Assert.IsFalse(set.IsEmpty);
set.RemoveAction(ActionType.BasicSynthesis); set.RemoveAction(in pool, ActionType.BasicSynthesis);
set.RemoveAction(ActionType.WasteNot2); set.RemoveAction(in pool, ActionType.WasteNot2);
Assert.IsTrue(set.IsEmpty); Assert.IsTrue(set.IsEmpty);
Assert.AreEqual(0, set.Count); Assert.AreEqual(0, set.Count);
@@ -43,17 +57,17 @@ public class ActionSetTests
{ {
var set = new ActionSet(); var set = new ActionSet();
Assert.IsTrue(set.AddAction(ActionType.BasicSynthesis)); Assert.IsTrue(set.AddAction(in pool, ActionType.BasicSynthesis));
Assert.IsFalse(set.AddAction(ActionType.BasicSynthesis)); Assert.IsFalse(set.AddAction(in pool, ActionType.BasicSynthesis));
Assert.IsTrue(set.RemoveAction(ActionType.BasicSynthesis)); Assert.IsTrue(set.RemoveAction(in pool, ActionType.BasicSynthesis));
Assert.IsFalse(set.RemoveAction(ActionType.BasicSynthesis)); Assert.IsFalse(set.RemoveAction(in pool, ActionType.BasicSynthesis));
Assert.IsTrue(set.AddAction(ActionType.BasicSynthesis)); Assert.IsTrue(set.AddAction(in pool, ActionType.BasicSynthesis));
Assert.IsTrue(set.AddAction(ActionType.WasteNot2)); Assert.IsTrue(set.AddAction(in pool, ActionType.WasteNot2));
Assert.IsTrue(set.RemoveAction(ActionType.BasicSynthesis)); Assert.IsTrue(set.RemoveAction(in pool, ActionType.BasicSynthesis));
Assert.IsTrue(set.RemoveAction(ActionType.WasteNot2)); Assert.IsTrue(set.RemoveAction(in pool, ActionType.WasteNot2));
} }
[TestMethod] [TestMethod]
@@ -61,18 +75,18 @@ public class ActionSetTests
{ {
var set = new ActionSet(); var set = new ActionSet();
set.AddAction(ActionType.BasicSynthesis); set.AddAction(in pool, ActionType.BasicSynthesis);
Assert.IsTrue(set.HasAction(ActionType.BasicSynthesis)); Assert.IsTrue(set.HasAction(in pool, ActionType.BasicSynthesis));
Assert.IsFalse(set.HasAction(ActionType.WasteNot2)); Assert.IsFalse(set.HasAction(in pool, ActionType.WasteNot2));
set.AddAction(ActionType.WasteNot2); set.AddAction(in pool, ActionType.WasteNot2);
Assert.IsTrue(set.HasAction(ActionType.BasicSynthesis)); Assert.IsTrue(set.HasAction(in pool, ActionType.BasicSynthesis));
Assert.IsTrue(set.HasAction(ActionType.WasteNot2)); Assert.IsTrue(set.HasAction(in pool, ActionType.WasteNot2));
set.RemoveAction(ActionType.BasicSynthesis); set.RemoveAction(in pool, ActionType.BasicSynthesis);
Assert.IsFalse(set.HasAction(ActionType.BasicSynthesis)); Assert.IsFalse(set.HasAction(in pool, ActionType.BasicSynthesis));
Assert.IsTrue(set.HasAction(ActionType.WasteNot2)); Assert.IsTrue(set.HasAction(in pool, ActionType.WasteNot2));
} }
[TestMethod] [TestMethod]
@@ -80,25 +94,25 @@ public class ActionSetTests
{ {
var set = new ActionSet(); var set = new ActionSet();
set.AddAction(ActionType.BasicSynthesis); set.AddAction(in pool, ActionType.BasicSynthesis);
set.AddAction(ActionType.ByregotsBlessing); set.AddAction(in pool, ActionType.ByregotsBlessing);
set.AddAction(ActionType.DelicateSynthesis); set.AddAction(in pool, ActionType.DelicateSynthesis);
set.AddAction(ActionType.Reflect); set.AddAction(in pool, ActionType.Reflect);
Assert.AreEqual(4, set.Count); Assert.AreEqual(4, set.Count);
Assert.AreEqual(ActionType.DelicateSynthesis, set.ElementAt(0)); Assert.AreEqual(ActionType.DelicateSynthesis, set.ElementAt(in pool, 0));
Assert.AreEqual(ActionType.Reflect, set.ElementAt(1)); Assert.AreEqual(ActionType.Reflect, set.ElementAt(in pool, 1));
Assert.AreEqual(ActionType.ByregotsBlessing, set.ElementAt(2)); Assert.AreEqual(ActionType.ByregotsBlessing, set.ElementAt(in pool, 2));
Assert.AreEqual(ActionType.BasicSynthesis, set.ElementAt(3)); Assert.AreEqual(ActionType.BasicSynthesis, set.ElementAt(in pool, 3));
set.RemoveAction(ActionType.Reflect); set.RemoveAction(in pool, ActionType.Reflect);
Assert.AreEqual(3, set.Count); Assert.AreEqual(3, set.Count);
Assert.AreEqual(ActionType.DelicateSynthesis, set.ElementAt(0)); Assert.AreEqual(ActionType.DelicateSynthesis, set.ElementAt(in pool, 0));
Assert.AreEqual(ActionType.ByregotsBlessing, set.ElementAt(1)); Assert.AreEqual(ActionType.ByregotsBlessing, set.ElementAt(in pool, 1));
Assert.AreEqual(ActionType.BasicSynthesis, set.ElementAt(2)); Assert.AreEqual(ActionType.BasicSynthesis, set.ElementAt(in pool, 2));
} }
[TestMethod] [TestMethod]
@@ -118,13 +132,13 @@ public class ActionSetTests
var set = new ActionSet(); var set = new ActionSet();
foreach(var action in actions) foreach(var action in actions)
set.AddAction(action); set.AddAction(in pool, action);
var counts = new Dictionary<ActionType, int>(); var counts = new Dictionary<ActionType, int>();
var rng = new Random(0); var rng = new Random(0);
for (var i = 0; i < 100; i++) for (var i = 0; i < 100; i++)
{ {
var action = set.SelectRandom(rng); var action = set.SelectRandom(in pool, rng);
CollectionAssert.Contains(actions, action); CollectionAssert.Contains(actions, action);