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); }
private MyPGM GetSwitch(RailType rt, bool Right) { MyPGM FlipFlopSwitch = new MyPGM(Size, Size, m_Switch); FlipFlopSwitch.SetValue(0, 0, (byte)rt); if (Right) { FlipFlopSwitch.SetValue(5, 1, 128); } else { FlipFlopSwitch.SetValue(2, 1, 128); } return(FlipFlopSwitch); }
/// <summary> /// rails are crossing like tunnel or bridge over another rail /// </summary> /// <returns></returns> public MyPGM GetCrossing() { MyPGM Crossing = new MyPGM(Size, Size, m_Cross); Crossing.SetValue(0, 0, (byte)RailType.CROSS); return(Crossing); }
/// <summary> /// Starter /// </summary> /// <returns></returns> public MyPGM GetStart() { MyPGM Starter = new MyPGM(Size, Size, m_Start); Starter.SetValue(0, 0, (byte)RailType.START); Starter.Rotate90(); return(Starter); }
/// <summary> /// RailCurve Change direction /// </summary> /// <returns></returns> public MyPGM GetCurve(int Rot) { MyPGM Curve = new MyPGM(Size, Size, m_Curve); Curve.SetValue(0, 0, (byte)RailType.CURVE); for (int i = 0; i < Rot; i++) { Curve.Rotate90(); } return(Curve); }
/// <summary> /// a Connection straight rail /// </summary> /// <param name="Rot">up/down or left/right</param> /// <returns></returns> public MyPGM GetStraight(int Rot) { MyPGM StraightRail = new MyPGM(Size, Size, m_Straight); StraightRail.SetValue(0, 0, (byte)RailType.STRAIGHT); if (Rot > 0) { StraightRail.Rotate90(); } return(StraightRail); }
private void FillConnMatrix(MyPGM ConnMat, int[] SubConn, int[] ConnY) { int XStartPos = ReadWriteHead.XRailsCnt + 1; for (int j = 0; j < ConnMat.XSize; j++) { if (SubConn[j] == 2) { ConnMat.SetValue(j, 0, 1); } } for (int i = 1; i < ConnMat.YSize; i++) { for (int j = 0; j < ConnMat.XSize; j++) { int ValBefore = ConnMat.GetValue(j, i - 1); int ValActual = ConnMat.GetValue(j, i); int Conn = ConnY[i]; int Sub = SubConn[j]; if (ValActual == 2) { ConnMat.SetValue(j, i, 2); } else if (ValActual == 1) { if (ValBefore == 0) { ConnMat.SetValue(j, i, 3); } else { ConnMat.SetValue(j, i, 5); } } else { if (Conn == 0) { if (ValBefore == 0) { } else if (ValBefore == 6) { } else { ConnMat.SetValue(j, i, 1); } } else { if (ValBefore == 0) { if (Conn > j + 1) { ConnMat.SetValue(j, i, 6); } } else { if (Conn > j + 1) { ConnMat.SetValue(j, i, 4); } else { ConnMat.SetValue(j, i, 1); } } } } } } }