/// <summary> /// Optimizes an instruction set by combining similar movement instructions. /// </summary> public IEnumerable<MovementInstruction> Optimize(IEnumerable<MovementInstruction> instructions) { MovementInstruction currentInstruction = new MovementInstruction(MovementDirection.None, 0); foreach(var newInstruction in instructions) { if (newInstruction.Direction == currentInstruction.Direction) { currentInstruction = currentInstruction.IncrementDistance(newInstruction.Distance); } else { if (currentInstruction.Direction != MovementDirection.None) { yield return currentInstruction; } currentInstruction = newInstruction; } } yield return currentInstruction; }
public InstructionSentEventArgs(MovementInstruction instruction, int instructionNumber, int instructionCount) { this.Instruction = instruction; this.InstructionNumber = instructionNumber; this.InstructionCount = instructionCount; }