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


C# GameState.HuntersClosestTo方法代码示例

本文整理汇总了C#中FuryOfDracula.GameLogic.GameState.HuntersClosestTo方法的典型用法代码示例。如果您正苦于以下问题:C# GameState.HuntersClosestTo方法的具体用法?C# GameState.HuntersClosestTo怎么用?C# GameState.HuntersClosestTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FuryOfDracula.GameLogic.GameState的用法示例。


在下文中一共展示了GameState.HuntersClosestTo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ChooseSetupForRoadBlock

        private Location ChooseSetupForRoadBlock(GameState game, out Location roadBlock2, out ConnectionType roadBlockType)
        {
            // if agressive, block nearest hunter's retreat
            if (Strategy == Strategy.Aggressive)
            {
                // choose the closest hunter, or a random one of the closest ones
                List<HunterPlayer> closestHunters = game.HuntersClosestTo(game.Dracula.CurrentLocation);
                HunterPlayer target = closestHunters[new Random().Next(0, closestHunters.Count())];

                // choose a location connected to that hunter's location by road that is further away from dracula than their current location
                List<Location> connectedLocations = game.Map.LocationsConnectedByRoadTo(target.CurrentLocation);
                List<int> distances = new List<int>();
                int longestDistance = 0;
                foreach (Location location in connectedLocations)
                {
                    distances.Add(game.DistanceByRoadOrSeaBetween(location, game.Dracula.CurrentLocation, false));
                    if (distances.Last() > longestDistance)
                    {
                        longestDistance = distances.Last();
                    }
                }
                List<Location> shortlist = new List<Location>();
                int index = -1;
                foreach (int dist in distances)
                {
                    index++;
                    if (dist == longestDistance)
                    {
                        shortlist.Add(connectedLocations[index]);
                    }
                }

                // put the roadblock there
                roadBlock2 = shortlist[new Random().Next(0, shortlist.Count())];
                roadBlockType = ConnectionType.Road;
                return target.CurrentLocation;
            }
            else if (Strategy == Strategy.Sneaky && NumberOfPossibleCurrentLocations > 4)
            {
                // choose two hunters that are not in the same location
                int distanceBetweenLordGodalmingAndDrSeward = game.DistanceByRoadBetween(game.Hunters[(int)Hunter.LordGodalming].CurrentLocation, game.Hunters[(int)Hunter.DrSeward].CurrentLocation, true);
                int distanceBetweenLordGodalmingAndVanHelsing = game.DistanceByRoadBetween(game.Hunters[(int)Hunter.LordGodalming].CurrentLocation, game.Hunters[(int)Hunter.VanHelsing].CurrentLocation, true);
                int distanceBetweenLordGodalmingAndMinaHarker = game.DistanceByRoadBetween(game.Hunters[(int)Hunter.LordGodalming].CurrentLocation, game.Hunters[(int)Hunter.MinaHarker].CurrentLocation, true);
                int distanceBetweenDrSewardAndVanHelsing = game.DistanceByRoadBetween(game.Hunters[(int)Hunter.DrSeward].CurrentLocation, game.Hunters[(int)Hunter.VanHelsing].CurrentLocation, true);
                int distanceBetweenDrSewardAndMinaHarker = game.DistanceByRoadBetween(game.Hunters[(int)Hunter.DrSeward].CurrentLocation, game.Hunters[(int)Hunter.MinaHarker].CurrentLocation, true);
                int distanceBetweenVanHelsingAndMinaHarker = game.DistanceByRoadBetween(game.Hunters[(int)Hunter.VanHelsing].CurrentLocation, game.Hunters[(int)Hunter.MinaHarker].CurrentLocation, true);

                HunterPlayer firstHunter = null;
                HunterPlayer secondHunter = null;

                int shortestNonZeroDistance = 99;
                if (distanceBetweenLordGodalmingAndDrSeward > 0 && distanceBetweenLordGodalmingAndDrSeward < shortestNonZeroDistance)
                {
                    shortestNonZeroDistance = distanceBetweenLordGodalmingAndDrSeward;
                    firstHunter = game.Hunters[(int)Hunter.LordGodalming];
                    secondHunter = game.Hunters[(int)Hunter.DrSeward];
                }
                if (distanceBetweenLordGodalmingAndVanHelsing > 0 && distanceBetweenLordGodalmingAndVanHelsing < shortestNonZeroDistance)
                {
                    shortestNonZeroDistance = distanceBetweenLordGodalmingAndVanHelsing;
                    firstHunter = game.Hunters[(int)Hunter.LordGodalming];
                    secondHunter = game.Hunters[(int)Hunter.VanHelsing];
                }
                if (distanceBetweenLordGodalmingAndMinaHarker > 0 && distanceBetweenLordGodalmingAndMinaHarker < shortestNonZeroDistance)
                {
                    shortestNonZeroDistance = distanceBetweenLordGodalmingAndMinaHarker;
                    firstHunter = game.Hunters[(int)Hunter.LordGodalming];
                    secondHunter = game.Hunters[(int)Hunter.MinaHarker];
                }
                if (distanceBetweenDrSewardAndVanHelsing > 0 && distanceBetweenDrSewardAndVanHelsing < shortestNonZeroDistance)
                {
                    shortestNonZeroDistance = distanceBetweenDrSewardAndVanHelsing;
                    firstHunter = game.Hunters[(int)Hunter.DrSeward];
                    secondHunter = game.Hunters[(int)Hunter.VanHelsing];
                }
                if (distanceBetweenDrSewardAndMinaHarker > 0 && distanceBetweenDrSewardAndMinaHarker < shortestNonZeroDistance)
                {
                    shortestNonZeroDistance = distanceBetweenDrSewardAndMinaHarker;
                    firstHunter = game.Hunters[(int)Hunter.DrSeward];
                    secondHunter = game.Hunters[(int)Hunter.MinaHarker];
                }
                if (distanceBetweenVanHelsingAndMinaHarker > 0 && distanceBetweenVanHelsingAndMinaHarker < shortestNonZeroDistance)
                {
                    shortestNonZeroDistance = distanceBetweenVanHelsingAndMinaHarker;
                    firstHunter = game.Hunters[(int)Hunter.VanHelsing];
                    secondHunter = game.Hunters[(int)Hunter.MinaHarker];
                }
                if (firstHunter != null)
                {
                    // figure out a road that is between them
                    if (shortestNonZeroDistance == 1)
                    {
                        roadBlock2 = secondHunter.CurrentLocation;
                        roadBlockType = ConnectionType.Road;
                        return firstHunter.CurrentLocation;
                    }
                    if (shortestNonZeroDistance == 2)
                    {
                        List<Location> firstHuntersConnections = game.Map.LocationsConnectedByRoadTo(firstHunter.CurrentLocation);
                        List<Location> secondHuntersConnections = game.Map.LocationsConnectedByRoadTo(secondHunter.CurrentLocation);
//.........这里部分代码省略.........
开发者ID:UncleGus,项目名称:dracula,代码行数:101,代码来源:DecisionMaker.cs


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