public void AddBlueBackedCardToAllPossibleTrails(GameState game) { List<PossibleTrailSlot[]> newPossibilityTree = new List<PossibleTrailSlot[]>(); foreach (PossibleTrailSlot[] trail in PossibilityTree) { Location currentLocation = Location.Nowhere; for (int i = 0; i < 6; i++) { if (trail[i].Location != Location.Nowhere) { currentLocation = trail[i].Location; break; } } List<PossibleTrailSlot> possibleCards = new List<PossibleTrailSlot>(); List<Location> possibleLocations = game.Map.LocationsConnectedBySeaTo(currentLocation); foreach (Location location in possibleLocations) { if (!TrailContainsLocation(trail, location) && game.Map.TypeOfLocation(location) == LocationType.Sea && !game.LocationIsBlocked(location)) { possibleCards.Add(new PossibleTrailSlot(location, Power.None, game.TimeOfDay, CardBack.Blue)); } } foreach (PossibleTrailSlot possibleCard in possibleCards) { PossibleTrailSlot[] newTrail = new PossibleTrailSlot[6]; for (int i = 5; i > 0; i--) { newTrail[i] = trail[i - 1]; } newTrail[0] = possibleCard; newPossibilityTree.Add(newTrail); } } PossibilityTree = newPossibilityTree; if (PossibilityTree.Count() == 0) { Console.WriteLine("Dracula stopped believing he exists after running AddBlueBackedCardToAllPossibleTrails"); PossibilityTree.Add(GetActualTrail(game)); } }
public List<PossibleTrailSlot[]> AddBlueBackedCardToTrail(GameState game, PossibleTrailSlot[] trail) { List<PossibleTrailSlot[]> newPossibilityTree = new List<PossibleTrailSlot[]>(); Location currentLocation = Location.Nowhere; for (int i = 0; i < 6; i++) { if (trail[i].Location != Location.Nowhere) { currentLocation = trail[i].Location; break; } } List<PossibleTrailSlot> possibleCards = new List<PossibleTrailSlot>(); List<Location> possibleLocations = game.Map.LocationsConnectedBySeaTo(currentLocation); foreach (Location location in possibleLocations) { if (!TrailContainsLocation(trail, location) && game.Map.TypeOfLocation(location) == LocationType.Sea && !game.LocationIsBlocked(location)) { possibleCards.Add(new PossibleTrailSlot(location, Power.None, game.TimeOfDay, CardBack.Blue)); } } foreach (PossibleTrailSlot possibleCard in possibleCards) { PossibleTrailSlot[] newTrail = new PossibleTrailSlot[6]; for (int i = 5; i > 0; i--) { newTrail[i] = trail[i - 1]; } newTrail[0] = possibleCard; newPossibilityTree.Add(newTrail); } return newPossibilityTree; }
public Location ChooseDestinationAndPower(GameState game, out Power power) { Location destination; if ((game.Dracula.AdvanceMoveLocation != Location.Nowhere && !game.LocationIsBlocked(game.Dracula.AdvanceMoveLocation)) || game.Dracula.AdvanceMovePower != Power.None) { power = game.Dracula.AdvanceMovePower; destination = game.Dracula.AdvanceMoveLocation; game.Dracula.AdvanceMoveLocation = Location.Nowhere; game.Dracula.AdvanceMovePower = Power.None; return destination; } var currentNumberOfPossibleCurrentLocations = NumberOfPossibleCurrentLocations; var currentActualTrail = GetActualTrail(game); var possibleMoves = GetPossibleMovesFromTrail(game, currentActualTrail); var possibleCurrentOrangeBackedLocations = new List<Location>(); foreach (var trail in PossibilityTree) { possibleCurrentOrangeBackedLocations.AddRange(GetPossibleCurrentLocationsFromPossibilityTree(AddOrangeBackedCardToTrail(game, trail))); } var possibleCurrentBlueBackedLocations = new List<Location>(); foreach (var trail in PossibilityTree) { possibleCurrentBlueBackedLocations.AddRange(GetPossibleCurrentLocationsFromPossibilityTree(AddBlueBackedCardToTrail(game, trail))); } var possibleWolfFormLocations = new List<Location>(); foreach (var trail in PossibilityTree) { possibleCurrentBlueBackedLocations.AddRange(GetPossibleCurrentLocationsFromPossibilityTree(AddWolfFormCardToTrail(game, trail))); } var uniquePossibleCurrentOrangeBackedLocations = new List<Location>(); var uniquePossibleCurrentBlueBackedLocations = new List<Location>(); var uniquePossibleWolfFormLocations = new List<Location>(); foreach (var location in possibleCurrentOrangeBackedLocations) { if (!uniquePossibleCurrentOrangeBackedLocations.Contains(location)) { uniquePossibleCurrentOrangeBackedLocations.Add(location); } } foreach (var location in possibleCurrentBlueBackedLocations) { if (!uniquePossibleCurrentBlueBackedLocations.Contains(location)) { uniquePossibleCurrentBlueBackedLocations.Add(location); } } foreach (var location in possibleWolfFormLocations) { if (!uniquePossibleWolfFormLocations.Contains(location)) { uniquePossibleWolfFormLocations.Add(location); } } var numberOfPossibleOrangeBackedLocationsThatWouldBeRevealed = uniquePossibleCurrentOrangeBackedLocations.Count(loc => game.HuntersAt(loc).Any()); var numberOfPossibleLocationsAfterMove = new List<int>(); foreach (var move in possibleMoves) { if ((game.HuntersAt(move.Location).Any() && game.Map.TypeOfLocation(move.Location) != LocationType.Sea) || move.Location == Location.CastleDracula) { numberOfPossibleLocationsAfterMove.Add(1); } else { if (move.Power == Power.None || move.Power == Power.Hide) { if (move.CardBack == CardBack.Orange) { numberOfPossibleLocationsAfterMove.Add(uniquePossibleCurrentOrangeBackedLocations.Count() - numberOfPossibleOrangeBackedLocationsThatWouldBeRevealed); } else if (move.CardBack == CardBack.Blue) { numberOfPossibleLocationsAfterMove.Add(uniquePossibleCurrentBlueBackedLocations.Count()); } } else if (move.Power == Power.Feed || move.Power == Power.DarkCall) { numberOfPossibleLocationsAfterMove.Add(currentNumberOfPossibleCurrentLocations); } else if (move.Power == Power.DoubleBack) { var doubleBackSlot = GetIndexOfLocationInTrail(move.Location, currentActualTrail); var uniquePossibleDoubleBackLocations = new List<Location>(); foreach (var trail in PossibilityTree) { if (DoubleBackToPositionIsValidForTrail(game, trail, doubleBackSlot) && !uniquePossibleDoubleBackLocations.Contains(trail[doubleBackSlot].Location)) { uniquePossibleDoubleBackLocations.Add(trail[doubleBackSlot].Location); } } numberOfPossibleLocationsAfterMove.Add(uniquePossibleDoubleBackLocations.Count() - uniquePossibleDoubleBackLocations.Count(loc => game.HuntersAt(loc).Any())); } else if (move.Power == Power.WolfForm) { numberOfPossibleLocationsAfterMove.Add(uniquePossibleWolfFormLocations.Count() - uniquePossibleWolfFormLocations.Count(loc => game.HuntersAt(loc).Any())); } } } var numberOfMovesUntilDeadEnd = new List<int>(); var deadEndMoves = GetPossibleMovesThatLeadToDeadEnds(game, currentActualTrail, possibleMoves, numberOfMovesUntilDeadEnd); int turnsUntilTrailCleared = GetNumberOfTurnsUntilTrailCleared(game); int index; int randomNumber; List<PossibleTrailSlot> shortList; switch (Strategy) { case Strategy.Sneaky: var distancesFromNearestHunter = new List<int>(); var currentDistanceFromHunters = game.GetDistanceToClosestHunter(game.Dracula.CurrentLocation, true); foreach (var move in possibleMoves) { if (move.Location != Location.Nowhere) { distancesFromNearestHunter.Add(game.GetDistanceToClosestHunter(move.Location, true)); GC.Collect(); } else { distancesFromNearestHunter.Add(currentDistanceFromHunters); } } var chancesToSelectMove = new List<int>(); index = -1; foreach (var move in possibleMoves) { index++; var deadEndIndex = deadEndMoves.FindIndex(m => m.Location == move.Location && m.Power == move.Power); if (deadEndIndex > -1 && turnsUntilTrailCleared > numberOfMovesUntilDeadEnd[deadEndIndex]) { chancesToSelectMove.Add(1); } else { chancesToSelectMove.Add((int)(Math.Pow(numberOfPossibleLocationsAfterMove[index] * distancesFromNearestHunter[index], CHANCETOSELECTSCALAR) * PercentageDifferenceInLikelihoodOfDraculaDeath(game.Dracula.Blood, move.Power))); } } 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; }
public void AddWolfFormToAllPossibleTrails(GameState game) { List<PossibleTrailSlot[]> newPossibilityTree = new List<PossibleTrailSlot[]>(); foreach (PossibleTrailSlot[] trail in PossibilityTree) { Location currentLocation = Location.Nowhere; for (int i = 0; i < 6; i++) { if (trail[i].Location != Location.Nowhere) { currentLocation = trail[i].Location; break; } } List<Location> possibleDestinations = new List<Location>(); List<Location> locationsToAdd = game.Map.LocationsConnectedByRoadTo(currentLocation); foreach (Location location in locationsToAdd) { if (!game.LocationIsBlocked(location) && !possibleDestinations.Contains(location)) { possibleDestinations.Add(location); } } List<Location> moreLocationsToAdd = new List<Location>(); foreach (Location location in possibleDestinations) { locationsToAdd = game.Map.LocationsConnectedByRoadTo(location); foreach (Location loc in locationsToAdd) { if (!game.LocationIsBlocked(loc) && !possibleDestinations.Contains(loc) && !TrailContainsLocation(trail, loc)) { moreLocationsToAdd.Add(loc); } } } possibleDestinations.AddRange(moreLocationsToAdd); List<PossibleTrailSlot> possibleCards = new List<PossibleTrailSlot>(); foreach (Location location in possibleDestinations) { possibleCards.Add(new PossibleTrailSlot(location, Power.WolfForm, game.TimeOfDay, CardBack.Orange)); } foreach (PossibleTrailSlot possibleCard in possibleCards) { PossibleTrailSlot[] newTrail = new PossibleTrailSlot[6]; for (int i = 5; i > 0; i--) { newTrail[i] = trail[i - 1]; } newTrail[0] = possibleCard; newPossibilityTree.Add(newTrail); } } PossibilityTree = newPossibilityTree; if (PossibilityTree.Count() == 0) { Console.WriteLine("Dracula stopped believing he exists after running AddWolfFormToAllPossibleTrails"); PossibilityTree.Add(GetActualTrail(game)); } }
public List<PossibleTrailSlot[]> AddOrangeBackedCardToTrail(GameState game, PossibleTrailSlot[] trail) { List<PossibleTrailSlot[]> newPossibilityTree = new List<PossibleTrailSlot[]>(); Location currentLocation = GetCurrentLocationFromTrail(trail); List<PossibleTrailSlot> possibleCards = new List<PossibleTrailSlot>(); List<Location> possibleLocations = game.Map.LocationsConnectedByRoadTo(currentLocation); foreach (Location location in possibleLocations) { if (!TrailContainsLocation(trail, location) && !game.LocationIsBlocked(location)) { possibleCards.Add(new PossibleTrailSlot(location, Power.None, game.TimeOfDay, CardBack.Orange)); } } if (!TrailContainsPower(trail, Power.Hide)) { possibleCards.Add(new PossibleTrailSlot(Location.Nowhere, Power.Hide)); } foreach (PossibleTrailSlot possibleCard in possibleCards) { PossibleTrailSlot[] newTrail = new PossibleTrailSlot[6]; for (int i = 5; i > 0; i--) { newTrail[i] = trail[i - 1]; } newTrail[0] = possibleCard; newPossibilityTree.Add(newTrail); } return newPossibilityTree; }
public void AddOrangeBackedCardToAllPossibleTrails(GameState game) { var newPossibilityTree = new List<PossibleTrailSlot[]>(); var list = PossibilityTree.FindAll(trail => TrailContainsPower(trail, Power.Hide)); foreach (var trail in PossibilityTree) { var currentLocation = GetCurrentLocationFromTrail(trail); var possibleCards = new List<PossibleTrailSlot>(); var possibleLocations = game.Map.LocationsConnectedByRoadTo(currentLocation); foreach (var location in possibleLocations) { if (!TrailContainsLocation(trail, location) && !game.LocationIsBlocked(location)) { possibleCards.Add(new PossibleTrailSlot(location, Power.None, game.TimeOfDay, CardBack.Orange)); } } if (!TrailContainsPower(trail, Power.Hide)) { possibleCards.Add(new PossibleTrailSlot(Location.Nowhere, Power.Hide)); } foreach (var possibleCard in possibleCards) { var newTrail = new PossibleTrailSlot[6]; for (int i = 5; i > 0; i--) { newTrail[i] = trail[i - 1]; } newTrail[0] = possibleCard; newPossibilityTree.Add(newTrail); } } PossibilityTree = newPossibilityTree; if (PossibilityTree.Count() == 0) { Console.WriteLine("Dracula stopped believing he exists after running AddOrangeBackedCardToAllPossibleTrails"); PossibilityTree.Add(GetActualTrail(game)); } }
private List<PossibleTrailSlot[]> AddWolfFormCardToTrail(GameState game, PossibleTrailSlot[] trail) { var currentLocation = GetCurrentLocationFromTrail(trail); var tempLocationList = game.Map.LocationsConnectedByRoadOrSeaTo(currentLocation); tempLocationList.RemoveAll(loc => game.LocationIsBlocked(loc)); var possibleDestinations = new List<Location>(); foreach (var location in tempLocationList) { possibleDestinations.Add(location); possibleDestinations.AddRange(game.Map.LocationsConnectedByRoadTo(location)); } possibleDestinations.RemoveAll(loc => game.LocationIsBlocked(loc) || TrailContainsLocation(trail, loc) || game.Map.TypeOfLocation(loc) == LocationType.Sea); var uniquePossibleDestinations = new List<Location>(); foreach (var location in possibleDestinations) { if (!uniquePossibleDestinations.Contains(location)) { uniquePossibleDestinations.Add(location); } } var newPossibilityTree = new List<PossibleTrailSlot[]>(); foreach (var location in uniquePossibleDestinations) { var newTrail = new PossibleTrailSlot[6]; for (int i = 5; i > 0; i--) { if (trail[i - 1] != null) { newTrail[i] = trail[i - 1]; } } newTrail[0] = new PossibleTrailSlot(location, Power.WolfForm, game.TimeOfDay, CardBack.Orange); } return newPossibilityTree; }
public List<PossibleTrailSlot> GetPossibleMovesFromTrail(GameState game, PossibleTrailSlot[] trail) { var possibleMoves = new List<PossibleTrailSlot>(); var currentLocation = GetCurrentLocationFromTrail(trail); var locationsInTrail = GetLocationsFromTrail(trail); var possiblePowers = Enumerations.GetAvailablePowers(game.TimeOfDay); possiblePowers.RemoveAll(power => GetPowersFromTrail(trail).Contains(power)); if (game.Map.TypeOfLocation(currentLocation) == LocationType.Sea) { possiblePowers.Remove(Power.Feed); possiblePowers.Remove(Power.DarkCall); possiblePowers.Remove(Power.Hide); } possiblePowers.RemoveAll(pow => TrailContainsPower(trail, pow)); var possibleDestinationsByDoubleBack = game.Map.LocationsConnectedByRoadOrSeaTo(currentLocation).Intersect(locationsInTrail); var possibleDestinationsByRoadOrSea = game.Map.LocationsConnectedByRoadOrSeaTo(currentLocation); possibleDestinationsByRoadOrSea.RemoveAll(location => possibleDestinationsByDoubleBack.Contains(location) || game.LocationIsBlocked(location)); var possibleDestinationsByWolfForm = new List<Location>(); if (possiblePowers.Contains(Power.WolfForm)) { possibleDestinationsByWolfForm = game.Map.LocationsConnectedByRoadOrSeaTo(currentLocation); possibleDestinationsByWolfForm.RemoveAll(loc => game.LocationIsBlocked(loc)); var secondLayerOfDestinations = new List<Location>(); var temporaryLayerOfDestinations = new List<Location>(); foreach (var destination in possibleDestinationsByWolfForm) { temporaryLayerOfDestinations.Clear(); temporaryLayerOfDestinations.AddRange(game.Map.LocationsConnectedByRoadOrSeaTo(destination)); temporaryLayerOfDestinations.RemoveAll(loc => game.LocationIsBlocked(loc) || game.Map.TypeOfLocation(loc) == LocationType.Sea || possibleDestinationsByWolfForm.Contains(loc) || secondLayerOfDestinations.Contains(loc) || locationsInTrail.Contains(loc)); secondLayerOfDestinations.AddRange(temporaryLayerOfDestinations); } possibleDestinationsByWolfForm.AddRange(secondLayerOfDestinations); possibleDestinationsByWolfForm.RemoveAll(loc => locationsInTrail.Contains(loc)); } foreach (var destination in possibleDestinationsByRoadOrSea) { if (game.Map.TypeOfLocation(destination) == LocationType.Sea) { possibleMoves.Add(new PossibleTrailSlot(destination, Power.None, game.TimeOfDay, CardBack.Blue)); } else { possibleMoves.Add(new PossibleTrailSlot(destination, Power.None, game.TimeOfDay, CardBack.Orange)); } } if (possiblePowers.Contains(Power.DoubleBack)) { foreach (var destination in possibleDestinationsByDoubleBack) { if (game.Map.TypeOfLocation(destination) == LocationType.Sea) { possibleMoves.Add(new PossibleTrailSlot(destination, Power.DoubleBack, game.TimeOfDay, CardBack.Blue)); } else { possibleMoves.Add(new PossibleTrailSlot(destination, Power.DoubleBack, game.TimeOfDay, CardBack.Orange)); } } } foreach (var power in possiblePowers) { if (power == Power.Hide) { possibleMoves.Add(new PossibleTrailSlot(Location.Nowhere, power, game.TimeOfDay, CardBack.Orange)); } else if (power == Power.DarkCall || power == Power.Feed) { possibleMoves.Add(new PossibleTrailSlot(Location.Nowhere, power, game.TimeOfDay, CardBack.Power)); } } foreach (var destination in possibleDestinationsByWolfForm) { possibleMoves.Add(new PossibleTrailSlot(destination, Power.WolfForm, game.TimeOfDay, CardBack.Orange)); } return possibleMoves; }
public void AddDoubleBackToAllPossibleTrails(GameState game, int doubleBackSlot) { List<PossibleTrailSlot[]> newPossibilityTree = new List<PossibleTrailSlot[]>(); foreach (PossibleTrailSlot[] trail in PossibilityTree) { Location currentLocation = GetCurrentLocationFromTrail(trail); if (trail[doubleBackSlot].Power != Power.Hide && game.Map.LocationsConnectedByRoadOrSeaTo(currentLocation).Contains(trail[doubleBackSlot].Location) && !game.LocationIsBlocked(trail[doubleBackSlot].Location)) { PossibleTrailSlot[] newPossibleTrail = new PossibleTrailSlot[6]; for (int i = 5; i > doubleBackSlot; i--) { newPossibleTrail[i] = trail[i]; } for (int i = doubleBackSlot; i > 0; i--) { newPossibleTrail[i] = trail[i - 1]; } newPossibleTrail[0] = trail[doubleBackSlot]; newPossibleTrail[0].Power = Power.DoubleBack; newPossibilityTree.Add(newPossibleTrail); } } PossibilityTree = newPossibilityTree; if (PossibilityTree.Count() == 0) { Console.WriteLine("Dracula stopped believing he exists after running AddDoubleBackToAllPossibleTrails"); PossibilityTree.Add(GetActualTrail(game)); } }