public Vector3[] GetWorldRegion(Cell node)
 {
     throw new NotImplementedException();
 }
 public bool CanOccupy(Cell target)
 {
     return (target.Info is Impassable && target.Info is Empty);
 }
 public IList<Cell> GetNeighbors(Cell node, object agent)
 {
     throw new NotImplementedException();
 }
        public IList<Cell> GetNeighbors(Cell node, IGridTraversalStrategy agent)
        {
            IList<Cell> neighbors = new List<Cell>();//GraphDirection.Offsets.Length);
            if (agent != null && agent.Grid != Grid)
                agent.Grid = Grid;
            for (int i = 1; i < GridDirectionExtentions.Offsets.Length - 1; i++)
            {
                if (Grid.Contains(node + GridDirectionExtentions.Offsets[i]))
                {
                    Cell neighbor = Grid[node + GridDirectionExtentions.Offsets[i]];
                    //if (!Contains(neighbor))
                    //    continue;

                    if (agent != null && !agent.CanMakeStep(node, neighbor))
                        continue;

                    neighbors.Add(neighbor);
                }

            }
            return neighbors;
        }
 public bool Contains(Cell node)
 {
     return Contains((int)node.X, (int)node.Y, (int)node.Z); //(node.X >= 0 && node.X < _x && node.Y >= 0 && node.Y < _y && node.Z >= 0 && node.Z < _z);
 }
 public double GetManhettenDistance(Cell source, Cell target)
 {
     throw new NotImplementedException();
 }
 public CellEdge(Cell from, Cell to, INodeInfo info)
 {
     From = from;
     To = to;
     Info = info;
 }
 public bool IsNearTarget(Cell source, Cell target, double distance)
 {
     return (distance.AlmostEquals(0, 0));
 }
        public IList<Cell> GetNeighbors(Cell node, Object agent)
        {
            if(!(agent is ITraversalStrategy<Cell>))
                throw new ArgumentException(String.Format(Strings.ArgumentTypeMismatch, typeof(IGridTraversalStrategy)));

            //if (!(agent is IGridMovementAlgorithm))
            //    throw new ArgumentException(String.Format(Strings.ArgumentTypeMismatch, typeof(IGridMovementAlgorithm)));

            return GetNeighbors(node, (IGridTraversalStrategy)agent);
        }
Example #10
0
 public Vector3 GetWorldLocation(Cell node)
 {
     //throw new NotImplementedException();
     return GetWorldLocation((Vector3)node);
 }
Example #11
0
 public IList<Cell> GetNeighbors(Cell node)
 {
     return GetNeighbors(node, null);
 }
Example #12
0
        public double GetManhettenDistance(Cell source, Cell target)
        {
            Vector3 t = GetWorldLocation(target);
            Vector3 s = GetWorldLocation(source);

            return (Math.Abs(t.X - s.X) + Math.Abs(t.Y - s.Y) + Math.Abs(t.Z - s.Z));
        }
