bool WeightedDeepSearchInnerCycle(Vertex currentVertex, Vertex targetVertex, Being being, int currentDepth, int maxDepth, List <Path> pathes, Path tempPath) { var failCount = 0; while (failCount < failsCount) { foreach (var vertex in currentVertex.LinkedVertices) { bool isNotPrevious = true; foreach (var vert in tempPath.Vertices) { if (vert.Equals(vertex)) { isNotPrevious = false; break; } } if (vertex.Equals(targetVertex) && isNotPrevious) { tempPath.Vertices.Add(vertex); tempPath.PathCost = being.GetPointCost( GetPointType(vertex, tempPath.Vertices.ToArray()[tempPath.Vertices.IndexOf(vertex)])); foreach (var path in pathes) { if (tempPath.Equals(path)) { tempPath.Vertices.Remove(vertex); return(false); } } return(true); } else if (currentDepth < maxDepth && IsVertexTypeGood(vertex, being.Type) && isNotPrevious) { tempPath.Vertices.Add(vertex); if (WeightedDeepSearchInnerCycle(vertex, targetVertex, being, currentDepth + 1, maxDepth, pathes, tempPath)) { if (tempPath.Vertices.IndexOf(vertex) > 0) { tempPath.PathCost += being.GetPointCost( GetPointType(vertex, tempPath.Vertices.ToArray()[tempPath.Vertices.IndexOf(vertex) - 1])); } return(true); } else { tempPath.Vertices.Remove(vertex); } } //else if (!isNotPrevious) //{ // continue; //} } failCount++; } return(false); }