import java.lang.*; import java.util.*; public class TwoThreeState extends TraversableState implements Heuristic { int stateValue; public TwoThreeState() { stateValue = 0; } public State applyOperator(String op) { TwoThreeState nextState = new TwoThreeState(); if (op.equals("add2")) { nextState.stateValue= stateValue+2; } else if (op.equals("add3")) { nextState.stateValue= stateValue+3; } return nextState; } public float costOf(String op) { if (op.equals("add2")) { return 2; } else { return (float) 4; } } public ArrayList validOperators() { ArrayList opList = new ArrayList(); opList.add("add3"); opList.add("add2"); return opList; } public boolean isGoal() { return (stateValue > 0 && stateValue%23==0) ; } public float h() { float hVal = 23 - stateValue; if (hVal<0) return 0; else return hVal; } public String toString() { return "(" + stateValue + ")"; } }