public static int FindStateNr(TMState ts, string StateName) { TMState tmpState = ts; int StateNr = 0; bool Found = false; while (tmpState != null) { if (StateName.Equals(tmpState.GetStateF())) { Found = true; break; } StateNr++; tmpState = tmpState.GetNext(); } if (Found) { return(StateNr / 2); } else { return(-1); } }
private MyPGM GetSubroutineConn(int States, ref int[] SubConn) { MyPGM ConnMatrix = new MyPGM(States * 2, States * ReadWriteHead.YRailsCnt + 1); TMState tmpState = m_TMStates; SubConn = new int[ConnMatrix.XSize]; int[] ConnY = new int[ConnMatrix.YSize]; m_Connected = new byte[ConnMatrix.XSize]; int ActStateNr = 0; for (int i = 0; i < SubConn.Length; i++) { SubConn[i] = 0; } for (int i = 0; i < ConnY.Length; i++) { ConnY[i] = 0; } while (tmpState != null) { int StateNr = TMLoader.FindStateNr(m_TMStates, tmpState.GetStateN()); int YPos = (ActStateNr / 2) * ReadWriteHead.YRailsCnt; if (StateNr >= 0) { if ((ActStateNr % 2) == 0) { YPos += ReadWriteHead.XReadOutputTrue; } else { YPos += ReadWriteHead.XReadOutputFalse; } bool Dir = false; if (tmpState.GetMove().Equals("R")) { Dir = true; } int SubPos = GetSubOutPos(States, StateNr, Dir); if (tmpState.GetRead().Equals(tmpState.GetWrite())) { if (SubConn[SubPos] == 0) { SubConn[SubPos] = 1; } ConnMatrix.SetValue(SubPos, YPos, 1); } else { SubConn[SubPos] = 2; ConnMatrix.SetValue(SubPos, YPos, 2); } ConnY[YPos] = SubPos + 1; } ActStateNr++; tmpState = tmpState.GetNext(); } FillConnMatrix(ConnMatrix, SubConn, ConnY); return(ConnMatrix); }
public static int CountStates(TMState ts) { TMState tmpState = ts; int cnt = 0; while (tmpState != null) { cnt++; tmpState = tmpState.GetNext(); } return(cnt); }
private TMState AddState(string state1, string read, string state2, string write, string move) { if (Start == null) { Start = new TMState(state1, read, state2, write, move); Last = Start; } else { Last.SetNext(new TMState(state1, read, state2, write, move)); Last = Last.GetNext(); } return(Last); }