Re enable random actions
This commit is contained in:
@@ -31,12 +31,17 @@ internal static class Program
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
var config = new SolverConfig()
|
||||||
|
{
|
||||||
|
Iterations = 1_000_000
|
||||||
|
};
|
||||||
|
|
||||||
var s = Stopwatch.StartNew();
|
var s = Stopwatch.StartNew();
|
||||||
if (true)
|
if (true)
|
||||||
_ = Solver.Crafty.Solver.SearchStepwise(new(), input, a => Console.WriteLine(a));
|
_ = Solver.Crafty.Solver.SearchStepwise(config, input, a => Console.WriteLine(a));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
(var actions, _) = Solver.Crafty.Solver.SearchOneshot(new(), input);
|
(var actions, _) = Solver.Crafty.Solver.SearchOneshot(config, input);
|
||||||
foreach (var action in actions)
|
foreach (var action in actions)
|
||||||
Console.Write($">{action.IntName()}");
|
Console.Write($">{action.IntName()}");
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ public class Solver
|
|||||||
public Simulator Simulator;
|
public Simulator Simulator;
|
||||||
public Node RootNode;
|
public Node RootNode;
|
||||||
|
|
||||||
// public Random Random => Simulator.Input.Random;
|
public Random Random => Simulator.Input.Random;
|
||||||
|
|
||||||
public Solver(SolverConfig config, SimulationState state, bool strict)
|
public Solver(SolverConfig config, SimulationState state, bool strict)
|
||||||
{
|
{
|
||||||
@@ -160,7 +160,7 @@ public class Solver
|
|||||||
if (initialState.IsComplete)
|
if (initialState.IsComplete)
|
||||||
return (initialNode, initialState.CompletionState, initialState.CalculateScore(Config.MaxStepCount) ?? 0);
|
return (initialNode, initialState.CompletionState, initialState.CalculateScore(Config.MaxStepCount) ?? 0);
|
||||||
|
|
||||||
var randomAction = initialState.AvailableActions.First();
|
var randomAction = initialState.AvailableActions.SelectRandom(Random);
|
||||||
initialState.AvailableActions.RemoveAction(randomAction);
|
initialState.AvailableActions.RemoveAction(randomAction);
|
||||||
var expandedNode = initialNode.Add(Execute(initialState.State, randomAction, true));
|
var expandedNode = initialNode.Add(Execute(initialState.State, randomAction, true));
|
||||||
|
|
||||||
@@ -175,7 +175,7 @@ public class Solver
|
|||||||
{
|
{
|
||||||
if (SimulationNode.GetCompletionState(currentCompletionState, currentActions) != CompletionState.Incomplete)
|
if (SimulationNode.GetCompletionState(currentCompletionState, currentActions) != CompletionState.Incomplete)
|
||||||
break;
|
break;
|
||||||
randomAction = currentActions.First();
|
randomAction = currentActions.SelectRandom(Random);
|
||||||
actions[actionCount++] = randomAction;
|
actions[actionCount++] = randomAction;
|
||||||
(currentState, currentCompletionState, currentActions) = ExecuteSimple(currentState, randomAction, true);
|
(currentState, currentCompletionState, currentActions) = ExecuteSimple(currentState, randomAction, true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,27 +3,20 @@ using System.Runtime.InteropServices;
|
|||||||
namespace Craftimizer.Solver.Crafty;
|
namespace Craftimizer.Solver.Crafty;
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Auto)]
|
[StructLayout(LayoutKind.Auto)]
|
||||||
public readonly struct SolverConfig
|
public readonly record struct SolverConfig
|
||||||
{
|
{
|
||||||
public readonly int Iterations;
|
public int Iterations { get; init; }
|
||||||
public readonly float ScoreStorageThreshold;
|
public float ScoreStorageThreshold { get; init; }
|
||||||
public readonly float MaxScoreWeightingConstant;
|
public float MaxScoreWeightingConstant { get; init; }
|
||||||
public readonly float ExplorationConstant;
|
public float ExplorationConstant { get; init; }
|
||||||
public readonly int MaxStepCount;
|
public int MaxStepCount { get; init; }
|
||||||
|
|
||||||
public SolverConfig() : this(30000, 1f, 0.1f, 4, 25) { }
|
public SolverConfig()
|
||||||
|
|
||||||
public SolverConfig(
|
|
||||||
int iterations = 30000,
|
|
||||||
float scoreStorageThreshold = 1f,
|
|
||||||
float maxScoreWeightingConstant = 0.1f,
|
|
||||||
float explorationConstant = 4f,
|
|
||||||
int maxStepCount = 25)
|
|
||||||
{
|
{
|
||||||
Iterations = iterations;
|
Iterations = 30000;
|
||||||
ScoreStorageThreshold = scoreStorageThreshold;
|
ScoreStorageThreshold = 1f;
|
||||||
MaxScoreWeightingConstant = maxScoreWeightingConstant;
|
MaxScoreWeightingConstant = 0.1f;
|
||||||
ExplorationConstant = explorationConstant;
|
ExplorationConstant = 4f;
|
||||||
MaxStepCount = maxStepCount;
|
MaxStepCount = 25;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user