Esempio n. 1
0
        public void PlayShouldProvideCorrectPlayerTurnContextToPlayers()
        {
            var firstPlayer      = new ValidPlayer();
            var firstPlayerInfo  = new RoundPlayerInfo(firstPlayer);
            var secondPlayer     = new ValidPlayer();
            var secondPlayerInfo = new RoundPlayerInfo(secondPlayer);
            var stateManager     = new StateManager();
            var deck             = new Deck();

            firstPlayerInfo.AddCard(Card.GetCard(CardSuit.Heart, CardType.King));
            firstPlayerInfo.AddCard(Card.GetCard(CardSuit.Heart, CardType.Queen));
            stateManager.SetState(new MoreThanTwoCardsLeftRoundState(stateManager));

            secondPlayerInfo.AddCard(Card.GetCard(CardSuit.Diamond, CardType.Ten));
            secondPlayerInfo.AddCard(Card.GetCard(CardSuit.Diamond, CardType.Ace));

            var trick = new Trick(firstPlayerInfo, secondPlayerInfo, stateManager, deck, GameRulesProvider.Santase);

            trick.Play();

            Assert.IsTrue(firstPlayer.GetTurnContextObject.IsFirstPlayerTurn);
            Assert.IsFalse(secondPlayer.GetTurnContextObject.IsFirstPlayerTurn);
            Assert.IsTrue(secondPlayer.GetTurnContextObject.FirstPlayerAnnounce != Announce.None);
            Assert.IsNotNull(secondPlayer.GetTurnContextObject.FirstPlayedCard);
            Assert.AreEqual(CardSuit.Heart, secondPlayer.GetTurnContextObject.FirstPlayedCard.Suit);

            Assert.IsTrue(
                secondPlayer.GetTurnContextObject.FirstPlayerRoundPoints == 20 ||
                secondPlayer.GetTurnContextObject.FirstPlayerRoundPoints == 40);
        }
Esempio n. 2
0
        public void PlayShouldCorrectlyDetermineTheWinner()
        {
            var firstPlayer      = new ValidPlayer();
            var firstPlayerInfo  = new RoundPlayerInfo(firstPlayer);
            var secondPlayer     = new ValidPlayer();
            var secondPlayerInfo = new RoundPlayerInfo(secondPlayer);
            var stateManager     = new StateManager();
            var deck             = new Deck();

            firstPlayerInfo.AddCard(Card.GetCard(CardSuit.Heart, CardType.Nine));
            secondPlayerInfo.AddCard(Card.GetCard(deck.TrumpCard.Suit, CardType.Jack));

            var trick  = new Trick(firstPlayerInfo, secondPlayerInfo, stateManager, deck, GameRulesProvider.Santase);
            var winner = trick.Play();

            Assert.IsTrue(winner == secondPlayerInfo);
            Assert.AreEqual(2, winner.RoundPoints);
            Assert.AreEqual(2, winner.TrickCards.Count);
            Assert.IsTrue(winner.TrickCards.Contains(Card.GetCard(CardSuit.Heart, CardType.Nine)));
            Assert.IsTrue(winner.TrickCards.Contains(Card.GetCard(deck.TrumpCard.Suit, CardType.Jack)));
            Assert.AreEqual(0, firstPlayerInfo.TrickCards.Count);

            Assert.AreEqual(0, firstPlayer.EndTurnContextObject.FirstPlayerRoundPoints);
            Assert.AreEqual(2, firstPlayer.EndTurnContextObject.SecondPlayerRoundPoints);
            Assert.AreEqual(0, secondPlayer.EndTurnContextObject.FirstPlayerRoundPoints);
            Assert.AreEqual(2, secondPlayer.EndTurnContextObject.SecondPlayerRoundPoints);

            Assert.AreEqual(0, firstPlayer.GetTurnContextObject.FirstPlayerRoundPoints);
            Assert.AreEqual(0, firstPlayer.GetTurnContextObject.SecondPlayerRoundPoints);
            Assert.AreEqual(0, secondPlayer.GetTurnContextObject.FirstPlayerRoundPoints);
            Assert.AreEqual(0, secondPlayer.GetTurnContextObject.SecondPlayerRoundPoints);
        }
