Replace ActionHistory with persistent ActionStatuses
This commit is contained in:
@@ -7,7 +7,7 @@ namespace Craftimizer.Solver.Crafty;
|
||||
public class Simulator : Sim
|
||||
{
|
||||
public new CompletionState CompletionState =>
|
||||
(ActionHistory.Count + 1) >= Solver.MaxStepCount ?
|
||||
(ActionCount + 1) >= Solver.MaxStepCount ?
|
||||
CompletionState.MaxActionCountReached :
|
||||
(CompletionState)base.CompletionState;
|
||||
public override bool IsComplete => CompletionState != CompletionState.Incomplete;
|
||||
@@ -65,7 +65,7 @@ public class Simulator : Sim
|
||||
return false;
|
||||
|
||||
if (action == ActionType.Observe &&
|
||||
IsPreviousAction(ActionType.Observe))
|
||||
ActionStates.Observed)
|
||||
return false;
|
||||
|
||||
if (action == ActionType.FinalAppraisal)
|
||||
@@ -78,7 +78,7 @@ public class Simulator : Sim
|
||||
return true;
|
||||
|
||||
// only allow Focused moves after Observe
|
||||
if (IsPreviousAction(ActionType.Observe) &&
|
||||
if (ActionStates.Observed &&
|
||||
action != ActionType.FocusedSynthesis &&
|
||||
action != ActionType.FocusedTouch)
|
||||
return false;
|
||||
|
||||
@@ -242,12 +242,13 @@ public class Solver
|
||||
|
||||
// playout to a terminal state
|
||||
var currentState = Tree.Get(expandedIndex).State;
|
||||
var preCount = currentState.State.ActionCount;
|
||||
var actions = new List<ActionType>();
|
||||
while (true)
|
||||
{
|
||||
if (currentState.IsComplete)
|
||||
break;
|
||||
randomAction = currentState.AvailableActions.ElementAt(0);
|
||||
actions.Add(randomAction);
|
||||
currentState = Execute(currentState.State, randomAction, true);
|
||||
}
|
||||
|
||||
@@ -257,7 +258,7 @@ public class Solver
|
||||
{
|
||||
if (score >= ScoreStorageThreshold && score >= Tree.Get(0).State.Scores.MaxScore)
|
||||
{
|
||||
(var terminalIndex, _) = ExecuteActions(expandedIndex, currentState.State.ActionHistory.Skip(preCount).ToList(), true);
|
||||
(var terminalIndex, _) = ExecuteActions(expandedIndex, actions, true);
|
||||
return (terminalIndex, currentState.CompletionState, score);
|
||||
}
|
||||
}
|
||||
@@ -298,13 +299,12 @@ public class Solver
|
||||
{
|
||||
var actions = new List<ActionType>();
|
||||
var node = Tree.Get(0);
|
||||
while (node.Children.Count != 0) {
|
||||
while (node.Children.Count != 0)
|
||||
{
|
||||
var next_index = RustMaxBy(node.Children, n => Tree.Get(n).State.Scores.MaxScore);
|
||||
node = Tree.Get(next_index);
|
||||
if (node.State.Action != null)
|
||||
{
|
||||
actions.Add(node.State.Action.Value);
|
||||
}
|
||||
}
|
||||
|
||||
return (actions, node.State);
|
||||
|
||||
Reference in New Issue
Block a user