Exemple #1
0
        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);
                        List<Location> overlap = new List<Location>();
                        foreach (Location location in firstHuntersConnections)
                        {
                            if (secondHuntersConnections.Contains(location))
                            {
                                overlap.Add(location);
                            }
                        }
                        // block that road
                        roadBlock2 = overlap[new Random().Next(0, overlap.Count())];
                        roadBlockType = ConnectionType.Road;
                        if (new Random().Next(0, 1) == 0)
                        {
                            return firstHunter.CurrentLocation;
                        }
                        else
                        {
                            return secondHunter.CurrentLocation;
                        }
                    }
                }
            }
            else if ((Strategy == Strategy.Sneaky && NumberOfPossibleCurrentLocations < 5) || Strategy == Strategy.FleeToCastleDracula)
            {
                // 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 closer to dracula than their current location
                List<Location> connectedLocations = game.Map.LocationsConnectedByRoadTo(target.CurrentLocation);
                List<int> distances = new List<int>();
                int shortestDistance = 100;
                foreach (Location location in connectedLocations)
                {
                    distances.Add(game.DistanceByRoadOrSeaBetween(location, game.Dracula.CurrentLocation, false));
                    if (distances.Last() < shortestDistance)
                    {
                        shortestDistance = distances.Last();
                    }
                }
                List<Location> shortlist = new List<Location>();
                int index = -1;
                foreach (int dist in distances)
                {
                    index++;
                    if (dist == shortestDistance)
                    {
                        shortlist.Add(connectedLocations[index]);
                    }
                }

                // put the roadblock there
                roadBlock2 = shortlist[new Random().Next(0, shortlist.Count())];
                roadBlockType = ConnectionType.Road;
                return target.CurrentLocation;
            }

            var allLocations = Enumerations.GetAllLocations();
            var allCities = new List<Location>();
            foreach (var loc in allLocations)
            {
                if (game.Map.TypeOfLocation(loc) == LocationType.SmallCity ||
                    game.Map.TypeOfLocation(loc) == LocationType.LargeCity)
                {
                    allCities.Add(loc);
                }
            }
            var roadBlock1 = allCities[new Random().Next(0, allCities.Count())];
            var citiesConnectedToRoadBlock1ByRoad = game.Map.LocationsConnectedByRoadTo(roadBlock1);
            var citiesConnectedToRoadBlock1ByTrain = game.Map.LocationsConnectedByTrainTo(roadBlock1);
            var citiesConnectedToRoadBlock1 = new List<Location>();
            citiesConnectedToRoadBlock1.AddRange(citiesConnectedToRoadBlock1ByRoad);
            citiesConnectedToRoadBlock1.AddRange(citiesConnectedToRoadBlock1ByTrain);
            roadBlock2 = citiesConnectedToRoadBlock1[new Random().Next(0, citiesConnectedToRoadBlock1.Count())];
            if (citiesConnectedToRoadBlock1ByRoad.Contains(roadBlock2))
            {
                if (citiesConnectedToRoadBlock1ByTrain.Contains(roadBlock2))
                {
                    if (new Random().Next(0, 2) == 0)
                    {
                        roadBlockType = ConnectionType.Road;
                    }
                    else
                    {
                        roadBlockType = ConnectionType.Rail;
                    }
                }
                else
                {
                    roadBlockType = ConnectionType.Road;
                }
            }
            else
            {
                roadBlockType = ConnectionType.Rail;
            }
            return roadBlock1;
        }