package at.oefai.aaa.agent.jam;

import at.oefai.aaa.agent.jam.types.Binding;

/**
 * Represents the runtime state of plan constructs.
 * @author Marc Huber
 * @author Jaeho Lee
 */
class PlanRuntimeAtomicState implements PlanRuntimeState {

    private PlanConstruct thisConstruct = null;
    private PlanRuntimeState substate = null;

    /**  */
    PlanRuntimeAtomicState(final PlanAtomicConstruct be) {
        this.thisConstruct = be;
        this.substate = be.getSequence().newRuntimeState();
    }

    // Member functions

    /**  */
    public State execute(final Binding b, final Goal thisGoal) {
        // Continue to loop execute while the sequence isn't done.  If the
        // sequence signals that it failed or succeeded, then return this
        // value.
        State returnVal;
        while (true) {
            returnVal = this.substate.execute(b, thisGoal);
            if (returnVal != State.CONSTRUCT_INCOMP) {
                return returnVal;
            }
        }
    }

}

