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; }
/// <summary> /// Checks if a given Event card is already known by Dracula to be in a given Hunter's hand and adds it if not /// </summary> /// <param name="game">The GameState</param> /// <param name="hunterRevealingCard">The Hunter revealing the card</param> /// <param name="eventBeingRevealed">The Event being revealed</param> /// <returns>The card corresponding to the Event revealed</returns> private static EventCard AddEventCardToDraculaKnownCardsIfNotAlreadyKnown(GameState game, HunterPlayer hunterRevealingCard, Event eventBeingRevealed) { var eventCardBeingRevealed = hunterRevealingCard.EventsKnownToDracula.Find(card => card.Event == eventBeingRevealed); if (eventCardBeingRevealed == null) { eventCardBeingRevealed = game.EventDeck.Find(card => card.Event == eventBeingRevealed); game.EventDeck.Remove(eventCardBeingRevealed); hunterRevealingCard.EventsKnownToDracula.Add(eventCardBeingRevealed); } return eventCardBeingRevealed; }
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)); } }
/// <summary> /// Determines if Dracula is playing Seduction at the start of an Encounter /// </summary> /// <param name="game">The GameState</param> /// <param name="logic">The artificial intelligence component</param> /// <returns>True if Dracula successfully plays Seduction</returns> private static bool DraculaIsPlayingSeduction(GameState game, DecisionMaker logic) { if (logic.ChooseToPlaySeduction(game)) { Console.WriteLine("Dracula is playing Seduction"); game.Dracula.DiscardEvent(Event.Seduction, game.EventDiscard); if (HunterPlayingGoodLuckToCancelDraculaEvent(game, Event.Seduction, Event.Seduction, logic) > 0) { Console.WriteLine("Seduction cancelled"); return false; } return true; } return false; }
/// <summary> /// Resolves a Hunter using an Item outside of combat /// </summary> /// <param name="game">The GameState</param> /// <param name="itemName">The string to be converted to the Item being used</param> /// <param name="hunterIndex">The string to be converted to the Hunter using the Item</param> private static void UseItem(GameState game, string itemName, string hunterIndex) { var index = 0; var hunterUsingItem = Hunter.Nobody; if (int.TryParse(hunterIndex, out index)) { hunterUsingItem = game.GetHunterFromInt(index); } var line = ""; while (hunterUsingItem == Hunter.Nobody && index != -1) { Console.WriteLine("Who is using an Item? {0}= {1}, {2}= {3}, {4}= {5}, {6}= {7} (-1 to cancel)", (int)Hunter.LordGodalming, Hunter.LordGodalming.Name(), (int)Hunter.DrSeward, Hunter.DrSeward.Name(), (int)Hunter.VanHelsing, Hunter.VanHelsing.Name(), (int)Hunter.MinaHarker, Hunter.MinaHarker.Name()); line = Console.ReadLine(); if (int.TryParse(line, out index)) { if (index == -1) { Console.WriteLine("Cancelled"); return; } hunterUsingItem = game.GetHunterFromInt(index); Console.WriteLine(hunterUsingItem.Name()); } else { Console.WriteLine("I didn't understand that"); } } var itemBeingUsed = Enumerations.GetItemFromString(itemName); while (itemBeingUsed == Item.None && line.ToLower() != "cancel") { Console.WriteLine("What is the name of the Item being used?"); line = Console.ReadLine(); itemBeingUsed = Enumerations.GetItemFromString(line); } if (line.ToLower() == "cancel") { Console.WriteLine("Cancelled"); return; } switch (itemBeingUsed) { case Item.Dogs: Console.WriteLine("Dogs is now face up in front of {0}", hunterUsingItem.Name()); game.Hunters[(int)hunterUsingItem].SetDogsFaceUp(true); AddItemCardToDraculaKnownCardsIfNotAlreadyKnown(game, game.Hunters[(int)hunterUsingItem], Item.Dogs); break; case Item.LocalRumors: var trailIndex = -1; Console.WriteLine( "In which trail position (1-6) or Catacombs position (7-9) would you like to reveal an Encounter?"); while (trailIndex == -1) { if (int.TryParse(Console.ReadLine(), out trailIndex)) { if (trailIndex < 1 || trailIndex > 9) { trailIndex = -1; } } } if (trailIndex < 7) { game.Dracula.RevealEncountersAtPositionInTrail(trailIndex - 1); } else { if (game.Dracula.Catacombs[trailIndex - 7] != null && game.Dracula.Catacombs[trailIndex - 7].EncounterTiles.Count() > 1) { var encounterIndex = -1; while (encounterIndex == -1) { Console.WriteLine("Which Encounter would you like to reveal? 1 or 2"); if (int.TryParse(Console.ReadLine(), out encounterIndex)) { if (encounterIndex < 1 || encounterIndex > 2) { encounterIndex = -1; } } } game.Dracula.RevealEncounterAtPositionInTrail(game, trailIndex - 1, encounterIndex - 1); } else { game.Dracula.RevealEncountersAtPositionInTrail(trailIndex - 1); } } game.Hunters[(int)hunterUsingItem].DiscardItem(game, Item.LocalRumors); DrawGameState(game); break; case Item.HolyWater: UseHolyWaterOnHunter(game, hunterUsingItem); game.Hunters[(int)hunterUsingItem].DiscardItem(game, Item.HolyWater); break; case Item.FastHorse: Console.WriteLine("{0} may travel two roads this turn", hunterUsingItem.Name()); game.Hunters[(int)hunterUsingItem].DiscardItem(game, Item.FastHorse); break; case Item.HeavenlyHost: Console.WriteLine("Heavenly Host placed in {0}", game.Hunters[(int)hunterUsingItem].CurrentLocation.Name()); PlaceHeavenlyHostIn(game, game.Hunters[(int)hunterUsingItem].CurrentLocation); game.Hunters[(int)hunterUsingItem].DiscardItem(game, Item.HeavenlyHost); break; default: Console.WriteLine("It is not appropriate to use {0} at this time", itemBeingUsed.Name()); break; } CheckForCardsRevealedForBeingBitten(game); }
public void LikelihoodOfHavingItemOfType_1ItemKnown_Returns1() { GameState game = new GameState(); ItemCard knife = game.ItemDeck.Find(card => card.Item == Item.Knife); vanHelsing.DrawItemCard(); vanHelsing.ItemsKnownToDracula.Add(knife); game.ItemDeck.Remove(knife); Assert.AreEqual(1, vanHelsing.LikelihoodOfHavingItemOfType(game, Item.Knife)); }
/// <summary> /// Adds and removes people from the given Hunter's group /// </summary> /// <param name="game">The GameState</param> /// <param name="hunterIndex">A string to be converted to the Hunter with whom to set up a group</param> private static void SetupGroup(GameState game, string hunterIndex) { var hunterFormingGroup = Hunter.Nobody; int index; if (int.TryParse(hunterIndex, out index)) { hunterFormingGroup = game.GetHunterFromInt(index); } var line = ""; while (hunterFormingGroup == Hunter.Nobody && index != -1) { Console.WriteLine( "Who is forming a group? {0}= {1}, {2}= {3}, {4}= {5} (Mina Harker cannot lead a group, -1 to cancel)", (int)Hunter.LordGodalming, Hunter.LordGodalming.Name(), (int)Hunter.DrSeward, Hunter.DrSeward.Name(), (int)Hunter.VanHelsing, Hunter.VanHelsing.Name()); line = Console.ReadLine(); if (int.TryParse(line, out index)) { if (index == -1) { Console.WriteLine("Cancelled"); return; } if (index == 4) { Console.WriteLine("Mina Harker cannot lead a group, add her to someone else's group instead"); } else { hunterFormingGroup = game.GetHunterFromInt(index); Console.WriteLine(hunterFormingGroup.Name()); } } else { Console.WriteLine("I didn't understand that"); } } while (index != -1) { Console.WriteLine("These are the people in {0}'s group:", hunterFormingGroup.Name()); foreach (var h in game.Hunters[(int)hunterFormingGroup].HuntersInGroup) { if (h != hunterFormingGroup) { Console.WriteLine(h.Name()); } } var hunterToAddOrRemove = Hunter.Nobody; while (hunterToAddOrRemove == Hunter.Nobody && index != -1) { Console.WriteLine( "Who is joining or leaving {0}'s group? {1}= {2}, {3}= {4}, {5}= {6} (Lord Godalming must lead any group he is in, -1 to cancel)", hunterFormingGroup.Name(), (int)Hunter.DrSeward, Hunter.DrSeward.Name(), (int)Hunter.VanHelsing, Hunter.VanHelsing.Name(), (int)Hunter.MinaHarker, Hunter.MinaHarker.Name()); line = Console.ReadLine(); if (int.TryParse(line, out index)) { if (index == -1) { Console.WriteLine("Cancelled"); return; } if (index == 1) { Console.WriteLine("Lord Godalming must lead any group he is in"); } else { hunterToAddOrRemove = game.GetHunterFromInt(index); Console.WriteLine(hunterFormingGroup.Name()); } } else { Console.WriteLine("I didn't understand that"); } } if ((int)hunterToAddOrRemove < (int)hunterFormingGroup) { Console.WriteLine("{0} cannot join {1}'s group, instead add {1} to {0}'s group", hunterToAddOrRemove.Name(), hunterFormingGroup.Name()); } else if (hunterToAddOrRemove == hunterFormingGroup) { Console.WriteLine("{0} is already in his own group, of course!", hunterFormingGroup.Name()); } else if (game.Hunters[(int)hunterFormingGroup].HuntersInGroup.Contains(hunterToAddOrRemove)) { game.Hunters[(int)hunterFormingGroup].HuntersInGroup.Remove(hunterToAddOrRemove); } else { game.Hunters[(int)hunterFormingGroup].HuntersInGroup.Add(hunterToAddOrRemove); } } }
/// <summary> /// Draws the gamestate on the screen /// </summary> /// <param name="game">The GameState</param> private static void DrawGameState(GameState game) { // line 1 Console.WriteLine("Trail Catacombs Time Vampires Resolve Dracula Ally Hunter Ally"); // line 2 for (var i = 5; i >= 0; i--) { if (game.Dracula.Trail[i] != null) { Console.ForegroundColor = game.Dracula.Trail[i].DraculaCards.First().Color; if (game.Dracula.Trail[i].DraculaCards.First().IsRevealed) { Console.Write(game.Dracula.Trail[i].DraculaCards.First().Abbreviation + " "); } else { Console.Write("### "); } } else { Console.Write(" "); } } Console.Write(" "); for (var i = 0; i < 3; i++) { if (game.Dracula.Catacombs[i] != null) { Console.ForegroundColor = game.Dracula.Catacombs[i].DraculaCards.First().Color; if (game.Dracula.Catacombs[i].DraculaCards.First().IsRevealed) { Console.Write(game.Dracula.Catacombs[i].DraculaCards.First().Abbreviation + " "); } else { Console.Write("### "); } } else { Console.Write(" "); } } switch (game.TimeOfDay) { case TimeOfDay.Dawn: case TimeOfDay.Dusk: Console.ForegroundColor = ConsoleColor.DarkYellow; break; case TimeOfDay.Noon: Console.ForegroundColor = ConsoleColor.Yellow; break; case TimeOfDay.Midnight: Console.ForegroundColor = ConsoleColor.Blue; break; case TimeOfDay.Twilight: case TimeOfDay.SmallHours: Console.ForegroundColor = ConsoleColor.DarkBlue; break; } Console.Write(" {0}", game.TimeOfDay.Name()); Console.ResetColor(); for (var i = game.TimeOfDay.Name().Length; i < 14; i++) { Console.Write(" "); } Console.Write(game.Vampires); for (var i = game.Vampires.ToString().Length; i < 11; i++) { Console.Write(" "); } Console.Write(game.Resolve); for (var i = game.Resolve.ToString().Length; i < 10; i++) { Console.Write(" "); } if (game.DraculaAlly != null) { Console.Write(game.DraculaAlly.Event.Name().Substring(0, 3).ToUpper()); } else { Console.Write(" "); } Console.Write(" "); if (game.HunterAlly != null) { Console.Write(game.HunterAlly.Event.Name().Substring(0, 3).ToUpper()); } Console.WriteLine(""); // line 3 for (var i = 5; i >= 0; i--) { if (game.Dracula.Trail[i] != null && game.Dracula.Trail[i].DraculaCards.Count() > 1) { Console.ForegroundColor = game.Dracula.Trail[i].DraculaCards[1].Color; if (game.Dracula.Trail[i].DraculaCards[1].IsRevealed) { Console.Write(game.Dracula.Trail[i].DraculaCards[1].Abbreviation + " "); } else { Console.Write("### "); } } else { Console.Write(" "); } } Console.Write(" "); for (var i = 0; i < 3; i++) { if (game.Dracula.Catacombs[i] != null && game.Dracula.Catacombs[i].EncounterTiles.Count() > 0) { if (game.Dracula.Catacombs[i].EncounterTiles.First().IsRevealed) { Console.ResetColor(); Console.Write(game.Dracula.Catacombs[i].EncounterTiles.First().Abbreviation + " "); } else { Console.ForegroundColor = ConsoleColor.DarkYellow; Console.Write(" ■ "); } } else { Console.Write(" "); } } Console.WriteLine(""); // line 4 for (var i = 5; i >= 0; i--) { if (game.Dracula.Trail[i] != null && game.Dracula.Trail[i].EncounterTiles.Count() > 0) { if (game.Dracula.Trail[i].EncounterTiles.First().IsRevealed) { Console.ResetColor(); Console.Write(game.Dracula.Trail[i].EncounterTiles.First().Abbreviation + " "); } else { Console.ForegroundColor = ConsoleColor.DarkYellow; Console.Write(" ■ "); } } else { Console.Write(" "); } } Console.Write(" "); for (var i = 0; i < 3; i++) { if (game.Dracula.Catacombs[i] != null && game.Dracula.Catacombs[i].EncounterTiles.Count() > 1) { if (game.Dracula.Catacombs[i].EncounterTiles[1].IsRevealed) { Console.ResetColor(); Console.Write(game.Dracula.Catacombs[i].EncounterTiles[1].Abbreviation + " "); } else { Console.ForegroundColor = ConsoleColor.DarkYellow; Console.Write(" ■ "); } } else { Console.Write(" "); } } Console.ResetColor(); Console.Write(" Dracula Blood Dracula Events"); Console.WriteLine(); // line 5 Console.Write(" {0} {1}", game.Dracula.Blood, game.Dracula.Blood > 9 ? game.Dracula.EventHand.Count().ToString() : (" " + game.Dracula.EventHand.Count())); Console.WriteLine(); Console.ResetColor(); }
public void LikelihoodOfHavingItemOfType_1UnknownItem_Returns5OutOf40() { GameState game = new GameState(); vanHelsing.DrawItemCard(); Assert.AreEqual( 5F / 40F, vanHelsing.LikelihoodOfHavingItemOfType(game, Item.Knife)); }
/// <summary> /// Determines if Dracula is playing Wild Horses at the start of a combat /// </summary> /// <param name="game">The GameState</param> /// <param name="logic">The artificial intelligence component</param> /// <returns>True if Dracula successfully plays Wild Horses</returns> private static bool DraculaIsPlayingWildHorses(GameState game, DecisionMaker logic) { if (logic.ChooseToPlayWildHorses(game)) { Console.WriteLine("Dracula is playing Wild Horses to control your movement"); game.Dracula.DiscardEvent(Event.WildHorses, game.EventDiscard); if (HunterPlayingGoodLuckToCancelDraculaEvent(game, Event.WildHorses, Event.WildHorses, logic) > 0) { Console.WriteLine("Wild Horses cancelled"); return false; } return true; } return false; }
/// <summary> /// Handles the situation when a Hunter must reveal all Items to Dracula /// </summary> /// <param name="game">The GameState</param> /// <param name="victim">The Hunter revealing Items</param> private static void DraculaLooksAtAllHuntersItems(GameState game, HunterPlayer victim) { game.ItemDeck.AddRange(victim.ItemsKnownToDracula); victim.ItemsKnownToDracula.Clear(); for (var i = 0; i < victim.ItemCount; i++) { Console.WriteLine("What is the name of the Item being revealed?"); var itemRevealed = Item.None; while (itemRevealed == Item.None) { itemRevealed = Enumerations.GetItemFromString(Console.ReadLine()); } AddItemCardToDraculaKnownCards(game, victim, itemRevealed); } }
/// <summary> /// Asks the user to name an Item and then discards it from that Hunter /// </summary> /// <param name="game">The GameState</param> /// <param name="hunter">The Hunter discarding an Item</param> private static bool DiscardUnknownItemFromHunter(GameState game, HunterPlayer hunter) { Console.WriteLine("Name the Item being discarded (cancel to cancel)"); var itemBeingDiscarded = Item.None; var line = ""; while (itemBeingDiscarded == Item.None && line.ToLower() != "cancel") { line = Console.ReadLine(); itemBeingDiscarded = Enumerations.GetItemFromString(line); } if (line.ToLower() != "cancel") { hunter.DiscardItem(game, itemBeingDiscarded); return true; } else { Console.WriteLine("No Item discarded"); return false; } }
/// <summary> /// Checks if Dracula is playing Sensationalist Press to prevent a Location card from being revealed /// </summary> /// <param name="game">The GameState</param> /// <param name="location">The Location being revealed</param> /// <param name="logic">The artificial intelligence component</param> /// <returns>True if Dracula successfully plays Sensationalist Press</returns> private static bool DraculaIsPlayingSensationalistPressToPreventRevealingLocation(GameState game, Location location, DecisionMaker logic) { if (logic.ChooseToPlaySensationalistPress(game, location)) { Console.WriteLine("Dracula is playing Sensationalist Press"); game.Dracula.DiscardEvent(Event.SensationalistPress, game.EventDiscard); if (HunterPlayingGoodLuckToCancelDraculaEvent(game, Event.SensationalistPress, Event.SensationalistPress, logic) > 0) { Console.WriteLine("Sensationalist Press cancelled"); return false; } return true; } return false; }
/// <summary> /// Resolves a Hunter using the Holy Water Item or the Holy Water font at St. Joseph & St. Mary /// </summary> /// <param name="game">The GameState</param> /// <param name="hunterReceivingHolyWater">The Hunter receiving the Holy Water effect</param> private static void UseHolyWaterOnHunter(GameState game, Hunter hunterReceivingHolyWater) { if (hunterReceivingHolyWater == Hunter.MinaHarker) { Console.WriteLine("Mina's bite cannot be cured"); return; } Console.WriteLine("Roll a die and enter the result"); var dieRoll = 0; while (dieRoll == 0) { if (int.TryParse(Console.ReadLine(), out dieRoll)) { if (dieRoll < 1 || dieRoll > 7) { dieRoll = 0; } } } switch (dieRoll) { case 1: Console.WriteLine("{0} loses 2 health", hunterReceivingHolyWater.Name()); game.Hunters[(int)hunterReceivingHolyWater].AdjustHealth(-2); CheckForHunterDeath(game); break; case 2: case 3: case 4: Console.WriteLine("Nothing happens"); break; case 5: case 6: Console.WriteLine("{0} is cured of a Bite", hunterReceivingHolyWater.Name()); game.Hunters[(int)hunterReceivingHolyWater].AdjustBites(-1); break; } }
private static void UseHolyWaterAtHospital(GameState game, string hunterIndex) { var hunterUsingHolyWater = Hunter.Nobody; int index = -2; if (int.TryParse(hunterIndex, out index)) { hunterUsingHolyWater = game.GetHunterFromInt(index); } var line = ""; while (hunterUsingHolyWater == Hunter.Nobody && index != -1) { Console.WriteLine("Who is using the Holy Water font? {0}= {1}, {2}= {3}, {4}= {5}, {6}= {7} (-1 to cancel)", (int)Hunter.LordGodalming, Hunter.LordGodalming.Name(), (int)Hunter.DrSeward, Hunter.DrSeward.Name(), (int)Hunter.VanHelsing, Hunter.VanHelsing.Name(), (int)Hunter.MinaHarker, Hunter.MinaHarker.Name()); line = Console.ReadLine(); if (int.TryParse(line, out index)) { if (index < -1 || index > 4) { index = -2; } if (index == -1) { Console.WriteLine("Cancelled"); return; } hunterUsingHolyWater = game.GetHunterFromInt(index); Console.WriteLine(hunterUsingHolyWater.Name()); } else { Console.WriteLine("I didn't understand that"); } } UseHolyWaterOnHunter(game, hunterUsingHolyWater); }
/// <summary> /// Asks the user to name an Event and then discards it from that Hunter /// </summary> /// <param name="game">The GameState</param> /// <param name="hunter">The Hunter discarding an Event</param> private static void DiscardUnknownEventFromHunter(GameState game, HunterPlayer hunter) { Console.WriteLine("Name the Event being discarded"); var eventBeingDiscarded = Event.None; while (eventBeingDiscarded == Event.None) { eventBeingDiscarded = Enumerations.GetEventFromString(Console.ReadLine()); } hunter.DiscardEvent(game, eventBeingDiscarded); }
private static void TradeCardsBetweenHunters(GameState game, string firstHunterIndex, string secondHunterIndex) { var firstHunterTrading = Hunter.Nobody; int index = -2; if (int.TryParse(firstHunterIndex, out index)) { firstHunterTrading = game.GetHunterFromInt(index); } var line = ""; while (firstHunterTrading == Hunter.Nobody && index != -1) { Console.WriteLine("Who is trading? {0}= {1}, {2}= {3}, {4}= {5}, {6}= {7} (-1 to cancel)", (int)Hunter.LordGodalming, Hunter.LordGodalming.Name(), (int)Hunter.DrSeward, Hunter.DrSeward.Name(), (int)Hunter.VanHelsing, Hunter.VanHelsing.Name(), (int)Hunter.MinaHarker, Hunter.MinaHarker.Name()); line = Console.ReadLine(); if (int.TryParse(line, out index)) { if (index < -1 || index > 4) { index = -2; } if (index == -1) { Console.WriteLine("Cancelled"); return; } firstHunterTrading = game.GetHunterFromInt(index); Console.WriteLine(firstHunterTrading.Name()); } else { Console.WriteLine("I didn't understand that"); } } var secondHunterTrading = Hunter.Nobody; index = -2; if (int.TryParse(secondHunterIndex, out index)) { secondHunterTrading = game.GetHunterFromInt(index); } line = ""; while (secondHunterTrading == Hunter.Nobody && index != -1) { Console.WriteLine("Who else is trading? {0}= {1}, {2}= {3}, {4}= {5}, {6}= {7} (-1 to cancel)", (int)Hunter.LordGodalming, Hunter.LordGodalming.Name(), (int)Hunter.DrSeward, Hunter.DrSeward.Name(), (int)Hunter.VanHelsing, Hunter.VanHelsing.Name(), (int)Hunter.MinaHarker, Hunter.MinaHarker.Name()); line = Console.ReadLine(); if (int.TryParse(line, out index)) { if (index < -1 || index > 4) { index = -2; } if (index == -1) { Console.WriteLine("Cancelled"); return; } secondHunterTrading = game.GetHunterFromInt(index); Console.WriteLine(secondHunterTrading.Name()); } else { Console.WriteLine("I didn't understand that"); } } line = ""; int answer = -1; while (answer < 0) { Console.WriteLine("How many Items does {0} now have?", firstHunterTrading.Name()); Int32.TryParse(line, out answer); } game.Hunters[(int)firstHunterTrading].SetItemCount(answer); line = ""; answer = -1; while (answer < 0) { Console.WriteLine("How many Items does {0} now have?", secondHunterTrading.Name()); Int32.TryParse(line, out answer); } game.Hunters[(int)secondHunterTrading].SetItemCount(answer); var allKnownItems = new List<ItemCard>(); allKnownItems.AddRange(game.Hunters[(int)firstHunterTrading].ItemsKnownToDracula); allKnownItems.AddRange(game.Hunters[(int)secondHunterTrading].ItemsKnownToDracula); var allPartiallyKnownItems = new List<ItemCard>(); allPartiallyKnownItems.AddRange(game.Hunters[(int)firstHunterTrading].ItemsPartiallyKnownToDracula); allPartiallyKnownItems.AddRange(game.Hunters[(int)secondHunterTrading].ItemsPartiallyKnownToDracula); var allItemChances = new List<float>(); allItemChances.AddRange(game.Hunters[(int)firstHunterTrading].PartiallyKnownItemChances); allItemChances.AddRange(game.Hunters[(int)secondHunterTrading].PartiallyKnownItemChances); var newAllPartiallyKnownItems = new List<ItemCard>(); var newAllItemChances = new List<float>(); index = -1; foreach (var i in allPartiallyKnownItems) { index++; if (!newAllPartiallyKnownItems.Any(card => card.Item == i.Item)) { float newChance = 0F; for (int j = index; j < allPartiallyKnownItems.Count(); j++) { if (i.Item == allPartiallyKnownItems[j].Item) { newChance += allItemChances[j]; } } newAllPartiallyKnownItems.Add(i); newAllItemChances.Add(newChance); } } allPartiallyKnownItems = newAllPartiallyKnownItems; allItemChances = newAllItemChances; if (game.Hunters[(int)firstHunterTrading].ItemCount == 0) { game.Hunters[(int)firstHunterTrading].ItemsKnownToDracula.Clear(); game.Hunters[(int)firstHunterTrading].ItemsPartiallyKnownToDracula.Clear(); game.Hunters[(int)firstHunterTrading].PartiallyKnownItemChances.Clear(); game.Hunters[(int)secondHunterTrading].ItemsKnownToDracula = allKnownItems; game.Hunters[(int)secondHunterTrading].ItemsPartiallyKnownToDracula = allPartiallyKnownItems; game.Hunters[(int)secondHunterTrading].PartiallyKnownItemChances = allItemChances; } else if (game.Hunters[(int)secondHunterTrading].ItemCount == 0) { game.Hunters[(int)secondHunterTrading].ItemsKnownToDracula.Clear(); game.Hunters[(int)secondHunterTrading].ItemsPartiallyKnownToDracula.Clear(); game.Hunters[(int)secondHunterTrading].PartiallyKnownItemChances.Clear(); game.Hunters[(int)firstHunterTrading].ItemsKnownToDracula = allKnownItems; game.Hunters[(int)firstHunterTrading].ItemsPartiallyKnownToDracula = allPartiallyKnownItems; game.Hunters[(int)firstHunterTrading].PartiallyKnownItemChances = allItemChances; } else { game.Hunters[(int)firstHunterTrading].ItemsKnownToDracula.Clear(); game.Hunters[(int)secondHunterTrading].ItemsKnownToDracula.Clear(); game.Hunters[(int)firstHunterTrading].ItemsPartiallyKnownToDracula.Clear(); game.Hunters[(int)secondHunterTrading].ItemsPartiallyKnownToDracula.Clear(); game.Hunters[(int)firstHunterTrading].ItemsPartiallyKnownToDracula.AddRange(allKnownItems); game.Hunters[(int)secondHunterTrading].ItemsPartiallyKnownToDracula.AddRange(allKnownItems); foreach (var i in allKnownItems) { game.Hunters[(int)firstHunterTrading].PartiallyKnownItemChances.Add(0.5F); game.Hunters[(int)secondHunterTrading].PartiallyKnownItemChances.Add(0.5F); } foreach (var f in allItemChances) { game.Hunters[(int)firstHunterTrading].PartiallyKnownItemChances.Add(0.5F * f); game.Hunters[(int)secondHunterTrading].PartiallyKnownItemChances.Add(0.5F * f); } } index = -1; foreach (var i in game.Hunters[(int)firstHunterTrading].ItemsPartiallyKnownToDracula) { index++; while (game.Hunters[(int)firstHunterTrading].PartiallyKnownItemChances[index] >= 1F) { game.Hunters[(int)firstHunterTrading].ItemsKnownToDracula.Add(i); game.Hunters[(int)firstHunterTrading].PartiallyKnownItemChances[index]--; } } index = -1; foreach (var f in game.Hunters[(int)firstHunterTrading].PartiallyKnownItemChances) { index++; if (f == 0) { game.Hunters[(int)firstHunterTrading].ItemsPartiallyKnownToDracula[index] = null; } } game.Hunters[(int)firstHunterTrading].ItemsPartiallyKnownToDracula.RemoveAll(i => i == null); game.Hunters[(int)firstHunterTrading].PartiallyKnownItemChances.RemoveAll(f => f == 0); index = -1; foreach (var i in game.Hunters[(int)secondHunterTrading].ItemsPartiallyKnownToDracula) { index++; while (game.Hunters[(int)secondHunterTrading].PartiallyKnownItemChances[index] >= 1F) { game.Hunters[(int)secondHunterTrading].ItemsKnownToDracula.Add(i); game.Hunters[(int)secondHunterTrading].PartiallyKnownItemChances[index]--; } } index = -1; foreach (var f in game.Hunters[(int)secondHunterTrading].PartiallyKnownItemChances) { index++; if (f == 0) { game.Hunters[(int)secondHunterTrading].ItemsPartiallyKnownToDracula[index] = null; } } game.Hunters[(int)secondHunterTrading].ItemsPartiallyKnownToDracula.RemoveAll(i => i == null); game.Hunters[(int)secondHunterTrading].PartiallyKnownItemChances.RemoveAll(f => f == 0); CheckForDiscardRequired(game); }
/// <summary> /// For spending a Resolve point by a Hunter /// </summary> /// <param name="game">The GameState</param> /// <param name="resolveName">A string to be converted to the ResolveAbility being used</param> /// <param name="hunterIndex">A string to be converted to the Hunter spending Resolve</param> /// <param name="logic">The artificial intelligence component</param> private static void SpendResolve(GameState game, string resolveName, string hunterIndex, DecisionMaker logic) { var hunterSpendingResolve = Hunter.Nobody; int index = -2; if (int.TryParse(hunterIndex, out index)) { hunterSpendingResolve = game.GetHunterFromInt(index); } var line = ""; while (hunterSpendingResolve == Hunter.Nobody && index != -1) { Console.WriteLine("Who is spending resolve? {0}= {1}, {2}= {3}, {4}= {5}, {6}= {7} (-1 to cancel)", (int)Hunter.LordGodalming, Hunter.LordGodalming.Name(), (int)Hunter.DrSeward, Hunter.DrSeward.Name(), (int)Hunter.VanHelsing, Hunter.VanHelsing.Name(), (int)Hunter.MinaHarker, Hunter.MinaHarker.Name()); line = Console.ReadLine(); if (int.TryParse(line, out index)) { if (index < -1 || index > 4) { index = -2; } if (index == -1) { Console.WriteLine("Cancelled"); return; } hunterSpendingResolve = game.GetHunterFromInt(index); Console.WriteLine(hunterSpendingResolve.Name()); } else { Console.WriteLine("I didn't understand that"); } } var ability = Enumerations.GetResolveAbilityFromString(resolveName); while (ability == ResolveAbility.None && line.ToLower() != "cancel") { Console.WriteLine("What resolve ability is {0} using?", hunterSpendingResolve.Name()); line = Console.ReadLine(); if (line.ToLower() == "cancel") { Console.WriteLine("Cancelled"); return; } ability = Enumerations.GetResolveAbilityFromString(line); } switch (ability) { case ResolveAbility.NewspaperReports: PlayNewsPaperReports(game, hunterSpendingResolve, logic); break; case ResolveAbility.InnerStrength: PlayInnerStrength(game, hunterSpendingResolve); break; case ResolveAbility.SenseOfEmergency: PlaySenseOfEmergency(game, hunterSpendingResolve, logic); break; } game.AdjustResolve(-1); }
/// <summary> /// Determines if Dracula is playing Trap against a Hunter at the start of a combat /// </summary> /// <param name="game">The GameState</param> /// <param name="huntersInvolved">The list of Hunters involved in the combat</param> /// <param name="opponent">The Opponent</param> /// <param name="logic">The artificial intelligence component</param> /// <returns>True if Dracula successfully plays Trap</returns> private static bool DraculaIsPlayingTrap(GameState game, List<HunterPlayer> huntersInvolved, Opponent opponent, DecisionMaker logic) { if (logic.ChooseToPlayTrap(game, huntersInvolved, opponent)) { Console.WriteLine("Dracula is playing Trap"); game.Dracula.DiscardEvent(Event.Trap, game.EventDiscard); if (HunterPlayingGoodLuckToCancelDraculaEvent(game, Event.Trap, Event.Trap, logic) > 0) { Console.WriteLine("Trap cancelled"); return false; } return true; } return false; }
/// <summary> /// Provides details about various aspects of the gamestate that are not otherwise displayed on the screen /// </summary> /// <param name="game">The GameState</param> private static void DisplayState(GameState game, string argument1, DecisionMaker logic) { Console.WriteLine("The state of the game:"); foreach (var h in game.Hunters) { if (h != null) { Console.WriteLine("{0} is in {1} with {2} Items and {3} Events, on {4} health with {5} bites{6}", h.Hunter.Name(), h.CurrentLocation.Name(), h.ItemCount, h.EventCount, h.Health, h.BiteCount, h.HasDogsFaceUp ? " and has Dogs face up" : ""); if (h.EncountersInFrontOfPlayer.Any()) { Console.Write("These Encounter tiles are in front of {0}: ", h.Hunter.Name()); foreach (EncounterTile enc in h.EncountersInFrontOfPlayer) { Console.Write("{0}, ", enc.Encounter.Name()); } Console.WriteLine(""); } if (h.ItemsKnownToDracula.Any() && argument1 == "debug") { Console.Write("These Items held by {0} are known to Dracula: ", h.Hunter.Name()); foreach (var i in h.ItemsKnownToDracula) { Console.Write("{0}, ", i.Item.Name()); } Console.WriteLine(""); } if (h.EventsKnownToDracula.Any() && argument1 == "debug") { Console.Write("These Events held by {0} are known to Dracula: ", h.Hunter.Name()); foreach (var e in h.EventsKnownToDracula) { Console.Write("{0}, ", e.Event.Name()); } Console.WriteLine(""); } } } if (argument1 == "debug") { Console.WriteLine("Dracula is in {0} with {1} blood and has {2} Events", game.Dracula.CurrentLocation.Name(), game.Dracula.Blood, game.Dracula.EventHand.Count()); Console.Write("Dracula is holding these Encounter tiles: "); foreach (var enc in game.Dracula.EncounterHand) { Console.Write("{0} ", enc.Encounter.Name()); } Console.WriteLine(""); if (game.Dracula.EventHand.Count() > 0) { Console.Write("Dracula is holding these Event cards: "); foreach (var e in game.Dracula.EventHand) { Console.Write("{0} ", e.Event.Name()); } } } Console.WriteLine(""); Console.WriteLine("These Items are in the discard:"); foreach (var i in game.ItemDiscard) { Console.WriteLine(i.Item.Name()); } Console.WriteLine("These Events are in the discard:"); foreach (var e in game.EventDiscard) { Console.WriteLine(e.Event.Name()); } if (argument1 == "debug") { Console.WriteLine("There are {0} possible configurations of Dracula's trail", logic.PossibilityTree.Count()); Console.WriteLine("Dracula could be in one of {0} possible locations", logic.NumberOfPossibleCurrentLocations); Console.WriteLine("Dracula's current strategy is {0}", logic.Strategy); } }
/// <summary> /// Handles the situation when a Hunter must reveal all Event cards to Dracula /// </summary> /// <param name="game">The GameState</param> /// <param name="victim">The Hunter revealing Event cards</param> private static void DraculaLooksAtAllHuntersEvents(GameState game, HunterPlayer victim) { game.EventDeck.AddRange(victim.EventsKnownToDracula); victim.EventsKnownToDracula.Clear(); for (var i = 0; i < victim.EventCount; i++) { Console.WriteLine("What is the name of the Event being revealed?"); var eventRevealed = Event.None; while (eventRevealed == Event.None) { eventRevealed = Enumerations.GetEventFromString(Console.ReadLine()); } AddEventCardToDraculaKnownCards(game, victim, eventRevealed); } }
/// <summary> /// Determines if Dracula is playing Customs Search on a Hunter /// </summary> /// <param name="game">The GameState</param> /// <param name="hunterMoved">The Hunter who moved</param> /// <param name="origin">The original Location</param> /// <param name="logic">The artificial intelligence component</param> /// <returns>True if Dracula successfully plays Customs Search</returns> private static bool DraculaIsPlayingCustomsSearch(GameState game, Hunter hunterMoved, Location origin, DecisionMaker logic) { if (logic.ChooseToPlayCustomsSearch(game, hunterMoved, origin)) { Console.WriteLine("Dracula is playing Customs Search"); game.Dracula.DiscardEvent(Event.CustomsSearch, game.EventDiscard); if (HunterPlayingGoodLuckToCancelDraculaEvent(game, Event.CustomsSearch, Event.CustomsSearch, logic) > 0) { Console.WriteLine("Customs Search cancelled"); return false; } return true; } return false; }
/// <summary> /// Adds 1 to the count of cards of the given type to the given Hunter /// </summary> /// <param name="game">The GameState</param> /// <param name="cardType">Item or Event</param> /// <param name="hunterIndex">A string to be converted to the Hunter drawing the card</param> private static void DrawCard(GameState game, string cardType, string hunterIndex) { var index = 0; var hunterToDraw = Hunter.Nobody; if (int.TryParse(hunterIndex, out index)) { hunterToDraw = game.GetHunterFromInt(index); } var line = ""; while (hunterToDraw == Hunter.Nobody && index != -1) { Console.WriteLine("Who is drawing a card? {0}= {1}, {2}= {3}, {4}= {5}, {6}= {7} (-1 to cancel)", (int)Hunter.LordGodalming, Hunter.LordGodalming.Name(), (int)Hunter.DrSeward, Hunter.DrSeward.Name(), (int)Hunter.VanHelsing, Hunter.VanHelsing.Name(), (int)Hunter.MinaHarker, Hunter.MinaHarker.Name()); line = Console.ReadLine(); if (int.TryParse(line, out index)) { if (index == -1) { Console.WriteLine("Cancelled"); return; } hunterToDraw = game.GetHunterFromInt(index); Console.WriteLine(hunterToDraw.Name()); } else { Console.WriteLine("I didn't understand that"); } } do { switch (cardType) { case "i": case "item": game.Hunters[index].DrawItemCard(); Console.WriteLine("{0} drew an Item card, up to {1}", hunterToDraw.Name(), game.Hunters[index].ItemCount); return; case "e": case "event": game.Hunters[index].DrawEventCard(); Console.WriteLine("{0} drew an Event card, up to {1}", hunterToDraw.Name(), game.Hunters[index].EventCount); return; default: Console.WriteLine("What type of card is {0} drawing?", hunterToDraw.Name()); cardType = Console.ReadLine().ToLower(); break; } } while (cardType != "cancel"); Console.WriteLine("Cancelled"); }
/// <summary> /// Adds an Event card to the list of cards known to Dracula /// </summary> /// <param name="game">The GameState</param> /// <param name="victim">The Hunter who has revealed an Event</param> /// <param name="eventRevealed">The Event revealed by the Hunter</param> private static void AddEventCardToDraculaKnownCards(GameState game, HunterPlayer victim, Event eventRevealed) { var eventCardRevealed = game.EventDeck.Find(card => card.Event == eventRevealed); victim.EventsKnownToDracula.Add(eventCardRevealed); game.EventDeck.Remove(eventCardRevealed); }
public void LikelihoodOfHavingItemOfType_1UnknownItemIKnownItemDifferentType_Returns3OutOf39() { GameState game = new GameState(); vanHelsing.DrawItemCard(); vanHelsing.DrawItemCard(); ItemCard knife = game.ItemDeck.Find(card => card.Item == Item.Knife); vanHelsing.ItemsKnownToDracula.Add(knife); Assert.AreEqual(3F / 40F, vanHelsing.LikelihoodOfHavingItemOfType(game, Item.Crucifix)); }
/// <summary> /// Determines if Dracula is playing Devilish Power to cancel an Event played by a Hunter /// </summary> /// <param name="game">The GameState</param> /// <param name="eventBeingPlayedNow">The Event being played now</param> /// <param name="eventInitiallyPlayed">The Event initially played at the beginning of this exchange</param> /// <param name="logic">The artificial intelligence component</param> /// <returns>True if Dracula successfully plays Devilish Power</returns> private static bool DraculaIsPlayingDevilishPowerToCancelEvent(GameState game, Event eventBeingPlayedNow, Event eventInitiallyPlayed, DecisionMaker logic, HunterPlayer hunterPlayingEvent) { if (logic.ChooseToCancelEventWithDevilishPower(game, eventBeingPlayedNow, eventInitiallyPlayed, hunterPlayingEvent)) { Console.WriteLine("Dracula is playing Devilish Power to cancel {0}", eventBeingPlayedNow.Name()); game.Dracula.DiscardEvent(Event.DevilishPower, game.EventDiscard); if (HunterPlayingGoodLuckToCancelDraculaEvent(game, Event.DevilishPower, eventInitiallyPlayed, logic) > 0) { return false; } return true; } return false; }
public void LikelihoodOfHavingItemOfType_NoItems_Returns0() { GameState game = new GameState(); Assert.AreEqual(0, vanHelsing.LikelihoodOfHavingItemOfType(game, Item.Crucifix)); }
/// <summary> /// Checks to see if Dracula is playing False Tip-off when a Hunter attempts to catch a train by rolling the die /// </summary> /// <param name="game">The GameState</param> /// <param name="logic">The artificial intelligence component</param> /// <returns>True if Dracula successfully plays False Tip-off</returns> private static bool DraculaIsPlayingFalseTipoffToDelayHunter(GameState game, DecisionMaker logic) { if (logic.ChooseToDelayHunterWithFalseTipoff(game)) { Console.WriteLine("Dracula is playing False Tip-off to delay the train"); game.Dracula.DiscardEvent(Event.FalseTipoff, game.EventDiscard); if (HunterPlayingGoodLuckToCancelDraculaEvent(game, Event.FalseTipoff, Event.FalseTipoff, logic) > 0 || HunterPlayingCharteredCarriageToCancelFalseTipOff(game, Event.FalseTipoff, Event.FalseTipoff, logic) > 0) { return false; } return true; } return false; }
public void BeforeAll() { game = new GameState(); }
/// <summary> /// Determines if Dracula is playing Rage against a Hunter at the start of a combat /// </summary> /// <param name="game">The GameState</param> /// <param name="huntersInvolved">The list of Hunters involved in the combat</param> /// <param name="logic">The artificial intelligence component</param> /// <returns>True if Dracula successfully plays Rage</returns> private static Hunter DraculaIsPlayingRageAgainstHunter(GameState game, List<HunterPlayer> huntersInvolved, DecisionMaker logic) { var rageTarget = logic.ChooseToPlayRage(game, huntersInvolved); if (rageTarget != Hunter.Nobody) { Console.WriteLine("Dracula is playing Rage against {0}", rageTarget.Name()); game.Dracula.DiscardEvent(Event.Rage, game.EventDiscard); if (HunterPlayingGoodLuckToCancelDraculaEvent(game, Event.Rage, Event.Rage, logic) > 0) { Console.WriteLine("Rage cancelled"); return Hunter.Nobody; } return rageTarget; } return Hunter.Nobody; }