Fix HTN task ordering bug (#32909)
* first, bad ordering * fix * Revert "first, bad ordering", recording artifacts This reverts commit 22307675d79b417371775a0558c39781f59423d6.
This commit is contained in:
@@ -56,16 +56,16 @@ public sealed class HTNPlanJob : Job<HTNPlan>
|
|||||||
// hence we'll store it here.
|
// hence we'll store it here.
|
||||||
var appliedStates = new List<Dictionary<string, object>?>();
|
var appliedStates = new List<Dictionary<string, object>?>();
|
||||||
|
|
||||||
var tasksToProcess = new Queue<HTNTask>();
|
var tasksToProcess = new Stack<HTNTask>();
|
||||||
var finalPlan = new List<HTNPrimitiveTask>();
|
var finalPlan = new List<HTNPrimitiveTask>();
|
||||||
tasksToProcess.Enqueue(_rootTask);
|
tasksToProcess.Push(_rootTask);
|
||||||
|
|
||||||
// How many primitive tasks we've added since last record.
|
// How many primitive tasks we've added since last record.
|
||||||
var primitiveCount = 0;
|
var primitiveCount = 0;
|
||||||
|
|
||||||
int tasksProcessed = 0;
|
int tasksProcessed = 0;
|
||||||
|
|
||||||
while (tasksToProcess.TryDequeue(out var currentTask))
|
while (tasksToProcess.TryPop(out var currentTask))
|
||||||
{
|
{
|
||||||
if (tasksProcessed++ > _rootTask.MaximumTasks)
|
if (tasksProcessed++ > _rootTask.MaximumTasks)
|
||||||
throw new Exception("HTN Planner exceeded maximum tasks");
|
throw new Exception("HTN Planner exceeded maximum tasks");
|
||||||
@@ -161,7 +161,7 @@ public sealed class HTNPlanJob : Job<HTNPlan>
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Goes through each compound task branch and tries to find an appropriate one.
|
/// Goes through each compound task branch and tries to find an appropriate one.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private bool TryFindSatisfiedMethod(HTNCompoundTask compoundId, Queue<HTNTask> tasksToProcess, NPCBlackboard blackboard, ref int mtrIndex)
|
private bool TryFindSatisfiedMethod(HTNCompoundTask compoundId, Stack<HTNTask> tasksToProcess, NPCBlackboard blackboard, ref int mtrIndex)
|
||||||
{
|
{
|
||||||
var compound = _protoManager.Index<HTNCompoundPrototype>(compoundId.Task);
|
var compound = _protoManager.Index<HTNCompoundPrototype>(compoundId.Task);
|
||||||
|
|
||||||
@@ -182,9 +182,9 @@ public sealed class HTNPlanJob : Job<HTNPlan>
|
|||||||
if (!isValid)
|
if (!isValid)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
foreach (var task in branch.Tasks)
|
foreach (var task in branch.Tasks.AsEnumerable().Reverse())
|
||||||
{
|
{
|
||||||
tasksToProcess.Enqueue(task);
|
tasksToProcess.Push(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -198,7 +198,7 @@ public sealed class HTNPlanJob : Job<HTNPlan>
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void RestoreTolastDecomposedTask(
|
private void RestoreTolastDecomposedTask(
|
||||||
Stack<DecompositionState> decompHistory,
|
Stack<DecompositionState> decompHistory,
|
||||||
Queue<HTNTask> tasksToProcess,
|
Stack<HTNTask> tasksToProcess,
|
||||||
List<Dictionary<string, object>?> appliedStates,
|
List<Dictionary<string, object>?> appliedStates,
|
||||||
List<HTNPrimitiveTask> finalPlan,
|
List<HTNPrimitiveTask> finalPlan,
|
||||||
ref int primitiveCount,
|
ref int primitiveCount,
|
||||||
@@ -223,7 +223,7 @@ public sealed class HTNPlanJob : Job<HTNPlan>
|
|||||||
|
|
||||||
primitiveCount = lastDecomp.PrimitiveCount;
|
primitiveCount = lastDecomp.PrimitiveCount;
|
||||||
blackboard = lastDecomp.Blackboard;
|
blackboard = lastDecomp.Blackboard;
|
||||||
tasksToProcess.Enqueue(lastDecomp.CompoundTask);
|
tasksToProcess.Push(lastDecomp.CompoundTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user