Example #13
0
        /// <summary>
        /// Creates new grid of specefic size
        /// </summary>
        /// <param name="sizeX">X size parameter</param>
        /// <param name="sizeY">Y size parameter</param>
        /// <param name="sizeZ">Z size parameter</param>
        public void Create(int sizeX, int sizeY, int sizeZ, Cell3D polygon, INodeInfo fill = null)
        {
            SizeX = sizeX;
            SizeY = sizeY;
            SizeZ = sizeZ;
            Nodes = new ArrayEx<Cell>(new int[] { SizeX, SizeY, SizeZ });

            for (int k = 0; k < SizeZ; k++)
            {
                for (int j = 0; j < SizeY; j++)
                {
                    for (int i = 0; i < SizeX; i++)
                    {
                        //_nodes[i, j, k] = new Node3D<T>(i * Polygon.Bounds.SizeX, j * Polygon.Bounds.SizeY, k * Polygon.Bounds.SizeZ, Polygon);
                        Nodes[i, j, k] = new Cell(i, j, k, Polygon, this, fill);
                    }
                }
            }
        }
 /// <summary>
 /// Determines whether the agent can pass through target node or not
 /// </summary>
 /// <param name="target">Target node</param>
 /// <returns>True, if the agent can pass through the node</returns>
 public bool CanPass(Cell target)
 {
     return (target.Info is Passable || target.Info is Ladder);
 }
        /// <summary>
        /// Provides access to the nodes storage.
        /// </summary>
        /// <param name="x">Coordinate X</param>
        /// <param name="y">Coordinate Y</param>
        /// <param name="z">Coordinate Z</param>
        /// <returns>A node described by three coordinates.</returns>
        //public Cell this[int x, int y, int z]
        //{
        //    get
        //    {
        //        if (x < 0 && x >= SizeX)
        //        {
        //            string message = String.Format(CultureInfo.CurrentCulture, Strings.ArgumentGreaterAndLess, SizeX, 0);
        //            throw new ArgumentOutOfRangeException("x", message);
        //        }
        //        if (y < 0 && y >= SizeY)
        //        {
        //            string message = String.Format(CultureInfo.CurrentCulture, Strings.ArgumentGreaterAndLess, SizeY, 0);
        //            throw new ArgumentOutOfRangeException("y", message);
        //        }
        //        if (z < 0 && z >= SizeZ)
        //        {
        //            string message = String.Format(CultureInfo.CurrentCulture, Strings.ArgumentGreaterAndLess, SizeZ, 0);
        //            throw new ArgumentOutOfRangeException("z", message);
        //        }
        //        return Nodes[x, y, z];
        //    }
        //    set
        //    {
        //        Nodes[x, y, z] = value;
        //    }
        //}
        public Cell this[Cell v]
        {
            get
            {
                if (v.X < 0 && v.X > SizeX)
                {
                    string message = String.Format(CultureInfo.CurrentCulture, Strings.ArgumentGreaterAndLess, 0, SizeX);
                    throw new ArgumentOutOfRangeException("x", message);
                }
                if (v.Y < 0 && v.Y > SizeY)
                {
                    string message = String.Format(CultureInfo.CurrentCulture, Strings.ArgumentGreaterAndLess, 0, SizeY);
                    throw new ArgumentOutOfRangeException("y", message);
                }
                if (v.Z < 0 && v.Z > SizeZ)
                {
                    string message = String.Format(CultureInfo.CurrentCulture, Strings.ArgumentGreaterAndLess, 0, SizeZ);
                    throw new ArgumentOutOfRangeException("z", message);
                }
                return Nodes[v];
            }

            set
            {

                Nodes[v] = (PathNodeCell)value;
            }
        }
        public double GetStepCost(Cell source, Cell target)
        {
            int cost;
            cost = 5;

            if (target.Info is Passable)
                cost = 5;
            else if (target.Info is Ladder)
                cost = 6;

            //switch (Nodes[target].Info.GetType())
            //{
            //    case CellType.Passable:
            //        cost = 5;
            //        break;
            //    case CellType.Ladder:
            //        cost = 6;
            //        break;
            //    default:
            //        cost = 5;
            //        break;
            //}
            if(GridDirectionExtentions.IsDiagonal(target - source))
            {
                cost = (int)(cost * 1.4);
            }
            return cost;
        }
 public bool Contains(Cell node)
 {
     if (Nodes.ContainsValue((PathNodeCell)node))
     {
         return true;
     }
     else
     {
         return false;
     }
 }
        public bool CanMakeStep(Cell source, Cell target)
        {
            //if (target.X.AlmostEquals(2) && target.Y.AlmostEquals(2) && target.Z.AlmostEquals(0))
            //{
            //    Debug.Write(target);
            //}

            CellEdge edge;// = Grid.Edges[source, target];
            Grid.Edges.TryGetValue(source, target, out edge);
            //if ((target.X == 1 && target.Y == 4 && target.Z == 0) && (source.X == 1 && source.Y == 3 && source.Z == 0))
            //{
            //    Debug.Print("Stop");
            //}

            if (!CanPass(target) || ((edge != null) && !(edge.Info is Passable || edge.Info is Empty)))
                return false;
            Vector3 dirOffset, horOffset, wertOffset;
            horOffset = target - source;
            wertOffset = target - source;
            dirOffset = target - source;
            dirOffset.Z = 0;

            if (GridDirectionExtentions.IsDiagonal(dirOffset))
            {
                horOffset.Y = 0;
                wertOffset.X = 0;

                bool hor;
                if(((Grid3D)Grid).Contains(source + horOffset))
                {
                    //if(((Grid3D) Grid)[source + horOffset].Info is Empty)
                    //{
                    //    Debug.Write(target + "is empty");
                    //}

                    hor = ((Grid3D) Grid)[source + horOffset].Info is Passable;
                }
                else
                {
                    hor = true;
                }

                bool wert;
                if (((Grid3D)Grid).Contains(source + wertOffset))
                {
                    //if (((Grid3D)Grid)[source + wertOffset].Info is Empty)
                    //{
                    //    Debug.Write(target + "is empty");
                    //}

                    wert = ((Grid3D)Grid)[source + wertOffset].Info is Passable;
                }
                else
                {
                    wert = true;
                }

                if (!(hor && wert && CanPass(target)))
                {
                    return false;
                }
                //return (hor && wert && CanMakeStep(source, target));
            }
            //else
            //{
            //    if (!(CanPass(target)))
            //        return false;
            //}

            if (target.Info is Ladder)
            {
                Vector3 p = (target - source);
                p.Z = 0;
                if (!(source.Info is Ladder))
                {
                    //bool invalidDirection1 = (p.GetDirection() != ((Ladder) target.Info).Direction);
                    //bool invalidDirection2 = (p.GetDirection() != ((Ladder) target.Info).Direction.Opposite());
                    if (target.Z != source.Z || !p.AsDirection().IsColinear(((Ladder)target.Info).Direction))
                    {
                        return false;
                    }
                }
                else
                {
                    if (p.AsDirection() != ((Ladder)target.Info).Direction && p.AsDirection() != ((Ladder)target.Info).Direction.Opposite())
                    {
                        return false;
                    }
                }
            }
            else
            {
                if (target.Z != source.Z)
                {
                    return false;
                }

                if (source.Info is Ladder)
                {
                    Vector3 p = (target - source);
                    if (!p.AsDirection().IsColinear(((Ladder)source.Info).Direction))
                    {
                        return false;
                    }
                }

            }
            return true;
        }
Example #19
0
        public CellsNeighboringState IsNeighborTo(Cell second)
        {
            Vector3 crd = this - second;

            if(crd.X == 0 && crd.Y == 0 && crd.Z == 0)
                return CellsNeighboringState.Same;

            bool CrdXInRange = crd.X >= -1 && crd.X <= 1;
            bool CrdYInRange = crd.Y >= -1 && crd.Y <= 1;
            bool CrdZInRange = crd.Z >= -1 && crd.Z <= 1;

            if (CrdXInRange && CrdYInRange && CrdZInRange)
                return CellsNeighboringState.Neighbors;

            return CellsNeighboringState.NonNeighbors;
        }