コード例 #1
0
        public void Run()
        {
            if (MachineEstado == Estado.Pronto)
            {
                MachineEstado = Estado.Rodando;
            }

            if (MachineEstado != Estado.Rodando)
            {
                return;
            }

            var instruction = Instrucoes.FirstOrDefault(i => i.IsValid(this));

            if (instruction == null)
            {
                Stop();
                return;
            }

            EstadoAtual = instruction.SairEstadoInstrucoes;
            Dado.Escreva(instruction.ResultadoInstrucoes);

            switch (instruction.MovimentoInstrucao)
            {
            case TuringMachineInstrucoes.Movement.Left:
                Dado.MoverAnterior();
                break;

            case TuringMachineInstrucoes.Movement.Right:
                Dado.MoverProximo();
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(instruction.MovimentoInstrucao));
            }
        }