/// <summary> /// Calls the Tick method of the currently executing nested instruction /// and if necessary advances the PC. /// </summary> /// <param name="critterState">The state of the critter to work on.</param> /// <returns><code>true</code> if more execution steps must be executed /// to finish the instruction execution. <code>false</code> if /// instruction execution has finished.</returns> protected bool InternalTick(CritterState critterState) { if (critterState == null) { throw new ArgumentNullException(nameof(critterState)); } if (this.pc < 0) { throw new IndexOutOfRangeException("PC out of range"); } if (this.pc >= this.instructions.Count) { return(false); } var instr = this.instructions[this.pc]; if (instr.Tick(critterState) == false) { this.pc++; } return(this.pc < this.instructions.Count); }
/// <summary> /// Advances the critter in direction of the destination by <see cref="StepLength"/>. /// </summary> /// <returns><code>false</code> if the critter has arrived at its destination.</returns> public override bool Tick(CritterState critterState) { // calculate difference vector from current pos to dest var pos = new Vector(critterState.PositionX, critterState.PositionY); var dest = new Vector(DestX, DestY); var diff = dest - pos; if (diff.Length < StepLength) { critterState.PositionX = DestX; critterState.PositionY = DestY; return(false); } // normalize diff vector so that length is 1, then multiply it // with StepLength to get the increment vector. var unit = diff.Normalize(); var increment = unit * StepLength; // add increment vector to current pos to get new pos var newPos = pos + increment; critterState.PositionX = newPos.X; critterState.PositionY = newPos.Y; return(true); }
/// <summary> /// See <see cref="Instruction.Tick(CritterState)"/>. /// </summary> public override bool Tick(CritterState critterState) { if (base.InternalTick(critterState) == false) { base.ResetPC(); this.count++; if (this.count >= Repetitions) { this.count = 0; return(false); } } return(true); }
public override bool Tick(CritterState critterState) { return(this.tick(critterState)); }
/// <summary> /// When implemented in a derived class, advances to the next step in /// instruction execution, potentially mutating the passed <see cref="CritterState"/>. /// </summary> /// <param name="critterState">The critter state to work on.</param> /// <returns><code>true</code> if more execution steps must be executed /// to finish the instruction execution. <code>false</code> if /// instruction execution has finished.</returns> public abstract bool Tick(CritterState critterState);
public override bool Tick(CritterState critterState) { return(base.InternalTick(critterState)); }
/// <summary> /// Advances the program by one step, potentially mutating the passed /// <see cref="CritterState"/>. /// </summary> /// <param name="critterState">The state of the critter that is controlled by the program.</param> /// <returns><code>true</code> if the program has more steps to execute. /// <code>false</code> if the program has finished.</returns> public bool Tick(CritterState critterState) { return(this.root.Tick(critterState)); }