/// <summary> /// Execute the instruction /// </summary> public override void Execute(IBefungeRunTime befungeRunTime) { int x = befungeRunTime.MaxExtent.x == befungeRunTime.CurrentPosition.x ? 0 : befungeRunTime.CurrentPosition.x + 1; befungeRunTime.CurrentPosition = new CoOrds(x, befungeRunTime.CurrentPosition.y); base.Execute(befungeRunTime); }
/// <summary> /// Execute the instruction /// </summary> public override void Execute(IBefungeRunTime befungeRunTime) { int y = befungeRunTime.MaxExtent.y == befungeRunTime.CurrentPosition.y ? 0 : befungeRunTime.CurrentPosition.y + 1; befungeRunTime.CurrentPosition = new CoOrds(befungeRunTime.CurrentPosition.x, y); base.Execute(befungeRunTime); }
/// <summary> /// Execute the instruction /// </summary> public override void Execute(IBefungeRunTime befungeRunTime) { int a = befungeRunTime.RetrieveLastValue(); befungeRunTime.Output = a.ToString(); base.Execute(befungeRunTime); }
/// <summary> /// Execute the instruction /// </summary> public override void Execute(IBefungeRunTime befungeRunTime) { int val = befungeRunTime.ReviewLastValueOrDefault(0); befungeRunTime.StoreValue(val); base.Execute(befungeRunTime); }
/// <summary> /// Execute the instruction /// </summary> public override void Execute(IBefungeRunTime befungeRunTime) { char val = (char)befungeRunTime.RetrieveLastValue(); befungeRunTime.Output = val.ToString(); base.Execute(befungeRunTime); }
/// <summary> /// Execute the instruction /// </summary> public override void Execute(IBefungeRunTime befungeRunTime) { int val = befungeRunTime.RetrieveLastValue(); befungeRunTime.StoreValue(val == 0 ? 1 : 0); base.Execute(befungeRunTime); }
/// <summary> /// Execute the instruction /// </summary> public override void Execute(IBefungeRunTime befungeRunTime) { Direction[] directions = { MoveDown.Instance, MoveLeft.Instance, MoveRight.Instance, MoveUp.Instance }; int randomIndex = (new Random()).Next(directions.Length); befungeRunTime.CurrentDirection = directions[randomIndex]; base.Execute(befungeRunTime); }
/// <summary> /// Execute the instruction /// </summary> public override void Execute(IBefungeRunTime befungeRunTime) { IMode numberMode = NumberMode.Instance; IMode stringMode = StringMode.Instance; befungeRunTime.CurrentMode = (befungeRunTime.CurrentMode.IsNumberMode) ? stringMode : numberMode; base.Execute(befungeRunTime); }
/// <summary> /// Execute the instruction /// </summary> public override void Execute(IBefungeRunTime befungeRunTime) { int a = befungeRunTime.RetrieveLastValue(); int b = befungeRunTime.RetrieveLastValue(); befungeRunTime.StoreValue(a + b); base.Execute(befungeRunTime); }
/// <summary> /// Execute the instruction /// </summary> public override void Execute(IBefungeRunTime befungeRunTime) { int y = befungeRunTime.RetrieveLastValue(); int x = befungeRunTime.RetrieveLastValue(); int val = (int)befungeRunTime.GetValue(new CoOrds(x, y)); befungeRunTime.StoreValue(val); base.Execute(befungeRunTime); }
/// <summary> /// Execute the instruction /// </summary> public override void Execute(IBefungeRunTime befungeRunTime) { int y = befungeRunTime.RetrieveLastValue(); int x = befungeRunTime.RetrieveLastValue(); char v = (char)befungeRunTime.RetrieveLastValue(); befungeRunTime.PutValue(new CoOrds(x, y), v); base.Execute(befungeRunTime); }
/// <summary> /// Execute the current instruction /// </summary> public void ExecuteInstruction(IBefungeRunTime runTime) { IInstruction currentInstruction = _defaultInstruction; if (_instructionsLookup.ContainsKey(runTime.CurrentInstruction)) { _instructionsLookup.TryGetValue(runTime.CurrentInstruction, out currentInstruction); } currentInstruction.Execute(runTime); }
/// <summary> /// Execute the instruction /// </summary> public override void Execute(IBefungeRunTime befungeRunTime) { int val = befungeRunTime.RetrieveLastValue(); Direction moveDown = MoveDown.Instance; Direction moveUp = MoveUp.Instance; befungeRunTime.CurrentDirection = val == 0 ? moveDown : moveUp; base.Execute(befungeRunTime); }
/// <summary> /// Execute the instruction /// </summary> public override void Execute(IBefungeRunTime befungeRunTime) { int val = befungeRunTime.RetrieveLastValue(); Direction moveRight = MoveRight.Instance; Direction moveLeft = MoveLeft.Instance; befungeRunTime.CurrentDirection = val == 0 ? moveRight : moveLeft; base.Execute(befungeRunTime); }
/// <summary> /// Execute the instruction /// </summary> public override void Execute(IBefungeRunTime befungeRunTime) { int value; string input = ""; while (!Int32.TryParse(input, out value)) { input = befungeRunTime.Input("Please supply an Integer:"); } befungeRunTime.StoreValue(value); base.Execute(befungeRunTime); }
/// <summary> /// Execute the instruction /// </summary> public override void Execute(IBefungeRunTime befungeRunTime) { string input = ""; while (input.Length == 0) { input = befungeRunTime.Input("Please supply a Character:"); } // take the first character and get the ASCII value int ASCIIvalue = (int)input[0]; befungeRunTime.StoreValue(ASCIIvalue); base.Execute(befungeRunTime); }
/// <summary> /// Execute the instruction /// </summary> /// <exception cref="UnsupportedInstructionException">Thrown when an unknown instruction is encountered</exception> public override void Execute(IBefungeRunTime befungeRunTime) { int value; if (Int32.TryParse(befungeRunTime.CurrentInstruction.ToString(), out value)) { befungeRunTime.StoreValue(value); } else { string message = $"Unsupported Instruction: {befungeRunTime.CurrentInstruction.ToString()}."; Console.WriteLine(message); throw new UnsupportedInstructionException(message); } base.Execute(befungeRunTime); }
/// <summary> /// Execute the instruction /// </summary> public override void Execute(IBefungeRunTime befungeRunTime) { befungeRunTime.EndProgram = true; base.Execute(befungeRunTime); }
/// <summary> /// Execute the current instruction /// </summary> public void ExecuteInstruction(IBefungeRunTime runTime) { IInstruction currentInstruction = runTime.CurrentInstruction == '"' ? _toggleStringMode : _defaultInstruction; currentInstruction.Execute(runTime); }
/// <summary> /// Execute the instruction /// </summary> public override void Execute(IBefungeRunTime befungeRunTime) { befungeRunTime.CurrentDirection.Execute(befungeRunTime); base.Execute(befungeRunTime); }
/// <summary> /// Execute the instruction /// </summary> public virtual void Execute(IBefungeRunTime befungeRunTime) { // Move in the current direction befungeRunTime.CurrentDirection.Execute(befungeRunTime); }
/// <summary> /// Execute the instruction /// </summary> public override void Execute(IBefungeRunTime befungeRunTime) { befungeRunTime.StoreValue((int)befungeRunTime.CurrentInstruction); base.Execute(befungeRunTime); }
/// <summary> /// Execute the instruction /// </summary> public virtual void Execute(IBefungeRunTime befungeRunTime) { befungeRunTime.CurrentDirection = this; befungeRunTime.ReadInstruction(); }