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


C# GameState.DistanceByRoadOrSeaBetween方法代码示例

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


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

示例1: ChooseDestinationForWildHorses

        public Location ChooseDestinationForWildHorses(GameState game)
        {
            var possibleDestination = game.Map.LocationsConnectedByRoadTo(game.Dracula.CurrentLocation);
            List<int> distances = new List<int>();
            int longestDistance = 0;
            foreach (Location location in possibleDestination)
            {
                distances.Add(game.DistanceByRoadOrSeaBetween(location, Location.CastleDracula, false));
                if (distances.Last() > longestDistance)
                {
                    longestDistance = distances.Last();
                }
            }

            List<Location> shortList = new List<Location>();
            int index = -1;
            foreach (Location location in possibleDestination)
            {
                index++;
                if (distances[index] == longestDistance)
                {
                    shortList.Add(location);
                }
            }
            return shortList[new Random().Next(0, shortList.Count())];
        }
开发者ID:UncleGus,项目名称:dracula,代码行数:26,代码来源:DecisionMaker.cs

示例2: ChooseDestinationAndPower


//.........这里部分代码省略.........
                    }
                    int totalCombinations = 0;
                    foreach (int i in chancesToSelectMove)
                    {
                        totalCombinations += i;
                    }
                    randomNumber = new Random().Next(0, totalCombinations);
                    index = -1;
                    int count = 0;
                    foreach (int i in chancesToSelectMove)
                    {
                        index++;
                        count += i;
                        if (count > randomNumber)
                        {
                            power = possibleMoves[index].Power;
                            return possibleMoves[index].Location;
                        }
                    }
                    power = possibleMoves[0].Power;
                    return possibleMoves[0].Location;
                case Strategy.Aggressive:
                    var distancesFromVictim = new List<int>();
                    var currentDistanceFromVictim = game.GetDistanceToHunter(victim);
                    foreach (var move in possibleMoves)
                    {
                        if (move.Location != Location.Nowhere)
                        {
                            distancesFromVictim.Add(game.GetDistanceToHunter(victim));
                            GC.Collect();
                        }
                        else
                        {
                            distancesFromVictim.Add(currentDistanceFromVictim);
                        }
                    }
                    int shortestDistanceToVictim = distancesFromVictim.First();
                    foreach (var i in distancesFromVictim)
                    {
                        if (i < shortestDistanceToVictim)
                        {
                            shortestDistanceToVictim = i;
                        }
                    }
                    shortList = new List<PossibleTrailSlot>();
                    index = -1;
                    foreach (PossibleTrailSlot move in possibleMoves)
                    {
                        index++;
                        if (distancesFromVictim[index] == shortestDistanceToVictim)
                        {
                            shortList.Add(move);
                        }
                    }
                    randomNumber = new Random().Next(0, shortList.Count());
                    power = shortList[randomNumber].Power;
                    return shortList[randomNumber].Location;
                case Strategy.FleeToCastleDracula:
                    var distancesToCastleDracula = new List<int>();
                    var currentDistanceFromCastleDracula = game.DistanceByRoadOrSeaBetween(game.Dracula.CurrentLocation, Location.CastleDracula, false);
                    foreach (var move in possibleMoves)
                    {
                        if (move.Location != Location.Nowhere)
                        {
                            distancesToCastleDracula.Add(game.DistanceByRoadOrSeaBetween(move.Location, Location.CastleDracula, false));
                            GC.Collect();
                        }
                        else
                        {
                            distancesToCastleDracula.Add(currentDistanceFromCastleDracula);
                        }
                    }
                    int shortestDistanceToCastleDracula = distancesToCastleDracula.First();
                    foreach (int i in distancesToCastleDracula)
                    {
                        if (i < shortestDistanceToCastleDracula)
                        {
                            shortestDistanceToVictim = i;
                        }
                    }
                    shortList = new List<PossibleTrailSlot>();
                    index = -1;
                    foreach (PossibleTrailSlot move in possibleMoves)
                    {
                        index++;
                        if (distancesToCastleDracula[index] == shortestDistanceToCastleDracula)
                        {
                            shortList.Add(move);
                        }
                    }
                    randomNumber = new Random().Next(0, shortList.Count());
                    power = shortList[randomNumber].Power;
                    return shortList[randomNumber].Location;

            }

            int rand = new Random().Next(0, possibleMoves.Count());
            power = possibleMoves[rand].Power;
            return possibleMoves[rand].Location;
        }
