public void DrawMachine(TuringMachine machine) { drawArea.Clear(Color.White); Pen blackPen = new Pen(Color.Black); float NumberOfBoxes = machine.MachineTape.boxes.Count; int pointer = machine.Pointer; List <string> symbols = machine.MachineTape.boxes; float width = DrawingArea.Width - 10; float boxWidth = width / NumberOfBoxes; float boxHeight = boxWidth; float startX = 2; float startY = (DrawingArea.Height - boxHeight) / 2; float letterHeight = (boxHeight - 5); DrawArrow((startX + boxWidth / 2) + pointer * boxWidth, startY + boxHeight + 50, (startX + boxWidth / 2) + pointer * boxWidth, startY + boxHeight + 5, Color.FromArgb(255, 0, 0, 255)); for (int i = 0; i < NumberOfBoxes; i++) { drawArea.DrawLine(blackPen, startX + boxWidth * i, startY, startX + boxWidth * i, startY + boxHeight); drawArea.DrawLine(blackPen, startX + boxWidth * (i + 1), startY, startX + boxWidth * (i + 1), startY + boxHeight); drawArea.DrawLine(blackPen, startX + boxWidth * i, startY, startX + boxWidth * (i + 1), startY); drawArea.DrawLine(blackPen, startX + boxWidth * i, startY + boxHeight, startX + boxWidth * (i + 1), startY + boxHeight); DrawString(symbols[i], startX + boxWidth * i, startY + (boxHeight - letterHeight) / 2, letterHeight, Color.Black); } }
private void SelectMachine() { FirstMultiplier = true; drawArea.Clear(Color.White); while (dataGridView1.Columns.Count >= 1) { dataGridView1.Columns.RemoveAt(0); } if (radioButton1.Checked) { um = new Subtractor("", "♭" + MultiplierTxtEntry.Text); } else if (radioButton2.Checked) { um = new Adder("", MultiplierTxtEntry.Text); } else if (radioButton3.Checked) { um = new UnaryMultiplier("", MultiplierTxtEntry.Text); } else if (radioButton4.Checked) { um = new Duplicador("", "♭" + MultiplierTxtEntry.Text); } else if (radioButton5.Checked) { um = new PalindromeValidator("", MultiplierTxtEntry.Text + "♭♭"); } }
static async Task Main(string[] args) { var program = new TuringMachine(); await program.Menu(); Console.ReadLine(); }
public static void Main(string[] args) { var cnw = GetConsoleWindow(); ShowWindow(cnw, SW_HIDE); Application.EnableVisualStyles(); TuringMachine turing = new TuringMachine(); Application.Run(turing); }
public string Run(string currentSymbol, TuringMachine machine) { foreach (var rule in TransitionRules) { if (!rule.Symbol.IsMatch(currentSymbol)) { continue; } foreach (var op in rule.Operations) { op.Execute(machine); } return(rule.NextStateName); } return(null); }
private void Compile() { history = ""; counter = 0; lStepCount.Text = "Steps: 0"; List <MoveFunktion> funktions; Band inputBand; try { funktions = TuringParser.ParseMoveFunctions(tbMoveFun.Text).ToList(); } catch (Exception ex) { tbError.Text = ex.Message + "\r\n\r\n" + ex.StackTrace; return; } try { inputBand = TuringParser.ReadBaender(tbInputBand.Text)[0]; } catch (Exception ex) { tbError.Text = ex.Message + "\r\n\r\n" + ex.StackTrace; return; } tbError.Text = "No Compile Errors"; List <Band> baender = new List <Band>(); baender.Add(inputBand); for (int i = 0; i < numBaender.Value; i++) { baender.Add(new Band()); } machine = new TuringMachine(baender, funktions); DumpMachine(); }
public static void Main(string[] args) { if (args.Length < 2) { Console.Error.WriteLine("Invalid arguments. Please provide program path and tape path."); return; } var programPath = args[0]; if (!File.Exists(programPath)) { Console.Error.WriteLine($"Invalid program path: {programPath}"); return; } Console.WriteLine($"Program file path: {programPath}"); var programInput = File.ReadAllLines(programPath); var tapePath = args[1]; if (!File.Exists(tapePath)) { Console.Error.WriteLine($"Invalid tape path: {tapePath}"); return; } Console.WriteLine($"Tape file path: {tapePath}"); var tapeInput = File.ReadAllText(tapePath); Console.WriteLine($"Initial machine state: {tapeInput}"); Console.WriteLine("Program: "); foreach (var line in programInput) { Console.WriteLine(line); } try { var machineState = TuringMachine.AnalyzeMachineStateDescription(tapeInput); Console.WriteLine("Head state: " + machineState.headState); Console.WriteLine("Head position: " + machineState.headPosition); Console.WriteLine("Tape: " + new string(machineState.tape)); var program = TuringMachine.parseProgram(programInput); Console.WriteLine("\nProgram execution..."); var history = TuringMachine.ExecuteProgram(machineState, program); Console.WriteLine("\nMachine state change:"); foreach (var line in history) { Console.WriteLine(line); } } catch (Exception e) { var color = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.DarkRed; Console.Error.WriteLine(e.Message); Console.ForegroundColor = color; } Console.WriteLine("\nPress enter to exit."); Console.ReadLine(); }