package ec.gp.syntactic.simplification.logic;

import ec.EvolutionState;
import ec.app.semanticGP.func.logic.And;
import ec.app.semanticGP.func.logic.Constant;
import ec.app.semanticGP.func.logic.Inv;
import ec.gp.GPNode;
import ec.gp.syntactic.simplification.IRule;
import ec.util.Parameter;

class AndNotRule implements IRule {

	private EvolutionState state;

	@Override
	public void setup(EvolutionState state, Parameter base) {
		this.state = state;
	}

	@Override
	public boolean match(GPNode subtree) {
		if (!(subtree instanceof And))
			return false;

		if (subtree.children[0] instanceof Inv) {
			return subtree.children[0].children[0].rootedTreeEquals(subtree.children[1]);
		}

		if (subtree.children[1] instanceof Inv) {
			return subtree.children[1].children[0].rootedTreeEquals(subtree.children[0]);
		}

		return false;
	}

	@Override
	public GPNode replace(GPNode subtree) {
		assert match(subtree) : "The given tree is not a form of (p and not p) or (not p and p)";

		return Constant.get(false);
	}

}
