示例#1
0
        public IHex GetNW(IHex t)
        {
            int col = -1;
            int row = -1;

            if (t.GetCol() % 2 == 0)
            {
                col = t.GetCol() - 1;
                row = t.GetRow() - 1;
            }
            else
            {
                col = t.GetCol() - 1;
                row = t.GetRow();
            }
            return(GetDirectionalTile(col, row));
        }
示例#2
0
        private GetPathDataClass GetPathHelperData(IHex t)
        {
            var data = new GetPathDataClass();

            data.OpenSet = new List <IHex>()
            {
                t
            };
            data.ClosedSet       = new List <Pair <int, int> >();
            data.InitPath        = new Path();
            data.PathsToGoal     = new List <Path>();
            data.PathsToGoalDict = new Dictionary <Pair <int, int>, Path>();
            data.PathsToGoalDict.Add(new Pair <int, int>(t.GetCol(), t.GetRow()), data.InitPath);
            return(data);
        }
示例#3
0
        public Path GetBruteForcePathViaFiniteSet(List <IHex> set, IHex s, IHex g, IPathable navigator)
        {
            var validPaths = new List <Path>();
            var openSet    = new List <IHex>()
            {
                s
            };

            foreach (var tile in set)
            {
                if (!tile.Equals(s))
                {
                    openSet.Add(tile);
                }
            }
            bool found     = false;
            var  pathDict  = new Dictionary <Pair <int, int>, Path>();
            var  closedSet = new List <Pair <int, int> >();
            var  initPath  = new Path();

            initPath.AddTile(s, navigator);
            pathDict.Add(new Pair <int, int>(s.GetCol(), s.GetRow()), initPath);

            while (openSet.Count > 0 && !found)
            {
                var tile = openSet.ElementAt(0);
                foreach (var neighbor in tile.GetAdjacent())
                {
                    var neighborKey = new Pair <int, int>(neighbor.GetCol(), neighbor.GetRow());
                    if (neighbor.GetCurrentOccupant() == null)
                    {
                        var innerKey     = new Pair <int, int>(tile.GetCol(), tile.GetRow());
                        var previousPath = pathDict[innerKey];
                        var newPath      = previousPath.DeepCopy();
                        newPath.AddTile(neighbor, navigator);
                        var newKey = new Pair <int, int>(neighbor.GetCol(), neighbor.GetRow());
                        if (!pathDict.ContainsKey(newKey))
                        {
                            pathDict.Add(newKey, newPath);
                        }
                        else
                        {
                            if (newPath.Score < pathDict[newKey].Score)
                            {
                                pathDict[newKey] = newPath;
                            }
                        }
                        if (neighbor == g)
                        {
                            validPaths.Add(newPath);
                            found = true;
                        }
                    }
                    else
                    {
                        closedSet.Add(neighborKey);
                    }
                }
                closedSet.Add(new Pair <int, int>(tile.GetCol(), tile.GetRow()));
                openSet.Remove(tile);
            }

            if (validPaths.Count > 0)
            {
                var bestPath = validPaths.OrderBy(x => x.Score).ToList()[0];
                return(bestPath);
            }
            else
            {
                return(initPath);
            }
        }
示例#4
0
 public IHex GetN(IHex t)
 {
     return(GetDirectionalTile(t.GetCol(), t.GetRow() - 1));
 }