Esempio n. 3
0
        public void PlayShouldChangeTheDeckTrumpWhenPlayerPlaysChangeTrumpAction()
        {
            var firstPlayer      = new ValidPlayer(PlayerActionType.ChangeTrump);
            var firstPlayerInfo  = new RoundPlayerInfo(firstPlayer);
            var secondPlayer     = new ValidPlayer();
            var secondPlayerInfo = new RoundPlayerInfo(secondPlayer);
            var stateManager     = new StateManager();

            stateManager.SetState(new MoreThanTwoCardsLeftRoundState(stateManager));
            var deck      = new Deck();
            var trumpSuit = deck.TrumpCard.Suit;

            var oldTrumpCard = deck.TrumpCard;
            var nineOfTrump  = Card.GetCard(trumpSuit, CardType.Nine);

            firstPlayerInfo.AddCard(nineOfTrump);
            secondPlayerInfo.AddCard(
                Card.GetCard(trumpSuit == CardSuit.Heart ? CardSuit.Club : CardSuit.Heart, CardType.Ace));

            var trick = new Trick(firstPlayerInfo, secondPlayerInfo, stateManager, deck, GameRulesProvider.Santase);

            trick.Play();

            Assert.AreEqual(nineOfTrump, deck.TrumpCard);
            Assert.AreEqual(nineOfTrump, secondPlayer.GetTurnContextObject.TrumpCard);
            Assert.IsTrue(firstPlayerInfo.TrickCards.Contains(oldTrumpCard), "Trick cards should contain oldTrumpCard");
            Assert.IsFalse(firstPlayerInfo.Cards.Contains(nineOfTrump));
            Assert.IsFalse(
                firstPlayer.CardsCollection.Contains(nineOfTrump),
                "Player contains nine of trump after changing trump card");
        }
Esempio n. 4
0
        public void PlayShouldCallGetTurnAndEndTurnForBothPlayers()
        {
            var firstPlayer      = new ValidPlayer();
            var firstPlayerInfo  = new RoundPlayerInfo(firstPlayer);
            var secondPlayer     = new ValidPlayer();
            var secondPlayerInfo = new RoundPlayerInfo(secondPlayer);
            var stateManager     = new StateManager();
            var deck             = new Deck();

            SimulateGame(firstPlayerInfo, secondPlayerInfo, deck);

            var trick  = new Trick(firstPlayerInfo, secondPlayerInfo, stateManager, deck, GameRulesProvider.Santase);
            var winner = trick.Play();

            Assert.AreEqual(1, firstPlayer.GetTurnCalledCount);
            Assert.AreEqual(1, secondPlayer.GetTurnCalledCount);
            Assert.AreEqual(1, firstPlayer.EndTurnCalledCount);
            Assert.AreEqual(1, secondPlayer.EndTurnCalledCount);

            Assert.IsNotNull(firstPlayer.GetTurnContextObject);
            Assert.IsNotNull(secondPlayer.GetTurnContextObject);
            Assert.IsNotNull(firstPlayer.EndTurnContextObject);
            Assert.IsNotNull(secondPlayer.EndTurnContextObject);

            Assert.IsNotNull(firstPlayer.EndTurnContextObject.FirstPlayedCard);
            Assert.IsNotNull(firstPlayer.EndTurnContextObject.SecondPlayedCard);
            Assert.IsNotNull(secondPlayer.EndTurnContextObject.FirstPlayedCard);
            Assert.IsNotNull(secondPlayer.EndTurnContextObject.SecondPlayedCard);

            Assert.IsTrue(winner == firstPlayerInfo || winner == secondPlayerInfo);
        }
Esempio n. 5
0
        public void PlayTrumpOrderTest()
        {
            var players      = PlayersSetup.BuildFourAIPlayers();
            var fourthPlayer = players[3];

            var cardsHeldByPlayer   = new Dictionary <IPlayer, List <Card> >();
            var cardsPlayedByPlayer = new Dictionary <IPlayer, List <Card> >();

            var heart = SuitHelper.GetSuit(CardSuit.Heart);

            cardsHeldByPlayer[players[0]] = new List <Card> {
                new Card(RankHelper.GetRank("7"), heart)
            };
            cardsHeldByPlayer[players[1]] = new List <Card> {
                new Card(RankHelper.GetRank("A"), heart)
            };
            cardsHeldByPlayer[players[2]] = new List <Card> {
                new Card(RankHelper.GetRank("8"), heart)
            };
            cardsHeldByPlayer[players[3]] = new List <Card> {
                new Card(RankHelper.GetRank("9"), heart)
            };

            var trick = new Trick(players, heart);

            trick.Play(cardsHeldByPlayer, cardsPlayedByPlayer);
            var winner = trick.GetTaker();

            Assert.AreEqual(fourthPlayer, winner);
        }
