Beispiel #1
0
        private void QuickRunButton_Click(object sender, RoutedEventArgs e)
        {
            TuringMachineBroker broker = new TuringMachineBroker(ContainingMachine);

            broker.InitializeMachine();
            MessageBox.Show("Machine Output: " + broker.Run(InputTextBox.Text), "Result", MessageBoxButton.OK, MessageBoxImage.Information);
        }
Beispiel #2
0
        public override string Run(string input)
        {
            TuringMachineBroker broker = new TuringMachineBroker(this);

            broker.InitializeMachine();
            return(broker.Run(input));
        }
Beispiel #3
0
        async void RunMachineStep(string input)
        {
            int cursor = 0;
            TuringMachineBroker broker = new TuringMachineBroker(ContainingMachine);

            try
            {
                broker.InitializeMachine();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }
            TuringBrokerStepResult stepresult = new TuringBrokerStepResult(null, '\0', Transition.Right);

            do
            {
                try
                {
                    await TapeControl.ScrollToItem(cursor, true);

                    stepresult = broker.Step(input[cursor], stepresult.Destination);
                    if (stepresult == null)
                    {
                        return;
                    }
                    await Task.Delay(500);

                    input = input.Remove(cursor, 1);
                    input = input.Insert(cursor, stepresult.ReplaceBy.ToString());
                    input = stepresult.Destination.RunVertex(input);

                    TapeControl.ChangeInput(input);

                    if (stepresult.To == Transition.Right)
                    {
                        cursor++;
                        if (cursor >= input.Length)
                        {
                            input += "#";
                        }
                    }
                    else if (stepresult.To == Transition.Left)
                    {
                        cursor--;
                        if (cursor < 0)
                        {
                            input  = "#" + input;
                            cursor = 0;
                            await TapeControl.ScrollToItem(1, false);
                        }
                    }

                    stepresult.Destination.InvokeActivation();
                }


                catch (Exception ex)
                {
                    //SetNotificationText("Error: " + ex.Message);
                    return;
                }
            } while (stepresult.Destination != null);

            TapeControl.ChangeInput(input);
        }