Exemplo n.º 1
0
        private bool FindPathAdj(Cell cellSrc, Cell cellDest, CellPartEnum startingDirection,
            bool ignoreDestCharacter, bool ignoreObstacle, bool useStraightAngle,
            out List<ArrayList> shortestPathAvoids, out bool hasObstacle)
        {
            shortestPathAvoids = new List<ArrayList>();
            hasObstacle = false;

            // source is destination
            if (cellSrc.Equals(cellDest)) return true;

            // destination cannot has character or obstacle
            if (!cellDest.HasPassability())
            {
                if (!ignoreDestCharacter && !ignoreObstacle) return false;
            }

            // find direct path (shortest path)
            ArrayList directPath = new ArrayList();
            if (!FindPath(cellSrc, cellDest, directPath, startingDirection,
                true, true, true, useStraightAngle)) return false;

            // find all adjacent cells for obstacle
            ArrayList adjCells = new ArrayList();
            ArrayList obsCells = new ArrayList();
            GetAdjCells(directPath, cellDest, ignoreDestCharacter, adjCells, obsCells);

            // if no obstacles
            if (obsCells.Count < 1)
            {
                hasObstacle = false;
                shortestPathAvoids.Add(directPath);
                return true;
            }
            else
            {
                hasObstacle = true;
            }

            // find new path
            List<ArrayList> pathAvoids = null;
            FindPathAvoid(directPath, adjCells, obsCells, cellDest, out pathAvoids);

            if (pathAvoids.Count < 1) return false;

            // get shortest avoid path (might be many)
            FindShortestPathAvoid(pathAvoids, out shortestPathAvoids);

            if (shortestPathAvoids.Count < 1) return false;

            return true;
        }
Exemplo n.º 2
0
        private bool FindPath_Good(Cell cellNext, Cell cellDest, CellPartEnum direction, ArrayList path, ArrayList deadPath,
            bool ignoreDestCharacter, bool ignoreObstacle, bool useStraightAngle)
        {
            //Debug.WriteLine(string.Format("Accept cell {0},{1}", cellNext._row, cellNext._col));
            path.Add(cellNext);

            if (cellNext.Equals(cellDest))
            {
                // end
                //Debug.WriteLine("Reach Destination");
                return true;
            }

            if (useStraightAngle)
                direction = CellPartEnum.Center;
            else
            {
                // change direction if has whole/direct angle
                double degree = FindDegree(cellNext.GetCenterPoint(), cellDest.GetCenterPoint());
                if (Math.Abs(degree) <= 0.05)
                    direction = CellPartEnum.CenterRight;
                else if (Math.Abs(degree - DIGONAL_ANGLE) <= 0.05)
                    direction = CellPartEnum.LowerRight;
                else if (Math.Abs(degree - (180 - DIGONAL_ANGLE)) <= 0.05)
                    direction = CellPartEnum.LowerLeft;
                else if (Math.Abs(degree - 180) <= 0.05)
                    direction = CellPartEnum.CenterLeft;
                else if (Math.Abs(degree - (180 + DIGONAL_ANGLE)) <= 0.05)
                    direction = CellPartEnum.UpperLeft;
                else if (Math.Abs(degree - (360 - DIGONAL_ANGLE)) <= 0.05)
                    direction = CellPartEnum.UpperRight;
            }

            return FindPath_Sub(cellNext, cellDest, path, direction, deadPath,
                ignoreDestCharacter, ignoreObstacle, useStraightAngle);
        }
Exemplo n.º 3
0
        public bool FindPath(Cell cellSrc, Cell cellDest, ArrayList path, CellPartEnum startingDirection,
            bool ignoreDestCharacter, bool ignoreObstacle, bool includeSrcCell, bool useStraightAngle)
        {
            if (includeSrcCell) path.Add(cellSrc);

            if (cellSrc.Equals(cellDest))
            {
                // end
                return true;
            }

            //CellPartEnum direction = FindDirection(cellSrc.GetCenterPoint(), cellDest.GetCenterPoint());
            CellPartEnum direction = startingDirection;
            Debug.WriteLine("--------------------------------------");
            Debug.WriteLine(string.Format("Start to find at {0}", direction));

            // detect unless cell
            ArrayList deadPath = new ArrayList();
            return FindPath_Sub(cellSrc, cellDest, path, direction, deadPath,
                ignoreDestCharacter, ignoreObstacle, useStraightAngle);
        }