Exemple #1
0
        /// <summary>
        /// Signals the <see cref="Robot"/> to start moving.
        /// </summary>
        /// <param name="grid">The <see cref="IGrid"/> to traverse.</param>
        public void Traverse(IGrid grid)
        {
            Contract.Requires(grid != null);
            Contract.Ensures(this.FinishPosition != null);

            foreach (var instruction in this.instructions)
            {
                var newPosition = instruction.TransformPosition(this.currentPosition);

                var moveResult = grid.Move(this.currentPosition, newPosition);

                if (moveResult == RobotFeedback.Lost)
                {
                    this.FinishPosition = this.currentPosition;
                    this.Lost = true;
                    return;
                }
                else if (moveResult == RobotFeedback.Safe)
                {
                    this.currentPosition = newPosition;
                }
            }

            this.FinishPosition = this.currentPosition;
        }