Exemple #1
0
 public static void MapTo <TLocationReferenceEntity>(this IHaveLocation haveLocation, IHaveLocationReferenceEntity <TLocationReferenceEntity> entity)
     where TLocationReferenceEntity : class, ILocationReferenceEntity, new()
 {
     if (haveLocation.Location != null)
     {
         if (entity.LocationReferenceEntity == null)
         {
             entity.LocationReferenceEntity = haveLocation.Location.MapTo <TLocationReferenceEntity>();
         }
         else
         {
             haveLocation.Location.MapTo(entity.LocationReferenceEntity);
         }
     }
 }
 public Renderable(IHaveLocation source, char representation, int zindex)
 {
     Source         = source;
     Representation = representation;
     ZIndex         = zindex;
 }
Exemple #3
0
 public static void CheckDeleteLocation <TLocationReferenceEntity>(this IHaveLocationReferenceEntities <TLocationReferenceEntity> haveLocationReferenceEntities, IHaveLocation haveLocation, IHaveLocationReferenceEntity <TLocationReferenceEntity> entity)
     where TLocationReferenceEntity : class, ILocationReferenceEntity
 {
     if (entity.LocationReferenceEntity != null && haveLocation.Location == null)
     {
         haveLocationReferenceEntities.LocationReferenceEntities.DeleteOnSubmit(entity.LocationReferenceEntity);
         entity.LocationReferenceEntity = null;
     }
 }
Exemple #4
0
        public Path CreatePath(Map map, IHaveLocation start, IHaveLocation end)
        {
            PathingMap pathingMap;
            var adjacentPoints = new List<AdjectPoint>
                {
                    new AdjectPoint(1, 1),
                    new AdjectPoint(1, 0),
                    new AdjectPoint(1, -1),
                    new AdjectPoint(0, -1),
                    new AdjectPoint(-1, -1),
                    new AdjectPoint(-1, 0),
                    new AdjectPoint(-1, 1),
                    new AdjectPoint(0, 1)
                };
            var path = new Path();
            var lowestLength = 0;
            for (int i = 0; i < 7; i++)
            {
                pathingMap = BuildPathingMap(map);
                var startingPoint = new PathingPoint { LocX = start.LocX, LocY = start.LocY };
                startingPoint.IsCurrent = true;
                pathingMap.ClosedPoints.Add(startingPoint);
                var chosenPath = new List<PathingPoint>();
                while (startingPoint.LocX != end.LocX || startingPoint.LocY != end.LocY)
                {
                    var currentAdjacentPoints = new List<PathingPoint>();
                    foreach (var adjacentPoint in adjacentPoints)
                    {
                        var point = new PathingPoint
                            {
                                LocX = startingPoint.LocX + adjacentPoint.DeltaX,
                                LocY = startingPoint.LocY + adjacentPoint.DeltaY,
                                ParentX = startingPoint.LocX,
                                ParentY = startingPoint.LocY
                            };

                        if (adjacentPoint.DeltaX == 0 || adjacentPoint.DeltaY == 0)
                            point.GScore = 10;
                        else
                        {
                            point.GScore = 14;
                        }

                        point.HScore = 10 * (Math.Abs(end.LocX - point.LocX) + Math.Abs(end.LocY - point.LocY));

                        var matchedPoint = pathingMap.ClosedPoints.Any(x => x.LocX == point.LocX && x.LocY == point.LocY);
                        if (matchedPoint)
                            continue;

                        currentAdjacentPoints.Add(point);
                        var matchedOpen = pathingMap.OpenPoints.Where(x => x.LocX == point.LocX && x.LocY == point.LocY).ToList();
                        if (matchedOpen.Count > 0)
                        {
                            Console.WriteLine("Matched Open X: {0} Y: {1} F: {2} G: {3} H: {4}", point.LocX, point.LocY,
                                              point.FScore, point.GScore, point.HScore);
                            continue;
                        }

                        pathingMap.OpenPoints.Add(point);

                        Console.WriteLine("Open Adjacents X: {0} Y: {1} F: {2} G: {3} H: {4}", point.LocX, point.LocY,
                                          point.FScore, point.GScore, point.HScore);
                    }

                    startingPoint = currentAdjacentPoints.OrderBy(x => x.FScore).FirstOrDefault();
                    var otherOptions = currentAdjacentPoints.Where(x => x.FScore == startingPoint.FScore).OrderBy(y => y.FScore).ToList();
                    if (i > 0 && otherOptions.Count > i)
                        startingPoint = otherOptions[i];

                    Console.WriteLine("Chosen Point X: {0} Y: {1} F: {2} G: {3} H: {4}", startingPoint.LocX, startingPoint.LocY,
                                      startingPoint.FScore, startingPoint.GScore, startingPoint.HScore);
                    startingPoint.IsCurrent = true;
                    //Remove new current point from open points
                    var originalOpenPoint =
                        pathingMap.OpenPoints.Single(x => x.LocX == startingPoint.LocX && x.LocY == startingPoint.LocY);
                    pathingMap.OpenPoints.Remove(originalOpenPoint);
                    chosenPath.Add(startingPoint);
                    pathingMap.ClosedPoints.ForEach(x => x.IsCurrent = false);
                    pathingMap.ClosedPoints.Add(startingPoint);
                }

                foreach (var thingy in chosenPath)
                {
                    Console.WriteLine("Chosen Point X: {0} Y: {1} F: {2} G: {3} H: {4}", thingy.LocX, thingy.LocY,
                                     thingy.FScore, thingy.GScore, thingy.HScore);
                }
                if (lowestLength == 0 || lowestLength > chosenPath.Count)
                {
                    path = new Path();
                    foreach (var chosenPointInChosenPath in chosenPath)
                    {
                        path.Movements.Add(new Movement
                            {
                                NewX = chosenPointInChosenPath.LocX,
                                NewY = chosenPointInChosenPath.LocY
                            });
                    }

                    lowestLength = chosenPath.Count;
                }
            }

            return path;
        }
Exemple #5
0
 public NotAllCodePathReturnValue(IHaveLocation thing) : this(thing.Location)
 {
 }