public int GetPlayersLongestRoad(int playerID)
{
int highest = 0;
// floodfill from each road segment to see if it constitutes the longest road.
HashSet<Edge> visited = new HashSet<Edge>();
foreach (var road in roads.Where(r => GetRoad(r.Key) == playerID))
{
if (visited.Contains(road.Key)) continue; // already explored
visited.Add(road.Key);
// get ends
Intersection[] ends = this.GetAdjacentIntersections(road.Key);
HashSet<Edge> tempVisited = new HashSet<Edge>();
tempVisited.Add(road.Key);
int first = CountRoadLengthFromIntersection(road.Value, ends[0], tempVisited, visited);
int second = CountRoadLengthFromIntersection(road.Value, ends[1], tempVisited, visited);
int result = first + 1 + second;
if (highest < result)
{
highest = result;
}
}
return highest;
}