package at.oefai.aaa.agent.jam;

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

/**
 * A fake subclass of Goal to hold virtual goals.
 * As help or hinder behaviours for each standard of an actor
 * @author wrstlprmpft
 */
public class FakeStandardGoal extends AbstractGoal {
    private static final float FACTOR = 12; // factor for the fake utility

    private final float util;
    private final GoalAction ga;

    public FakeStandardGoal(final IntentionStructure pIs, final Relation r) {
        super(pIs);
        this.util = Math.abs(r.getStandardValue(null)) * FACTOR;
        this.ga = new MaintainGoalAction(this.transformRel(r), null);
    }

    public final float evalUtility() {
        return this.util;
    }

    public final GoalAction getGoalAction() {
        return this.ga;
    }

    private Relation transformRel(final Relation r) {
        // transform a standard relation into a behaviour rel
        String type;
        if (r.getStandardValue(null) > 0) {
            type = Relation.HELP_BEHAVIOUR_FACT;
        } else {
            type = Relation.HINDER_BEHAVIOUR_FACT;
        }
        ExpList el = new ExpList(r.getArgs());
        el.removeLast();
        return new Relation(type, el);
    }

    public final String formattedString() {
        return this.toString();
    }

    public final String toString() {
        StringBuffer sb = new StringBuffer();
        sb.append("FakeStandardGoal ");
        sb.append("|Utility:" + this.util + "| ");
        if (this.ga != null) {
            sb.append(this.ga.simpleString(getGoalBinding()));
        } else {
            sb.append("null");
        }
        sb.append(" | ");
        return sb.toString();
    }

}
