public void DisprovedConstructorWithCardTest() { Disproved target = new Disproved(disprovingPlayer, suggestion, cardShown); Assert.AreSame(suggestion, target.Suspicion); Assert.AreSame(disprovingPlayer, target.Player); Assert.AreSame(cardShown, target.CardShown); }
public void GetConstraintsWithoutCardTest() { Disproved target = new Disproved(disprovingPlayer, suggestion); var constraints = target.GetConstraints(nodes); Assert.AreEqual(1, constraints.Count()); var c = constraints.First() as SelectionCountConstraint; Assert.IsNotNull(c); CollectionAssert.AllItemsAreUnique(c.Nodes.ToList()); Assert.AreEqual(3, c.Nodes.Count()); Assert.AreEqual(1, c.Min); Assert.AreEqual(3, c.Max); Assert.IsTrue(c.SelectionState); }
public void GetConstraintsWithCardTest() { Disproved target = new Disproved(disprovingPlayer, suggestion, cardShown); var constraints = target.GetConstraints(nodes); Assert.AreEqual(1, constraints.Count()); var c = constraints.First() as SelectionCountConstraint; Assert.IsNotNull(c); Assert.AreEqual(1, c.Nodes.Count()); Assert.AreSame((from n in nodes where n.Card == cardShown select n).First(), c.Nodes.First()); Assert.AreEqual(1, c.Min); Assert.AreEqual(1, c.Max); Assert.IsTrue(c.SelectionState); }
/// <summary> /// Conducts the user through entering a suggestion. /// </summary> private void Suggestion() { Suspicion suggestion = this.GetSuggestion(); if (suggestion == null) { return; } var deducedClues = new List<Clue>(); foreach (Player opponent in this.game.PlayersInOrderAfter(this.suggestingPlayer)) { bool explicitAnswer = false; bool? disproved; // Do we already know whether this player could disprove it? if ((disproved = opponent.HasAtLeastOneOf(suggestion.Cards)).HasValue) { ConsoleHelper.WriteColor( ConsoleHelper.QuestionColor, "{0} {1} disprove {2}.", opponent.Name, disproved.Value ? "CAN" : "CANNOT", suggestion); } else { // Ask the gamer if the opponent did. switch ( ConsoleHelper.Choose( string.Format("Could {0} disprove {1}?", opponent.Name, suggestion), false, new[] { "Yes", "No", "Skip player", "Abort suggestion" })) { case 0: disproved = true; explicitAnswer = true; break; case 1: disproved = false; explicitAnswer = true; break; case 2: continue; case 3: return; } } Card alabi = null; if (this.suggestingPlayer == this.interactivePlayer && disproved.HasValue && disproved.Value) { IEnumerable<Card> possiblyShownCards = opponent.PossiblyHeldCards.Where(c => suggestion.Cards.Contains(c)); if (possiblyShownCards.Count() == 1) { ConsoleHelper.WriteColor( ConsoleHelper.QuestionColor, "{0} must have shown you {1}.", opponent, alabi = possiblyShownCards.First()); } else { alabi = ConsoleHelper.Choose( string.Format("Which card did {0} show you?", opponent), true, c => c.Name, possiblyShownCards.ToArray()); } } if (disproved.HasValue) { Clue clue; if (disproved.Value) { clue = new Disproved(opponent, suggestion, alabi); } else { clue = new CannotDisprove(opponent, suggestion); } if (!explicitAnswer) { deducedClues.Add(clue); } this.game.Clues.Add(clue); } if (disproved.HasValue && disproved.Value && this.game.Rules.DisprovalEndsTurn) { break; } } // We added clues that we could predict as explicit clues. // But if one of them were wrong (due to a mistaken answer by another player or data entry error) // we are increasing the strength of the mistake here by making a new clue based on our deductions. // So remove the deduced clues if the operator found a problem. if (deducedClues.Count > 0) { if (!ConsoleHelper.AskYesOrNo("Were the deduced answers correct?", false).Value) { deducedClues.ForEach(badClue => this.game.Clues.Remove(badClue)); Console.WriteLine("Deduced answers were removed from the set of clues. Use Force to add the correct answer and resolve conflicts."); } } }