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 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[]> 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; }
private bool TrailContainsLocation(PossibleTrailSlot[] trail, Location location) { for (int i = 0; i < 6; i++) { if (trail[i] != null && trail[i].Location == location) { return true; } } return false; }
private bool TrailContainsPower(PossibleTrailSlot[] trail, Power power) { for (int i = 0; i < 6; i++) { if (trail[i] != null && trail[i].Power == power) { return true; } } return false; }
private List<Power> GetPowersFromTrail(PossibleTrailSlot[] trail) { var powers = new List<Power>(); for (int i = 0; i < 6; i++) { if (trail[i] != null && trail[i].Power != Power.None && !powers.Any(item => item == trail[i].Power)) { powers.Add(trail[i].Power); } } return powers; }
private int IndexOfLocationInTrail(PossibleTrailSlot[] trail, Location loc) { for (int i = 0; i < 6; i++) { if (trail[i].Location == loc) { return i; } } return -1; }
public void AddEvasionCardToTrail(GameState game) { List<PossibleTrailSlot[]> newPossibilityTree = new List<PossibleTrailSlot[]>(); List<Location> allCities = new List<Location>(); List<Location> allLocations = Enumerations.GetAllLocations(); foreach (Location loc in allLocations) { if (game.Map.TypeOfLocation(loc) == LocationType.SmallCity || game.Map.TypeOfLocation(loc) == LocationType.LargeCity) { allCities.Add(loc); } } foreach (PossibleTrailSlot[] trail in PossibilityTree) { foreach (Location location in allCities) { if (!game.HuntersAt(location).Any() && !TrailContainsLocation(trail, location) && !game.CatacombsContainsLocation(location)) { PossibleTrailSlot[] newPossibleTrail = new PossibleTrailSlot[6]; for (int i = 5; i > 0; i--) { newPossibleTrail[i] = trail[i - 1]; } newPossibleTrail[0] = new PossibleTrailSlot(location, Power.None, game.TimeOfDay, CardBack.Orange); newPossibilityTree.Add(newPossibleTrail); } } } PossibilityTree = newPossibilityTree; if (PossibilityTree.Count() == 0) { Console.WriteLine("Dracula stopped believing he exists after running AddEvasionCardToTrail"); PossibilityTree.Add(GetActualTrail(game)); } }
private PossibleTrailSlot[] GetNewTrailFromDoubleBackMove(PossibleTrailSlot[] trail, int doubleBackIndex) { var newTrail = new PossibleTrailSlot[6]; for (int i = 5; i > doubleBackIndex; i--) { if (trail[i] != null) { newTrail[i] = trail[i]; } } for (int i = doubleBackIndex; i > 0; i--) { newTrail[i] = trail[i - 1]; } newTrail[0] = trail[doubleBackIndex]; return newTrail; }
private List<PossibleTrailSlot[]> GetExpandedTrail(GameState game, PossibleTrailSlot[] trail) { var newPossibilityTree = new List<PossibleTrailSlot[]>(); var possibleMoves = GetPossibleMovesFromTrail(game, trail); var currentLocation = GetCurrentLocationFromTrail(trail); foreach (var move in possibleMoves) { var newTimeOfDay = game.Map.TypeOfLocation(currentLocation) == LocationType.Sea ? trail[GetIndexOfLocationInTrail(currentLocation, trail)].TimeOfDay : (TimeOfDay)((int)(trail[GetIndexOfLocationInTrail(currentLocation, trail)].TimeOfDay) % 6 + 1); var newTrail = new PossibleTrailSlot[6]; if (move.Power == Power.DoubleBack) { newTrail = GetNewTrailFromDoubleBackMove(trail, GetIndexOfLocationInTrail(move.Location, trail)); newTrail[0].TimeOfDay = newTimeOfDay; } else { var newCardBack = game.Map.TypeOfLocation(move.Location) == LocationType.Sea ? CardBack.Blue : move.Power == Power.Feed || move.Power == Power.DarkCall ? CardBack.Power : CardBack.Orange; for (int i = 5; i > 0; i--) { if (trail[i - 1] != null) { newTrail[i] = trail[i - 1]; } newTrail[0] = new PossibleTrailSlot(move.Location, move.Power, newTimeOfDay, newCardBack); } } newPossibilityTree.Add(newTrail); } return newPossibilityTree; }
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)); } }
private bool DoubleBackToPositionIsValidForTrail(GameState game, PossibleTrailSlot[] trail, int doubleBackSlot) { return (game.Map.LocationsConnectedByRoadOrSeaTo(GetCurrentLocationFromTrail(trail)).Contains(trail[doubleBackSlot].Location)); }
private Location GetCurrentLocationFromTrail(PossibleTrailSlot[] trail) { for (int i = 0; i < 6; i++) { if (trail[i].Location != Location.Nowhere) { return trail[i].Location; } } return Location.Nowhere; }
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> GetPossibleMovesThatLeadToDeadEnds(GameState game, PossibleTrailSlot[] trail, List<PossibleTrailSlot> initialPossibleMoves, List<int> numberOfMovesBeforeReachingDeadEnd) { var deadEndMoves = new List<PossibleTrailSlot>(); return ExpandPossibilityTreeToFindDeadEnds(game, new List<PossibleTrailSlot[]> { trail }, 0, 6, GetIndexOfLocationInTrail(GetCurrentLocationFromTrail(trail), trail), initialPossibleMoves, deadEndMoves, numberOfMovesBeforeReachingDeadEnd); }
public void AddPowerCardToAllPossibleTrails(GameState game, Power power) { foreach (PossibleTrailSlot[] trail in PossibilityTree) { for (int i = 5; i > 0; i--) { trail[i] = trail[i - 1]; } trail[0] = new PossibleTrailSlot(Location.Nowhere, power, game.TimeOfDay, CardBack.Power); } }
public PossibleTrailSlot[] GetActualTrail(GameState game) { PossibleTrailSlot[] actualTrail = new PossibleTrailSlot[6]; for (int i = 0; i < 6; i++) { if (game.Dracula.Trail[i] != null) { actualTrail[i] = new PossibleTrailSlot(Location.Nowhere, Power.None); foreach (DraculaCard card in game.Dracula.Trail[i].DraculaCards) { if (card.Location != Location.Nowhere) { actualTrail[i].Location = card.Location; if (game.Map.TypeOfLocation(card.Location) == LocationType.Sea) { actualTrail[i].CardBack = CardBack.Blue; } else { actualTrail[i].CardBack = CardBack.Orange; } } if (card.Power != Power.None) { actualTrail[i].Power = card.Power; if (card.Power == Power.Hide) { actualTrail[i].CardBack = CardBack.Orange; } else if (card.Power == Power.Feed || card.Power == Power.DarkCall) { actualTrail[i].CardBack = CardBack.Power; } } } } } actualTrail[0].TimeOfDay = game.TimeOfDay; return actualTrail; }
private int GetIndexOfLocationInTrail(Location location, PossibleTrailSlot[] trail) { for (int i = 0; i < 6; i++) { if (trail[i] != null && trail[i].Location == location) { return i; } } return -1; }
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; }
private List<Location> GetLocationsFromTrail(PossibleTrailSlot[] trail) { var locations = new List<Location>(); for (int i = 0; i < 6; i++) { if (trail[i] != null && trail[i].Location != Location.Nowhere && !locations.Any(item => item == trail[i].Location)) { locations.Add(trail[i].Location); } } return locations; }
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)); } }