package at.ac.tuwien.dbai.alternation.examples;
import java.util.Set;
import java.util.Map;

atm AlternatingTuringMachine(char[] inputtape, TransitionFunction delta, Map<
                             Integer,Character> stateType, int initialState,int
                             C) {
    char[] worktape=new char[C];
    int inputCursor = 0;
    int workCursor = 0;
    int activeState=initialState;
    boolean first =true;

    state alternatingTuringMachine {
        if (first) {
            java.util.Arrays.fill(worktape, 'b');
            first=false;
        }
        if(stateType.get(activeState).equals('A')) {
            accept;
        }
        if(stateType.get(activeState).equals('R')) {
            reject;
        }
        if(stateType.get(activeState).equals('F')) {
            forall{
                for (TransitionFunction.Output outputTuple : delta.compute(
                     inputtape[inputCursor],worktape[workCursor],activeState)){
                    alternatingTuringMachine{
                        worktape[workCursor]=outputTuple.workSymbol;
                        activeState =outputTuple.newState;
                        inputCursor+=outputTuple.inputCursor;
                        workCursor+=outputTuple.workCursor;
                    }
                }
            }
        }
        if(stateType.get(activeState).equals('E')) {
            exists{
                for (TransitionFunction.Output outputTuple : delta.compute(
                     inputtape[inputCursor],worktape[workCursor],activeState)){
                    alternatingTuringMachine{
                        worktape[workCursor]=outputTuple.workSymbol;
                        activeState =outputTuple.newState;
                        inputCursor+=outputTuple.inputCursor;
                        workCursor+=outputTuple.workCursor;
                    }
                }
            }
        }
        reject;
    }
}