jill/src/main/java/io/github/agentsoz/jill/core/IntentionSelector.java
private void managePlan(int agentIndex, Stack255 agentExecutionStack, Plan node,
      Set<Integer> toRemove) {
    // If done then pop this plan/goal
    if (node.hasfinished()) {
      logger.debug(Log.logPrefix(agentIndex) + " finished executing plan "
          + node.getClass().getSimpleName());
      synchronized (agentExecutionStack) {
        // Pop the plan off the stack
        agentExecutionStack.pop();
        // Pop the goal off the stack
        agentExecutionStack.pop();
        if (agentExecutionStack.isEmpty()) {
          // remove empty intention stacks
          Agent agent = (Agent) GlobalState.agents.get(agentIndex);
          int size = agent.cleanupStacks();
          // If we are left with only one stack and that is empty, then agent is idle
          if (size == 1 && agent.getExecutionStack().isEmpty()) {
            // Mark this agent as idle
            // Main.setAgentIdle(i, true);
            toRemove.add(agentIndex);
          }
        }
      }
    } else {
      logger.debug(Log.logPrefix(agentIndex) + " is executing a step of plan "
          + node.getClass().getSimpleName());
      node.step();
    }
  }
private void managePlan(int agentIndex, Stack255 agentExecutionStack, Plan node,
      Set<Integer> toRemove) {
    // If done then pop this plan/goal
    if (node.hasfinished()) {
      logger.debug(Log.logPrefix(agentIndex) + " finished executing plan "
          + node.getClass().getSimpleName());
      synchronized (agentExecutionStack) {
        // Pop the plan off the stack
        agentExecutionStack.pop();
        // Pop the goal off the stack
        agentExecutionStack.pop();
        if (agentExecutionStack.isEmpty()) {
          // remove empty intention stacks
          Agent agent = (Agent) GlobalState.agents.get(agentIndex);
          int size = agent.cleanupStacks();
          // If we are left with only one stack and that is empty, then agent is idle
          if (size == 1 && agent.getExecutionStack().isEmpty()) {
            // Mark this agent as idle
            // Main.setAgentIdle(i, true);
            toRemove.add(agentIndex);
          }
        }
      }
    } else {
      logger.debug(Log.logPrefix(agentIndex) + " is executing a step of plan "
          + node.getClass().getSimpleName());
      node.step();
    }
  }
Manages the plan at the top of this agent's execution stack. If the plan has finished it is
removed, else it is progresses by a single {@link PlanStep}.

@param agentIndex the agent in question
@param agentExecutionStack this agent's execution stack
@param node the plan at the top of the execution stack
@param toRemove the remove list to which this agent should be added if the plan has finished