private void SubmitButton_Click(object sender, EventArgs e) { resultTextBox.Clear(); resultTextBox.BackColor = Color.LightGray; //validating that the input is 0 and 1 only bool validText = true; for (int i = 0; i < inputTextBox.Text.Length; i++) { if (inputTextBox.Text[i] != '0' && inputTextBox.Text[i] != '1') { MessageBox.Show("Input word may contain 0 and 1 only !!!"); validText = false; inputTextBox.Text = ""; break; } } if (validText) { TM.tape = new Tape(); TM.tape.setTapeState(inputTextBox.Text); refreshTape(); allStates = TM.runTuringMachine(inputTextBox.Text); currentStateIndex = 0; curStateId = prevStateId = allStates[0].id; GraphicalTMPanel.Refresh(); } }
private void goToFinalButton_Click(object sender, EventArgs e) { while (currentStateIndex < allStates.Count - 1) { NextStepButton_Click(sender, e); } GraphicalTMPanel.Refresh(); TapeTextBox.Refresh(); }
private void CompleteButton_Click(object sender, EventArgs e) { while (currentStateIndex < allStates.Count - 1) { NextStepButton_Click(sender, e); GraphicalTMPanel.Refresh(); TapeTextBox.Refresh(); System.Threading.Thread.Sleep(1000); } }
private void GraphicalTMPanel_Paint(object sender, PaintEventArgs e) { blackPen = new Pen(Color.FromArgb(0, 0, 0)); redPen = new Pen(Color.Red); orangePen = new Pen(Color.Orange); g = GraphicalTMPanel.CreateGraphics(); LoadFile_Click(sender, e); blackPen.Width = 3F; redPen.Width = 5F; orangePen.Width = 5F; //drawing the states Point drawPosition; for (int i = 0; i < statePosition.Count; i++) { drawPosition = statePosition[i]; drawPosition.X -= 25; drawPosition.Y -= 25; if (i == curStateId) { drawState(i, redPen, TM.states[i].isFinal); } else if (i == prevStateId) { drawState(i, orangePen, TM.states[i].isFinal); } else { drawState(i, blackPen, TM.states[i].isFinal); } } //drawing the labels of the nodes for (int i = 0; i < statePosition.Count; i++) { Label lbl = new Label(); lbl.Size = new Size(25, 15); lbl.Text = "Q" + i.ToString(); Point lblPosition = statePosition[i]; lblPosition.X -= 10; lblPosition.Y -= 5; lbl.Location = lblPosition; GraphicalTMPanel.Controls.Add(lbl); } }
private void GraphicalTMPanel_Paint(object sender, PaintEventArgs e) { blackPen = new Pen(Color.FromArgb(0, 0, 0)); redPen = new Pen(Color.Red); orangePen = new Pen(Color.Orange); g = GraphicalTMPanel.CreateGraphics(); blackPen.Width = 3F; redPen.Width = 5F; orangePen.Width = 5F; //drawing the states Point drawPosition; for (int i = 0; i < statePosition.Count; i++) { drawPosition = statePosition[i]; drawPosition.X -= 25; drawPosition.Y -= 25; if (i == curStateId) { drawState(i, redPen); } else if (i == prevStateId) { drawState(i, orangePen); } else { drawState(i, blackPen); } } //drawing the labels of the nodes for (int i = 0; i < statePosition.Count; i++) { Label lbl = new Label(); lbl.Size = new Size(25, 15); lbl.Text = "Q" + i.ToString(); Point lblPosition = statePosition[i]; lblPosition.X -= 10; lblPosition.Y -= 5; lbl.Location = lblPosition; GraphicalTMPanel.Controls.Add(lbl); } //drawing the transitions int from, to; for (int i = 0; i < TM.states.Count; i++) { from = i; if (TM.states[i].transition.ContainsKey('0')) { to = TM.states[i].transition['0'].Item3.id; if (from == to) { drawSelfLoop(from, from == 3 ? orientation.East: orientation.North, blackPen); } else { drawTransition(from, to, blackPen); } } if (TM.states[i].transition.ContainsKey('1')) { to = TM.states[i].transition['1'].Item3.id; if (from == to) { drawSelfLoop(from, from == 3 ? orientation.East : orientation.South, blackPen); } else { drawTransition(from, to, blackPen); } } if (TM.states[i].transition.ContainsKey(' ')) { to = TM.states[i].transition[' '].Item3.id; if (from == to) { drawSelfLoop(from, orientation.East, blackPen); } else { drawTransition(from, to, blackPen); } } } //drawing the text above each transition for (int i = 0; i < transitionLabelsPositions.Count; i++) { drawText(transitionLabelsPositions[i], transitionLabelsText[i]); } //drawText(new Point(256, 86), "0/$ , R"); //drawText(new Point(385, 45), "0/0 , R"); //drawText(new Point(380, 155), "1/1 , R"); //drawText(new Point(497, 86), "$/$ , L"); //drawText(new Point(642, 189), "0/$ , L"); //drawText(new Point(706, 88), "$/$ , S"); //drawText(new Point(700, 265), "1/1 , L"); //drawText(new Point(700, 290), "0/0 , L"); //drawText(new Point(373, 220), "$/$ , R"); //drawText(new Point(242, 200), "1/$ , R"); //drawText(new Point(303, 272), "0/0 , R"); //drawText(new Point(299, 384), "1/1 , R"); //drawText(new Point(421, 400), "$/$ , R"); //drawText(new Point(650, 364), "1/$ , L"); //drawText(new Point(672, 405), "$/$ , S"); //drawText(new Point(60, 180), "$/$ , S"); /* * 0 1 256 86 * 1 1 385, 45 * 1 1 396, 161 * 1 2 497, 86 * 2 3 642, 189 * 2 7 706, 88 * 3 3 700, 265 * 3 3 700, 296 * 0 4 260, 227 * 4 4 303, 272 * 4 4 299, 384 * 4 5 421, 392 * 5 3 650, 364 * 5 8 672, 405 * 0 9 27 ,194 */ }