private Point[] FindPath(Point start, Point goal, Dictionary <Point, int> visitedPlaces) { Point[] foundedPath = pathFindDelegete(start, goal, visitedPlaces); if (foundedPath == null) { return(null); } else { #if false Console.WriteLine($"HP - {currentHP}"); Console.WriteLine($"Points - {foundedPath.Count()}"); ShowPathToConsole(foundedPath); Console.WriteLine(); #endif bool isTherePlacesLessMax = false; #if false foreach (var item in visitedPlaces) { Console.Write(item.Key + " - " + item.Value + " " + map.ReturnObject(item.Key) + " "); if (visitedPlaces.ContainsKey(item.Key)) { Console.WriteLine(true); } } Console.WriteLine(); #endif foreach (int value in visitedPlaces.Values) { if (value <= MAX_STEPS_PER_PLACE) { isTherePlacesLessMax = true; break; } } if (!isTherePlacesLessMax) { return(null); } int tempHP = currentHP; if (!TakeDamageFromPath(foundedPath)) { return(foundedPath); } else { //If died in the founded way - restore HP and try again considering the visited places. currentHP = tempHP; pathFindDelegete = FindPathBread; return(FindPath(start, goal, visitedPlaces)); } } }
/// <summary> /// Uses A* algorithm, checking for doors and trying to pass through fire. /// </summary> /// <param name="start">Start point to start searching.</param> /// <param name="goal">Goal of the algorithm</param> /// <returns>Returns shortest way to the goal, else null if there is no way.</returns> private Point[] FindPath(Point start, Point goal) { //Used for keeping of number of times that character step on a place. Dictionary <Point, int> visitedPlaces = new Dictionary <Point, int>(); ScanWalkAbleTerritory(start, visitedPlaces); pathFindDelegete = FindPathA; return(FindPath(start, goal, visitedPlaces)); }