Beispiel #1
0
        private void AddLowestHeuristicToClosedListFromOpenList(int _destinationX, int _destinationY)
        {
            PathfinderTile bestTile = openList[0];

            foreach (PathfinderTile currentTile in openList)
            {
                if (currentTile.GetEstimationCostToDestination(_destinationX, _destinationY) < bestTile.GetEstimationCostToDestination(_destinationX, _destinationY))
                {
                    bestTile = currentTile;
                }
            }

            closedList.Add(bestTile);
        }
Beispiel #2
0
        public Pathfinder(GameState _gameInfo)
        {
            gameInfo = _gameInfo;
            int sizeX = gameInfo.board.GetLength(0);
            int sizeY = gameInfo.board.GetLength(0);

            globalMap = new PathfinderTile[sizeX, sizeY];

            //Initialise pathfinding board
            for (int i = 0; i < gameInfo.board.GetLength(0); ++i)
            {
                for (int j = 0; j < gameInfo.board.GetLength(0); ++j)
                {
                    globalMap[i, j] = new PathfinderTile(i, j, gameInfo.board[i][j]);
                }
            }
        }
Beispiel #3
0
        public Pathfinder(GameState _gameInfo)
        {
            gameInfo = _gameInfo;
            int sizeX = gameInfo.board.GetLength(0);
            int sizeY = gameInfo.board.GetLength(0);

            globalMap = new PathfinderTile[sizeX, sizeY];

            //Initialise pathfinding board
            for (int i = 0; i < gameInfo.board.GetLength(0); ++i)
            {
                for (int j = 0; j < gameInfo.board.GetLength(0); ++j)
                {
                    globalMap[i, j] = new PathfinderTile(i, j, gameInfo.board[i][j]);
                }
            }
        }
Beispiel #4
0
        private bool AddSpecificTileToOpenListIfValid(int _x, int _y, PathfinderTile tile)
        {
            if (_x >= 0 && _y >= 0)
            {
                if (_x < gameInfo.board.GetLength(0) && _y < gameInfo.board.GetLength(0))
                {
                    if (globalMap[_x, _y].IsTraversable(gameInfo.myHero.life, gameInfo.myHero.id) || globalMap[_x, _y] == tile)
                    {
                        if (!closedList.Contains(globalMap[_x, _y]) && !openList.Contains(globalMap[_x, _y]))
                        {
                            openList.Add(globalMap[_x, _y]);
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Beispiel #5
0
        private void AddSurroundingTilesToOpenList(int _x, int _y, PathfinderTile tile)
        {
            if (AddSpecificTileToOpenListIfValid(_x - 1, _y, tile))
            {
                openList[openList.Count - 1].parent = globalMap[_x, _y];
            }

            if (AddSpecificTileToOpenListIfValid(_x + 1, _y, tile))
            {
                openList[openList.Count - 1].parent = globalMap[_x, _y];
            }

            if (AddSpecificTileToOpenListIfValid(_x, _y - 1, tile))
            {
                openList[openList.Count - 1].parent = globalMap[_x, _y];
            }

            if (AddSpecificTileToOpenListIfValid(_x, _y + 1, tile))
            {
                openList[openList.Count - 1].parent = globalMap[_x, _y];
            }
        }
Beispiel #6
0
        private bool AddSpecificTileToOpenListIfValid(int _x, int _y, PathfinderTile tile)
        {
            if (_x >= 0 && _y >= 0)
            {
                if (_x < gameInfo.board.GetLength(0) && _y < gameInfo.board.GetLength(0))
                {
                    if (globalMap[_x, _y].IsTraversable(gameInfo.myHero.life, gameInfo.myHero.id) || globalMap[_x, _y]== tile)
                    {
                        if (!closedList.Contains(globalMap[_x, _y]) && !openList.Contains(globalMap[_x, _y]))
                        {
                            openList.Add(globalMap[_x, _y]);
                            return true;
                        }
                    }
                }
            }

            return false;
        }
Beispiel #7
0
        private void AddSurroundingTilesToOpenList(int _x, int _y, PathfinderTile tile)
        {
            if (AddSpecificTileToOpenListIfValid(_x - 1, _y,tile))
                openList[openList.Count - 1].parent = globalMap[_x, _y];

            if (AddSpecificTileToOpenListIfValid(_x + 1, _y, tile))
                openList[openList.Count - 1].parent = globalMap[_x, _y];

            if (AddSpecificTileToOpenListIfValid(_x, _y - 1, tile))
                openList[openList.Count - 1].parent = globalMap[_x, _y];

            if (AddSpecificTileToOpenListIfValid(_x, _y + 1, tile))
                openList[openList.Count - 1].parent = globalMap[_x, _y];
        }