当前位置: 首页>>代码示例>>C#>>正文


C# Route.CalculateALongestRoute方法代码示例

本文整理汇总了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
//.........这里部分代码省略.........
开发者ID:generateui,项目名称:SettleIn,代码行数:101,代码来源:XmlGame.cs


注:本文中的Route.CalculateALongestRoute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。