private int GetLongestLink(IEdge currentEdge, IVertex useVertex, HashSet<IEdge> visitedEdges) { if (visitedEdges.Contains(currentEdge)) { return 0; // if already visited } if (useVertex.Campus != null && useVertex.Campus.Color != Color) { return 1; // if other player's campus is in the way } visitedEdges.Add(currentEdge); int max = 0; foreach (IEdge edge in currentEdge.GetAdjacentEdgesSharedWith(useVertex)) { if (edge.Color != Color) continue; // use the vertex on the other side of the edge int path = GetLongestLink(edge, edge.Adjacent.Vertices.First(v => v != useVertex), visitedEdges); if (max < path) { max = path; } } visitedEdges.Remove(currentEdge); return max + 1; }