Example #1
0
        /// <summary>
        /// Calculates the steps it takes to move from start to target.
        /// </summary>
        /// <param name="start"> The start location. </param>
        /// <param name="target"> The target location. </param>
        /// <returns>
        /// The amount of steps it takes.
        /// </returns>
        private static int CostEstimate(Vector start, Vector target)
        {
            var temp = new Vector(start.X, start.Y);
            var cost = 0;

            while (!temp.Equals(target))
            {
                if (temp.X > target.X)
                {
                    temp = new Vector(temp.X - 1, temp.Y);
                    cost++;
                }
                else if (temp.X < target.X)
                {
                    temp = new Vector(temp.X + 1, temp.Y);
                    cost++;
                }

                if (temp.Y > target.Y)
                {
                    temp = new Vector(temp.X, temp.Y - 1);
                    cost++;
                }
                else if (temp.Y < target.Y)
                {
                    temp = new Vector(temp.X, temp.Y + 1);
                    cost++;
                }
            }

            return cost;
        }