public MyPGM(MyPGM picture) { m_XSize = picture.XSize; m_YSize = picture.YSize; m_Colordepth = picture.ColorDepth; m_PixelMap = Copy(picture); }
/// <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); }
private void SetRound(int States, int x, int y, int Rot) { RailParts rp = new RailParts(); MyPGM BigCurve = new MyPGM(States * RailParts.Size, States * RailParts.Size); for (int i = 0; i < States; i++) { for (int j = 0; j < States; j++) { if (i == j) { RailParts.SetField(BigCurve, rp.GetCurve(1), i, j); } else if (j < i) { RailParts.SetField(BigCurve, rp.GetStraight(1), i, j); } else { RailParts.SetField(BigCurve, rp.GetStraight(0), i, j); } } } for (int i = 0; i < Rot; i++) { BigCurve.Rotate90(); } SetField(BigCurve, x, y); }
private void SetInputs(int States) { RailParts rp = new RailParts(); SetField(rp.GetCurve(1), 0, 0); SetField(rp.GetStraight(1), 1, 0); SetField(rp.GetStraight(1), 2, 0); SetField(rp.GetStraight(1), 4, 0); MyPGM Sprung = rp.GetSprung(true); Sprung.Rotate90(); SetField(Sprung, ReadWriteHead.YWriteInput + 1, 0); for (int i = 0; i < States; i++) { int StartYPos = 1 + i * ReadWriteHead.YRailsCnt; SetField(rp.GetStraight(0), 0, StartYPos + 0); SetField(rp.GetStraight(0), 0, StartYPos + 1); SetField(rp.GetStraight(0), 0, StartYPos + 2); SetField(rp.GetCrossing(), 0, StartYPos + 3); SetField(rp.GetStraight(0), 0, StartYPos + 4); } int EndPos = 1 + States * ReadWriteHead.YRailsCnt; SetField(rp.GetCurve(0), 0, EndPos); SetField(rp.GetStraight(1), 1, EndPos); SetField(rp.GetStraight(1), 2, EndPos); SetField(rp.GetCurve(3), ReadWriteHead.YWriteOutput + 1, EndPos); }
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); }
/// <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); }
private byte[] Copy(MyPGM Pixmap) { byte[] NewPixMap = new byte[Pixmap.XSize * Pixmap.YSize]; for (int i = 0; i < NewPixMap.Length; i++) { NewPixMap[i] = Pixmap.GetValue(i); } return(NewPixMap); }
public void CopyAtPos(MyPGM pgm, int x, int y) { for (int i = 0; i < pgm.YSize; i++) { for (int j = 0; j < pgm.XSize; j++) { this.SetValue(x + j, y + i, pgm.GetValue(j, i)); } } }
/// <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); }
/// <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); }
public Envelope(TMState ts, bool Set) { m_core = new Core(ts, Set); m_States = m_core.States; m_XRailsCnt = (m_core.XRailsCnt + m_States * 4); m_YRailsCnt = (m_core.YRailsCnt + m_States * 2); int XSize = m_XRailsCnt * RailParts.Size; int YSize = m_YRailsCnt * RailParts.Size; m_EnvPgm = new MyPGM(XSize, YSize); m_EnvPgm.CopyAtPos(m_core.CorePgm, m_States * 2 * RailParts.Size, m_States * RailParts.Size); SetConn(); }
public Core(TMState ts, bool Set) { m_TMStates = ts; m_rp = new RailParts(); m_StateCnt = TMLoader.CountStates(m_TMStates) / 2; m_XRailsCnt = ReadWriteHead.XRailsCnt + m_StateCnt * 2 + 1; m_YRailsCnt = ReadWriteHead.YRailsCnt * m_StateCnt + 2; int XSize = m_XRailsCnt * RailParts.Size; int YSize = m_YRailsCnt * RailParts.Size; m_CorePgm = new MyPGM(XSize, YSize); SetRWHeads(m_StateCnt, Set); SetInputs(m_StateCnt); SetSubroutine(m_StateCnt); }
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); }
public void Rotate90() { MyPGM temp = new MyPGM(m_XSize, m_YSize, m_PixelMap, false); m_XSize = temp.YSize; m_YSize = temp.XSize; m_PixelMap = new byte[m_XSize * m_YSize]; for (int i = 0; i < temp.YSize; i++) { for (int j = 0; j < temp.XSize; j++) { SetValue(m_XSize - i - 1, j, temp.GetValue(j, i)); } } }
public Circuit(TMState ts, Tape tp, int StateBegin, int TapePos) { int envXSize = 0; int envYInOut = 0; RailParts rp = new RailParts(); MyPGM straight = rp.GetStraight(1); MyPGM Start = rp.GetStart(); int TpCnt = TMLoader.CountTape(tp); int STCnt = TMLoader.CountStates(ts) / 2; Tape tmpTape = tp; Envelope env = null; for (int i = 0; i < TpCnt; i++) { if (tmpTape.GetSign().Equals("t")) { env = new Envelope(ts, true); } else { env = new Envelope(ts, false); } if (i == 0) { envXSize = (env.XRailsCnt + 1); envYInOut = env.FirstInOutput; int XSize = envXSize * TpCnt; int YSize = env.YRailsCnt; m_CircuitPgm = new MyPGM(XSize * RailParts.Size, YSize * RailParts.Size); } RailParts.SetField(m_CircuitPgm, env.EnvelopePgm, envXSize * i + 1, 0); for (int j = 0; j < STCnt; j++) { if (j == StateBegin && i == TapePos) { RailParts.SetField(m_CircuitPgm, Start, envXSize * i, envYInOut + ReadWriteHead.YRailsCnt * j + 1); } else { RailParts.SetField(m_CircuitPgm, straight, envXSize * i, envYInOut + ReadWriteHead.YRailsCnt * j + 1); } } tmpTape = tmpTape.GetNext(); } }
private void GenerateNeededParts(bool Set) { Sprung1 = m_rp.GetSprung(false); Sprung1.Rotate270(); Sprung2 = m_rp.GetSprung(false); Sprung2.MirrorX(); Sprung2.Rotate90(); Straight1 = m_rp.GetStraight(0); Straight2 = m_rp.GetStraight(1); Cross = m_rp.GetCrossing(); FlipFlop = m_rp.GetFlipFlop(!Set); Lazy = m_rp.GetLazy(!Set); Lazy.Rotate270(); Curve1 = m_rp.GetCurve(0); Curve2 = m_rp.GetCurve(1); Curve3 = m_rp.GetCurve(2); }
public ReadWriteHead(bool Set) { m_rp = new RailParts(); GenerateNeededParts(Set); m_ReadWriteHead = new MyPGM(m_XRailsCnt * RailParts.Size, m_YRailsCnt * RailParts.Size); SetToPosition(FlipFlop, 2, 0); SetToPosition(Curve3, 3, 0); SetToPosition(Sprung1, 2, 1); SetToPosition(Cross, 3, 1); SetToPosition(Curve2, 1, 1); SetToPosition(Straight1, 1, 2); SetToPosition(Straight1, 3, 2); SetToPosition(Sprung2, 0, 3); SetToPosition(Lazy, 1, 3); SetToPosition(Straight2, 2, 3); SetToPosition(Sprung1, 3, 3); SetToPosition(Curve1, 0, 4); SetToPosition(Straight2, 1, 4); SetToPosition(Curve3, 2, 4); }
/// <summary> /// Copy a ARil at a Destination /// </summary> /// <param name="Dest">Destination Picture</param> /// <param name="Src">Pic to copy in</param> /// <param name="X">at X Pos</param> /// <param name="Y">at Y Pos</param> public static void SetField(MyPGM Dest, MyPGM Src, int X, int Y) { Dest.CopyAtPos(Src, X * RailParts.Size, Y * RailParts.Size); }
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); } } } } } } }
private void SetSubroutine(int States) { RailParts rp = new RailParts(); MyPGM Lazy = rp.GetLazy(false); Lazy.MirrorX(); Lazy.Rotate90(); MyPGM Sprung1 = rp.GetSprung(false); Sprung1.MirrorY(); MyPGM Sprung2 = rp.GetSprung(false); Sprung2.Rotate180(); int[] SubConn = null; MyPGM Begins = GetSubroutineConn(States, ref SubConn); bool OneCurveSet = false; // Paint Subroutine for (int i = SubConn.Length; i > 0; i--) { if (SubConn[i - 1] > 1) { if (OneCurveSet) { SetField(Lazy, 1 + ReadWriteHead.XRailsCnt + i - 1, 0); } else { SetField(rp.GetCurve(2), 1 + ReadWriteHead.XRailsCnt + i - 1, 0); } OneCurveSet = true; } else { if (OneCurveSet) { SetField(rp.GetStraight(1), 1 + ReadWriteHead.XRailsCnt + i - 1, 0); } } } // Paint Connections int XStartPos = ReadWriteHead.XRailsCnt + 1; int YStartPos = 1; for (int i = 0; i < Begins.YSize; i++) { for (int j = 0; j < Begins.XSize; j++) { int Val = Begins.GetValue(j, i); if (Val == 1) { SetField(rp.GetStraight(0), XStartPos + j, YStartPos + i); } else if (Val == 2) { SetField(Sprung1, XStartPos + j, YStartPos + i); } else if (Val == 3) { SetField(rp.GetCurve(2), XStartPos + j, YStartPos + i); } else if (Val == 4) { SetField(rp.GetCrossing(), XStartPos + j, YStartPos + i); } else if (Val == 5) { SetField(Sprung2, XStartPos + j, YStartPos + i); } else if (Val == 6) { SetField(rp.GetStraight(1), XStartPos + j, YStartPos + i); } } } int LastPos = Begins.YSize - 1; for (int i = 0; i < Begins.XSize; i++) { if (Begins.GetValue(i, LastPos) > 0) { m_Connected[i] = 1; } else { m_Connected[i] = 0; } } }
private void SetField(MyPGM pgm, int X, int Y) { m_CorePgm.CopyAtPos(pgm, X * RailParts.Size, Y * RailParts.Size); }
private void SetField(MyPGM pgm, int X, int Y) { RailParts.SetField(m_EnvPgm, pgm, X, Y); }
private void SetToPosition(MyPGM Part, int x, int y) { m_ReadWriteHead.CopyAtPos(Part, x * RailParts.Size, y * RailParts.Size); }
private void SetConn() { RailParts rp = new RailParts(); int OutYPos = m_core.YRailsCnt + m_States; int OutXPos = m_core.BeginRailsOuts + m_States * 2; MyPGM Sprung1 = rp.GetSprung(false); Sprung1.Rotate90(); Sprung1.MirrorY(); MyPGM Sprung2 = rp.GetSprung(false); Sprung2.Rotate270(); Sprung2.MirrorY(); MyPGM Sprung3 = rp.GetSprung(true); Sprung3.Rotate270(); Sprung3.MirrorY(); for (int i = 0; i < m_States; i++) { for (int j = 0; j < m_States; j++) { if (j == i) { SetField(Sprung1, m_States * 2 - j - 1, ReadWriteHead.YRailsCnt * i + ReadWriteHead.XReadInput + m_States + 1); SetField(Sprung2, j, ReadWriteHead.YRailsCnt * i + ReadWriteHead.XReadInput + m_States + 1); SetField(rp.GetCurve(1), m_States * 4 + ReadWriteHead.XRailsCnt + i + 1, ReadWriteHead.YRailsCnt * i + ReadWriteHead.XReadInput + m_States + 1); SetField(Sprung3, m_States * 5 + ReadWriteHead.XRailsCnt + m_States - i, ReadWriteHead.YRailsCnt * i + ReadWriteHead.XReadInput + m_States + 1); } else if (j < i) { SetField(rp.GetCrossing(), m_States * 2 - j - 1, ReadWriteHead.YRailsCnt * i + ReadWriteHead.XReadInput + m_States + 1); SetField(rp.GetStraight(1), j, ReadWriteHead.YRailsCnt * i + ReadWriteHead.XReadInput + m_States + 1); SetField(rp.GetStraight(1), m_States * 4 + ReadWriteHead.XRailsCnt + i + 1, ReadWriteHead.YRailsCnt * j + ReadWriteHead.XReadInput + m_States + 1); SetField(rp.GetStraight(1), m_States * 5 + ReadWriteHead.XRailsCnt + m_States - j, ReadWriteHead.YRailsCnt * i + ReadWriteHead.XReadInput + m_States + 1); } else { SetField(rp.GetStraight(1), m_States * 2 - j - 1, ReadWriteHead.YRailsCnt * i + ReadWriteHead.XReadInput + m_States + 1); SetField(rp.GetCrossing(), j, ReadWriteHead.YRailsCnt * i + ReadWriteHead.XReadInput + m_States + 1); SetField(rp.GetStraight(0), m_States * 4 + ReadWriteHead.XRailsCnt + i + 1, ReadWriteHead.YRailsCnt * j + ReadWriteHead.XReadInput + m_States + 1); SetField(rp.GetCrossing(), m_States * 5 + ReadWriteHead.XRailsCnt + m_States - j, ReadWriteHead.YRailsCnt * i + ReadWriteHead.XReadInput + m_States + 1); } } for (int j = i; j < m_States - 1; j++) { for (int z = 1; z < ReadWriteHead.YRailsCnt; z++) { SetField(rp.GetStraight(0), m_States * 2 - i - 1, ReadWriteHead.YRailsCnt * j + ReadWriteHead.XReadInput + m_States + 1 + z); SetField(rp.GetStraight(0), m_States * 4 + ReadWriteHead.XRailsCnt + i + 1, ReadWriteHead.YRailsCnt * j + ReadWriteHead.XReadInput + m_States + 1 + z); } } for (int j = 0; j < i; j++) { for (int z = 1; z < ReadWriteHead.YRailsCnt; z++) { SetField(rp.GetStraight(0), i, ReadWriteHead.YRailsCnt * j + ReadWriteHead.XReadInput + m_States + 1 + z); SetField(rp.GetStraight(0), m_States * 5 + ReadWriteHead.XRailsCnt + (m_States - i - 1) + 1, ReadWriteHead.YRailsCnt * j + ReadWriteHead.XReadInput + m_States + 1 + z); } } for (int j = 0; j < (ReadWriteHead.YRailsCnt - ReadWriteHead.XReadInput); j++) { SetField(rp.GetStraight(0), m_States + i, ReadWriteHead.YRailsCnt * m_States + m_States + j); SetField(rp.GetStraight(0), m_States * 4 + ReadWriteHead.XRailsCnt + 1 + i, ReadWriteHead.YRailsCnt * m_States + m_States + j); } for (int j = m_States * 2; j < OutXPos; j++) { SetField(rp.GetStraight(1), j, OutYPos + i); } for (int j = m_States; j < m_States * 3 + m_core.XRailsCnt; j++) { SetField(rp.GetStraight(1), j, i); } for (int j = 0; j < ReadWriteHead.XReadInput + 1; j++) { SetField(rp.GetStraight(0), i, j + m_States); SetField(rp.GetStraight(0), m_States * 3 + m_core.XRailsCnt + i, j + m_States); } } SetRound(m_States, OutXPos, OutYPos, 2); SetRound(m_States, m_States, OutYPos, 3); SetRound(m_States, OutXPos + m_States, OutYPos, 3); SetRound(m_States, OutXPos + m_States + m_States, OutYPos, 2); SetRound(m_States, 0, 0, 0); SetRound(m_States, m_States * 3 + m_core.XRailsCnt, 0, 1); }