private bool DoStep() { // Read band char c = turingBand.Read(); // Check if word is in a state to be accepted if (_finalStates.Contains(currentState)) { DisplayEnd(); return(false); } // Execute rule TuringRuleOutput o = _rules[new TuringRuleInput() { CurrentChar = c, CurrentState = currentState }]; currentState = o.NewState; turingBand.Write(o.NewChar, o.Direction); // Add command commands.Add($"State: {o.NewState}, Write: {o.NewChar}, Dir: {o.Direction}"); executionSteps++; // Display display(); return(true); }
public TuringMachine( List <string> states, string initialState, List <string> finalStates, List <char> symbols, char emptySymbol, List <char> inputSymbols, List <TuringRule> rules ) { // Output preparations Console.SetWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT); // Values this._states = new HashSet <string>(states); this._symbols = new HashSet <char>(symbols); this._emptySymbol = emptySymbol; this._inputSymbols = new HashSet <char>(inputSymbols); this._initialState = initialState; this._finalStates = new HashSet <string>(finalStates); foreach (TuringRule r in rules) { TuringRuleInput i = new TuringRuleInput() { CurrentChar = r.CurrentChar, CurrentState = r.CurrentState }; TuringRuleOutput o = new TuringRuleOutput() { Direction = r.Direction, NewChar = r.NewChar, NewState = r.NewState }; this._rules.Add(i, o); } this.turingBand = new TuringBand(_emptySymbol); this.settings = new TuringSettings(); }