示例#1
0
 public void SpyCardConstructorTest()
 {
     Player playerShowingCard = new Player("player");
     Card cardSeen = new Weapon("card");
     SpyCard target = new SpyCard(playerShowingCard, cardSeen);
     Assert.AreSame(playerShowingCard, target.Player);
     Assert.AreSame(cardSeen, target.Card);
 }
示例#2
0
 public void GetConstraintsTest()
 {
     Player playerShowingCard = new Player("test");
     Card cardSeen = new Weapon("test");
     Card anotherCard = new Suspect("test");
     Node[] nodes = new Node[] {
                        new Node(playerShowingCard, cardSeen),
                        new Node(playerShowingCard, anotherCard),
                    };
     SpyCard target = new SpyCard(playerShowingCard, cardSeen);
     var actual = target.GetConstraints(nodes);
     Assert.AreEqual(1, actual.Count());
     SelectionCountConstraint c = actual.First() as SelectionCountConstraint;
     Assert.IsNotNull(c);
     Assert.AreEqual(1, c.Min);
     Assert.AreEqual(1, c.Max);
     Assert.AreEqual(1, c.Nodes.Count());
     Assert.AreSame(nodes[0], c.Nodes.First());
 }
示例#3
0
        /// <summary>
        /// The spy.
        /// </summary>
        private void Spy()
        {
            // Display a hint to the user about which player might be the most beneficial to spy on.
            // Factors to consider include:
            // * what % of cards held by a player are still unknown? (odds of benefit)
            // * what % of the unknown cards are also unknown to the case file? (size of benefit assuming any)
            // TODO: an enhancement would be to simulate each of the unknown nodes for this player and measure
            // the size of any cascading effect.
            var stats = from p in this.game.Players
                        where p != this.interactivePlayer
                        let handSize = p.CardsHeldCount
                        let knownCardsInHand = this.game.Nodes.Count(n => n.CardHolder == p && n.IsSelected.HasValue && n.IsSelected.Value)
                        let unknownCardsInHand = handSize - knownCardsInHand
                        let possiblyRevealingCards = this.game.Nodes.Count(n => n.CardHolder == p && !n.IsSelected.HasValue)
                        let possibleCardsThatMayBeInCaseFile = this.game.Nodes.Count(n => n.CardHolder == p && !n.IsSelected.HasValue && !this.game.Nodes.First(cn => cn.CardHolder == this.game.CaseFile && cn.Card == n.Card).IsSelected.HasValue)
                        let oddsOfAnyBenefit = (float)unknownCardsInHand / p.CardsHeldCount
                        let oddsOfBenefitBeingSubstantial = possiblyRevealingCards > 0 ? ((float)possibleCardsThatMayBeInCaseFile / possiblyRevealingCards) : 0
                        let choiceStrength = oddsOfAnyBenefit * oddsOfBenefitBeingSubstantial
                        orderby choiceStrength descending
                        select new {
                            p.Name,
                            OddsOfAnyBenefit = oddsOfAnyBenefit,
                            OddsOfBenefitBeingSubstantial = oddsOfBenefitBeingSubstantial,
                            ChoiceStrength = choiceStrength
                        };

            Console.Write("{0,-" + this.playerColumnWidth + "} ", "Player");
            Console.Write("{0,20} ", "Odds of any benefit");
            Console.Write("{0,36} ", "Odds of an unknown card being useful");
            Console.Write("{0,20} ", "Strength of choice");
            Console.WriteLine();
            foreach (var stat in stats) {
                Console.Write("{0,-" + this.playerColumnWidth + "} ", stat.Name);
                Console.Write("{0,20:0}% ", stat.OddsOfAnyBenefit * 100);
                Console.Write("{0,36:0}% ", stat.OddsOfBenefitBeingSubstantial * 100);
                Console.Write("{0,20:0}%", stat.ChoiceStrength * 100);
                Console.WriteLine();
            }

            // Begin spying
            var clue = new SpyCard { Player = this.ChoosePlayer("Spy on which player?", true, false) };
            if (clue.Player == null) {
                return;
            }
            clue.Card = ConsoleHelper.Choose("Which card did you see?", true, c => c.Name, clue.PossiblySeenCards.ToArray());
            if (clue.Card == null) {
                return;
            }
            this.game.Clues.Add(clue);
        }