Пример #1
0
 public void AddClueTest()
 {
     Game g = StartPresetGame();
     Player player = players[0];
     Assert.AreEqual(0, g.Clues.Count);
     var clue = new CannotDisprove(player, new Suspicion(g.Suspects.First(), g.Weapons.First(), g.Places.First()));
     g.Clues.Add(clue);
     CollectionAssert.AreEquivalent(new Clue[] { clue }, g.Clues.ToArray());
     // So the clue is added to the list of clues.  Now see that the appropriate nodes were affected.
     foreach (Node node in g.Nodes.Where(n => n.CardHolder == player && clue.Suspicion.Cards.Contains(n.Card)))
         Assert.IsFalse(node.IsSelected.Value);
 }
Пример #2
0
        public void AddSeveralCluesTest()
        {
            Game g = StartPresetGame();
            g.AutoAnalysis = false;
            Suspicion s = new Suspicion(g.Suspects.First(), g.Weapons.First(), g.Places.First());
            //Debug.WriteLine("Adding that no one has these cards: " + s.Suspect.ToString() + ", " + s.Weapon.ToString() + ", " + s.Place.ToString());
            foreach (Player p in g.Players) {
                Clue clue = new CannotDisprove(p, s);
                g.Clues.Add(clue);
            }

            Assert.AreSame(s.Suspect, g.CaseFile.Suspect);
            Assert.AreSame(s.Weapon, g.CaseFile.Weapon);
            Assert.AreSame(s.Place, g.CaseFile.Place);
        }
Пример #3
0
        /// <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.");
                }
            }
        }