示例#1
0
        private static bool isGoalReachable(CollisionMap Map)
        {
            List <CollisionMapElement> neighboursToCheck = Map.getElement(Map.GoalPosition).getUnblockedNeighbours();
            List <CollisionMapElement> elementList       = new List <CollisionMapElement>();

            //Debug.Log("isGoalReachable");
            while (neighboursToCheck.Except(elementList).Count() > 0)
            {
                CollisionMapElement target = neighboursToCheck[0];
                if (!elementList.Contains(target))
                {
                    elementList.Add(target);
                }

                List <CollisionMapElement> neighbours = target.getUnblockedNeighbours();

                if (
                    neighboursToCheck.Except(neighbours).Count() != 0 &&
                    elementList.Intersect(neighbours).Count() != neighbours.Count()
                    )
                {
                    neighboursToCheck.AddRange(neighbours.Except(neighboursToCheck).ToList());
                }
                neighboursToCheck.Remove(target);
            }
            //Map.printMap();
            //Debug.Log("end isGoalReachable");

            return(elementList.Any(element => element.ElementCoordinate.Equals(Map.CurrentPosition)));
        }
示例#2
0
 public void addNeighbour(CollisionMapElement newNeighbour)
 {
     if (Neighbours == null)
     {
         Neighbours = new List <CollisionMapElement>();
     }
     Neighbours.Add(newNeighbour);
 }