Esempio n. 1
0
        /// <summary>
        /// Generate a Dijkstra Map to aid AI navigation through this map
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="map"></param>
        /// <param name="startingValue"></param>
        /// <param name="targetCondition"></param>
        /// <param name="passCondition"></param>
        /// <param name="blockedValue"></param>
        /// <returns></returns>
        public static ICellMap <int> GenerateDijkstraMap <T>(this ICellMap <T> map, Func <T, bool> targetCondition, Func <T, bool> passCondition,
                                                             int startingValue = 1000000, int blockedValue = -1)
        {
            ICellMap <int> dMap = map.SpawnNewGrid <int>();

            dMap.SetAll(startingValue);
            for (int i = 0; i < map.CellCount; i++)
            {
                T cellValue = map[i];
                if (targetCondition(cellValue))
                {
                    dMap[i] = 0;
                }
                else if (!passCondition(cellValue))
                {
                    dMap[i] = blockedValue;
                }
            }

            while (IterateDijkstraMap(dMap, blockedValue))
            {
            }

            return(dMap);
        }