public void ShouldReturnPlayerWithHighestCard_WhenSuitsAreEqual_AndTheLeadSuitIsTrumps()
        {
            var winner = player1InContract;
            var cardsPlayed = new CardsPlayedCollection
                                  {
                                      new CardPlayed(player2InContract, new Card(Rank.Three, Suit.Clubs)),
                                      new CardPlayed(player1NotInContract, new Card(Rank.Five, Suit.Clubs)),
                                      new CardPlayed(winner, new Card(Rank.King, Suit.Clubs)),
                                      new CardPlayed(player2NotInContract, new Card(Rank.Two, Suit.Clubs))
                                  };

            Assert.AreEqual(winner, game.DetermineWinner(cardsPlayed));
        }
Exemplo n.º 2
0
        protected override Card PlayCard(CardsPlayedCollection cardsPlayed)
        {
            if (!cardsPlayed.Any() && IsDeclarer)
            {

            }

            if (cardsPlayed.Any() && CanFollowSuit(cardsPlayed.First().Card))
            {
                var card = Hand.First(c => c.Suit == cardsPlayed.First().Card.Suit);
                return card;
            }

            return Hand.First();
        }
Exemplo n.º 3
0
        public Player DetermineWinner(CardsPlayedCollection cardsPlayed)
        {
            var winner = cardsPlayed.First();

            foreach (var cardPlayed in cardsPlayed)
            {
                if (cardPlayed.Card.Suit == winner.Card.Suit && cardPlayed.Card.Rank > winner.Card.Rank)
                {
                    winner = cardPlayed;
                    continue;
                }

                if (cardPlayed.Card.Suit == Contract.Suit && winner.Card.Suit != Contract.Suit)
                {
                    winner = cardPlayed;
                    continue;
                }
            }

            return cardsPlayed.Single(cp => cp == winner).Player;
        }
Exemplo n.º 4
0
        private CardsPlayedCollection PlayRound(Player current)
        {
            var cardsPlayed = new CardsPlayedCollection();

            for (var i = 0; i < _numberOfPlayers; i++)
            {
                cardsPlayed.Add(new CardPlayed(current, current.Play(cardsPlayed)));
                current = current.Next;
            }

            return cardsPlayed;
        }
Exemplo n.º 5
0
 public Card Play(CardsPlayedCollection cardsPlayed)
 {
     var cardPlayed = PlayCard(cardsPlayed);
     Hand.Remove(cardPlayed);
     return cardPlayed;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Selects which card from the Player's hand should be played next, given the supplied play history.
 /// </summary>
 /// <param name="cardsPlayed">The cards played so far in the current trick</param>
 /// <returns></returns>
 protected abstract Card PlayCard(CardsPlayedCollection cardsPlayed);