Ejemplo n.º 1
0
        public override string[] calculatePath()
        {
            List <string> path = new List <string>();

            while (goalPos.Count > 0)
            {
                Position target   = new Position(-3, -3);
                string[] pathstep = new string[0];
                foreach (Position position in goalPos)
                {
                    if (target.getX() == -3 && target.getY() == -3)
                    {
                        target   = position;
                        pathstep = getPathTo(position);
                        continue;
                    }

                    string[] tmp = getPathTo(position);
                    if (tmp.Length < pathstep.Length)
                    {
                        target   = position;
                        pathstep = tmp;
                    }
                }
                path.AddRange(pathstep);
                agent.reset(target);
                goalPos.Remove(target);
            }
            return(path.ToArray());
        }
Ejemplo n.º 2
0
 public int getDistanceTo(Position target)
 {
     return(Math.Abs((x) - target.getX()) + Math.Abs((y) - target.getY()));
 }