本文整理汇总了C#中Route.CalculateALongestRoute方法的典型用法代码示例。如果您正苦于以下问题:C# Route.CalculateALongestRoute方法的具体用法?C# Route.CalculateALongestRoute怎么用?C# Route.CalculateALongestRoute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Route
的用法示例。
在下文中一共展示了Route.CalculateALongestRoute方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CalculateLongestRoad
/// <summary>
/// Recalculates every route in case of a blokage
/// </summary>
/// <param name="town"></param>
/// <param name="player"></param>
public void CalculateLongestRoad(HexPoint town, GamePlayer player)
{
Route current = LongestRoute;
// When we have a current route, check if the new town is part of it
if (current != null)
{
// But only when the player building the town is other then the player owning
// the current route
if (!player.Equals(LongestRouteOwner))
{
// Create a list of hexpoints in current route
List<HexPoint> routePoints = new List<HexPoint>();
// Put all points into the list
foreach (RouteNode node in current)
{
if (!routePoints.Contains(node.GetNeighbourPoints()[0]))
routePoints.Add(node.GetNeighbourPoints()[0]);
if (!routePoints.Contains(node.GetNeighbourPoints()[1]))
routePoints.Add(node.GetNeighbourPoints()[1]);
}
// Check if the town is placed on a hexpoint in the route
if (routePoints.Contains(town))
{
// We have a winner! Nice play. This means given town which is built blocks
// We should iterate over all players, calculating their longest routes.
// If current keeper of the longest route has a new route with length
// equalling length of another player, current keeper keeps his LR.
// However, when two other players both have longest route, no one gets
// the route.
// TODO: make static function call of CalculateALongestRoute
Route phony = new Route();
// Get us some nice new dictionairy to store the calculated routes
Dictionary<GamePlayer, Route> playersRoutes = new Dictionary<GamePlayer, Route>();
// Fill the dictionairy with new routes
foreach (GamePlayer p in _Players)
playersRoutes.Add(p, phony.CalculateALongestRoute(p, this));
// Sweet! Now let's see who is the winner of the routecontest
// First get the longest route of current keeper of LR
Route currentWinnerRoute = playersRoutes[LongestRouteOwner];
// Get the length of the longest route(s)
int newWinnerLength = playersRoutes.Max(kvp => kvp.Value.Count);
Route newRoute = null;
if (currentWinnerRoute.Count == newWinnerLength)
{
// Current keeper of longest route has a new route with the maximum length.
// Therefore, he stays the keeper of the longest route
newRoute = currentWinnerRoute;
}
else
{
// Some other player(s) have a longer route then the previous route, and still longer
// then the longest route of the keeper of the previous route.
// Determine if we have a single player having so. If a single player is found,
// declare him the winner. When multiple players are found, no one gets
// declared winner.
IEnumerable<KeyValuePair<GamePlayer, Route>> winners =
playersRoutes.Where(kvp => kvp.Value.Count == newWinnerLength);
// We have more then one new winners. No one gets LR.
if (winners.Count() > 1)
{
newRoute = null;
}
// Only one new winner
if (winners.Count() == 1)
{
newRoute = winners.First().Value;
}
// Old player lost route, no players with routes > 4
if (winners.Count() == 0)
{
newRoute = null;
}
}
}
}
}
else
//.........这里部分代码省略.........