Esempio n. 6
0
        public void PlayMultipleColors()
        {
            var players     = PlayersSetup.BuildFourAIPlayers();
            var firstPlayer = players[0];

            var cardsHeldByPlayer   = new Dictionary <IPlayer, List <Card> >();
            var cardsPlayedByPlayer = new Dictionary <IPlayer, List <Card> >();

            var heart = SuitHelper.GetSuit(CardSuit.Heart);
            var spade = SuitHelper.GetSuit(CardSuit.Spade);
            var club  = SuitHelper.GetSuit(CardSuit.Club);

            cardsHeldByPlayer[players[0]] = new List <Card> {
                new Card(RankHelper.GetRank("7"), heart)
            };
            cardsHeldByPlayer[players[1]] = new List <Card> {
                new Card(RankHelper.GetRank("A"), club)
            };
            cardsHeldByPlayer[players[2]] = new List <Card> {
                new Card(RankHelper.GetRank("8"), club)
            };
            cardsHeldByPlayer[players[3]] = new List <Card> {
                new Card(RankHelper.GetRank("9"), club)
            };

            var trick = new Trick(players, spade);

            trick.Play(cardsHeldByPlayer, cardsPlayedByPlayer);
            var winner = trick.GetTaker();

            Assert.AreEqual(firstPlayer, winner);
        }
Esempio n. 7
0
        public void PlayShouldThrowAnExceptionWhenPlayerReturnsNullAction()
        {
            var firstPlayer = new Mock <IPlayer>();

            firstPlayer.Setup(x => x.GetTurn(It.IsAny <PlayerTurnContext>())).Returns((PlayerAction)null);
            var firstPlayerInfo = new RoundPlayerInfo(firstPlayer.Object);

            var secondPlayer     = new Mock <IPlayer>();
            var secondPlayerInfo = new RoundPlayerInfo(secondPlayer.Object);

            var stateManager = new StateManager();
            var deck         = new Deck();

            var trick = new Trick(firstPlayerInfo, secondPlayerInfo, stateManager, deck, GameRulesProvider.Santase);

            Assert.Throws <InternalGameException>(() => trick.Play());
        }
Esempio n. 8
0
        public void PlayShouldThrowAnExceptionWhenClosingTheGameAndNineOfTrumpsIsMissing()
        {
            var firstPlayer      = new ValidPlayer(PlayerActionType.ChangeTrump);
            var firstPlayerInfo  = new RoundPlayerInfo(firstPlayer);
            var secondPlayer     = new ValidPlayer();
            var secondPlayerInfo = new RoundPlayerInfo(secondPlayer);
            var stateManager     = new StateManager();

            stateManager.SetState(new MoreThanTwoCardsLeftRoundState(stateManager));
            var deck      = new Deck();
            var trumpSuit = deck.TrumpCard.Suit;

            firstPlayerInfo.AddCard(Card.GetCard(trumpSuit, CardType.Jack));
            secondPlayerInfo.AddCard(Card.GetCard(CardSuit.Heart, CardType.Ace));

            var trick = new Trick(firstPlayerInfo, secondPlayerInfo, stateManager, deck, GameRulesProvider.Santase);

            Assert.Throws <InternalGameException>(() => trick.Play());
        }
Esempio n. 9
0
        public void PlayShouldThrowAnExceptionWhenPlayerPlaysInvalidCard()
        {
            var firstPlayer = new Mock <IPlayer>();

            firstPlayer.Setup(x => x.GetTurn(It.IsAny <PlayerTurnContext>()))
            .Returns(PlayerAction.PlayCard(Card.GetCard(CardSuit.Club, CardType.Ace)));
            var firstPlayerInfo = new RoundPlayerInfo(firstPlayer.Object);

            var secondPlayer     = new Mock <IPlayer>();
            var secondPlayerInfo = new RoundPlayerInfo(secondPlayer.Object);

            var stateManager = new StateManager();
            var deck         = new Deck();

            firstPlayerInfo.AddCard(Card.GetCard(CardSuit.Heart, CardType.King));
            secondPlayerInfo.AddCard(Card.GetCard(CardSuit.Heart, CardType.Ace));

            var trick = new Trick(firstPlayerInfo, secondPlayerInfo, stateManager, deck, GameRulesProvider.Santase);

            Assert.Throws <InternalGameException>(() => trick.Play());
        }
