package at.oefai.aaa.agent;

import java.io.IOException;
import java.util.List;

import at.oefai.aaa.agent.jam.IEnvironment;
import at.oefai.aaa.agent.jam.WorldModelTableEvent;
import at.oefai.aaa.agent.jam.ParseException;
import at.oefai.aaa.agent.jam.types.Value;

/**
 * The Interpreter for Actors, knows about an environment; it can ask for actions and perceptions.
 * @author Stefan Rank
 */
public class ActorInterpreter extends ModelInterpreter implements IEnvironment {
    private final IEnvironment environment;

    /** Creates an Actor given the name, args for the superclass and the environment reference. */
    public ActorInterpreter(final String name, final String[] argv, final IEnvironment env)
                            throws ParseException, IOException {
        super(name, argv);
        assert (env != null);
        this.environment = env;
        //setShowIntentionStructure(true);
    }

    public final void assertName() {
        this.simpleAssert("myNameIs", new String[] {this.getName()});
    }


    // Outward functions

    public final WorldModelTableEvent[] getPerceptionsOf(final String agentName) {
        assert agentName.equals(this.getName());
        // ignore agentName argument, only this ones perceptions can be called
        return this.environment.getPerceptionsOf(this.getName());
    }

    public final boolean requestAction(final String actor, final String actionName, final List<Value> arguments) {
        assert actor.equals(this.getName());
        // ignore actor argument, only this one can act
        return this.environment.requestAction(this.getName(), actionName, arguments);
    }

}