开发者ID:UncleGus,项目名称:dracula,代码行数:101,代码来源:DecisionMaker.cs

示例3: 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

示例4: ChooseBatsDestination

 public Location ChooseBatsDestination(GameState game, Hunter hunterWithEncounter)
 {
     List<Location> possibleDestinations = game.Map.LocationsConnectedByRoadTo(game.Hunters[(int)hunterWithEncounter].CurrentLocation);
     List<int> distances = new List<int>();
     int totalDistanceWeights = 0;
     foreach (Location location in possibleDestinations)
     {
         distances.Add(game.DistanceByRoadOrSeaBetween(location, game.Dracula.CurrentLocation, false));
         totalDistanceWeights += distances.Last();
     }
     if (Strategy == Strategy.Sneaky)
     {
         int randomNumber = new Random().Next(0, totalDistanceWeights);
         int count = 0;
         int index = -1;
         foreach (int distance in distances)
         {
             index++;
             count += distance;
             if (count > randomNumber)
             {
                 return possibleDestinations[index];
             }
         }
     }
     else if (Strategy == Strategy.Aggressive)
     {
         List<Location> shortList = new List<Location>();
         int shortestDistance = distances.First();
         foreach (int distance in distances)
         {
             if (distance < shortestDistance)
             {
                 shortestDistance = distance;
             }
         }
         int index = -1;
         foreach (int distance in distances)
         {
             index++;
             if (distance == shortestDistance)
             {
                 shortList.Add(possibleDestinations[index]);
             }
         }
         return shortList[new Random().Next(0, shortList.Count())];
     }
     return possibleDestinations[new Random().Next(0, possibleDestinations.Count())];
 }
开发者ID:UncleGus,项目名称:dracula,代码行数:49,代码来源:DecisionMaker.cs

示例5: ChoosePortToGoToAfterStormySeas

        public Location ChoosePortToGoToAfterStormySeas(GameState game)
        {
            var validPorts = game.Map.GetPortsAdjacentTo(game.Dracula.CurrentLocation);
            if (!validPorts.Any())
            {
                return Location.Nowhere;
            }

            List<int> distances = new List<int>();
            if (Strategy == Strategy.Sneaky)
            {
                int totalDistanceWeights = 0;
                foreach (Location location in validPorts)
                {
                    int distance = game.GetDistanceToClosestHunter(location, false);
                    distances.Add(distance * distance);
                    totalDistanceWeights += distances.Last();
                }
                int randomNumber = new Random().Next(0, totalDistanceWeights);
                int count = 0;
                int index = -1;
                foreach (int dist in distances)
                {
                    index++;
                    count += dist;
                    if (count > randomNumber)
                    {
                        return validPorts[index];
                    }
                }
            }
            else if (Strategy == Strategy.Aggressive)
            {
                foreach (Location location in validPorts)
                {
                    int distance = game.GetDistanceToClosestHunter(location, false);
                }
                int shortestDistance = distances.First();
                foreach (int dist in distances)
                {
                    if (dist < shortestDistance)
                    {
                        shortestDistance = dist;
                    }
                }
                List<Location> shortList = new List<Location>();
                int index = -1;
                foreach (Location port in validPorts)
                {
                    index++;
                    if (distances[index] == shortestDistance)
                    {
                        shortList.Add(port);
                    }
                }
                return shortList[new Random().Next(0, shortList.Count())];
            }
            else if (Strategy == Strategy.FleeToCastleDracula)
            {
                foreach (Location location in validPorts)
                {
                    int distance = game.DistanceByRoadOrSeaBetween(location, Location.CastleDracula, false);
                }
                int shortestDistance = distances.First();
                foreach (int dist in distances)
                {
                    if (dist < shortestDistance)
                    {
                        shortestDistance = dist;
                    }
                }
                List<Location> shortList = new List<Location>();
                int index = -1;
                foreach (Location port in validPorts)
                {
                    index++;
                    if (distances[index] == shortestDistance)
                    {
                        shortList.Add(port);
                    }
                }
                return shortList[new Random().Next(0, shortList.Count())];
            }
            return validPorts[new Random().Next(0, validPorts.Count())];
        }
开发者ID:UncleGus,项目名称:dracula,代码行数:85,代码来源:DecisionMaker.cs


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