Esempio n. 10
0
        public void PlayShouldCallGetTurnOnlyForFirstPlayerWhenTheFirstPlayerGoesOutByAnnounce()
        {
            var firstPlayer      = new ValidPlayer();
            var firstPlayerInfo  = new RoundPlayerInfo(firstPlayer);
            var secondPlayer     = new ValidPlayer();
            var secondPlayerInfo = new RoundPlayerInfo(secondPlayer);
            var stateManager     = new StateManager();
            var deck             = new Deck();

            // 53 points in firstPlayerInfo.TrickCards
            firstPlayerInfo.TrickCards.Add(Card.GetCard(CardSuit.Diamond, CardType.Ace));
            firstPlayerInfo.TrickCards.Add(Card.GetCard(CardSuit.Diamond, CardType.Ten));
            firstPlayerInfo.TrickCards.Add(Card.GetCard(CardSuit.Spade, CardType.Ace));
            firstPlayerInfo.TrickCards.Add(Card.GetCard(CardSuit.Club, CardType.Ace));
            firstPlayerInfo.TrickCards.Add(Card.GetCard(CardSuit.Club, CardType.Ten));

            // Add cards for announcing 20
            firstPlayerInfo.AddCard(Card.GetCard(CardSuit.Heart, CardType.King));
            firstPlayerInfo.AddCard(Card.GetCard(CardSuit.Heart, CardType.Queen));
            stateManager.SetState(new MoreThanTwoCardsLeftRoundState(stateManager));

            secondPlayerInfo.AddCard(Card.GetCard(CardSuit.Heart, CardType.Ten));
            secondPlayerInfo.AddCard(Card.GetCard(CardSuit.Heart, CardType.Ace));

            var trick  = new Trick(firstPlayerInfo, secondPlayerInfo, stateManager, deck, GameRulesProvider.Santase);
            var winner = trick.Play();

            Assert.AreEqual(1, firstPlayer.GetTurnCalledCount);
            Assert.AreEqual(0, secondPlayer.GetTurnCalledCount);
            Assert.AreEqual(1, firstPlayer.EndTurnCalledCount);
            Assert.AreEqual(1, secondPlayer.EndTurnCalledCount);
            Assert.AreSame(firstPlayerInfo, winner);

            Assert.IsTrue(firstPlayerInfo.HasAtLeastOneTrick);
            Assert.IsFalse(secondPlayerInfo.HasAtLeastOneTrick);

            Assert.IsTrue(winner.RoundPoints == 73 || winner.RoundPoints == 93);
            Assert.IsTrue(winner.RoundPoints == 73 || winner.RoundPoints == 93);
        }
Esempio n. 11
0
        public void PlayShouldCloseTheGameWhenPlayerPlaysCloseGameAction()
        {
            var firstPlayer      = new ValidPlayer(PlayerActionType.CloseGame);
            var firstPlayerInfo  = new RoundPlayerInfo(firstPlayer);
            var secondPlayer     = new ValidPlayer();
            var secondPlayerInfo = new RoundPlayerInfo(secondPlayer);
            var stateManager     = new StateManager();

            stateManager.SetState(new MoreThanTwoCardsLeftRoundState(stateManager));
            var deck = new Deck();

            SimulateGame(firstPlayerInfo, secondPlayerInfo, deck);

            var trick = new Trick(firstPlayerInfo, secondPlayerInfo, stateManager, deck, GameRulesProvider.Santase);

            trick.Play();

            Assert.IsTrue(firstPlayerInfo.GameCloser);
            Assert.IsFalse(secondPlayerInfo.GameCloser);
            Assert.IsInstanceOf <FinalRoundState>(stateManager.State);
            Assert.IsInstanceOf <FinalRoundState>(secondPlayer.GetTurnContextObject.State);
        }
Esempio n. 12
0
        public void PlayWithRankTest()
        {
            var players      = PlayersSetup.BuildFourAIPlayers();
            var secondPlayer = players[1];

            var cardsHeldByPlayer   = new Dictionary <IPlayer, List <Card> >();
            var cardsPlayedByPlayer = new Dictionary <IPlayer, List <Card> >();

            var heart = SuitHelper.GetSuit(CardSuit.Heart);
            var spade = SuitHelper.GetSuit(CardSuit.Spade);

            cardsHeldByPlayer[players[0]] = new List <Card> {
                new Card(RankHelper.GetRank("7"), heart)
            };
            cardsHeldByPlayer[players[1]] = new List <Card> {
                new Card(RankHelper.GetRank("A"), heart)
            };
            cardsHeldByPlayer[players[2]] = new List <Card> {
                new Card(RankHelper.GetRank("8"), heart)
            };
            cardsHeldByPlayer[players[3]] = new List <Card> {
                new Card(RankHelper.GetRank("9"), heart)
            };

            var trick = new Trick(players, spade);

            trick.Play(cardsHeldByPlayer, cardsPlayedByPlayer);
            var winner = trick.GetTaker();

            Assert.AreEqual(secondPlayer, winner);

            var playedCards = trick.GetPlayedCards();

            Assert.IsNotNull(playedCards);
            Assert.AreEqual(4, playedCards.Count);
        }
Esempio n. 13
0
        private void PlayTrick()
        {
            Trick t = new Trick(this, myIsFirstTrick, myHeartsBroken);

            t.Play(myTrickStarter);

            myTakenCards[t.Winner].AddRange(t.Cards);

            if (!myHeartsBroken && t.HasPointCards) {
                myHeartsBroken = true;
            }

            myTrickStarter = t.Winner;
            myIsFirstTrick = false;
        }