public void Trick_IsLegal_PlayerDoesNotHaveSuit() { var firstPlayer = new Participant() { Cards = "9♠" }.Player; var player = new Participant() { Cards = "K♥;7♥;Q♣;8♣" }.Player; var startingPlayerCalcMock = new Mock <IStartingPlayerCalculator>(); startingPlayerCalcMock.Setup(m => m.GetStartingPlayer(It.IsAny <IHand>(), It.IsAny <ITrick>())).Returns(firstPlayer); var handMock = new Mock <IHand>(); handMock.Setup(m => m.Players).Returns(new List <IPlayer>()); handMock.Setup(m => m.ITricks).Returns(new List <ITrick>()); handMock.Setup(m => m.IGame.PartnerMethodEnum).Returns(PartnerMethod.JackOfDiamonds); handMock.Setup(m => m.PartnerCardEnum).Returns(SheepCard.JACK_DIAMONDS); var trick = new Trick(handMock.Object, startingPlayerCalcMock.Object); trick.Add(firstPlayer, SheepCard.N9_SPADES); Assert.IsTrue(trick.IsLegalAddition(SheepCard.N7_HEARTS, player), "There is no spades in the hand. Hearts is fine."); Assert.IsTrue(trick.IsLegalAddition(SheepCard.N8_CLUBS, player), "There is no spades in the hand. Clubs is fine."); Assert.IsTrue(trick.IsLegalAddition(SheepCard.QUEEN_CLUBS, player), "There is no spades in the hand. Trump is fine."); }
public void Trick_IsLegal_False_PartnerCanNowLeadWithAceOfPartnerFailSuit() { var partner = new Participant() { Cards = "T♥;7♥;K♦;J♦;A♠" }.Player; var hand = new Mock <IHand>(); var previousTrick = new Mock <ITrick>(); previousTrick.Setup(m => m.CardsByPlayer).Returns(new Dictionary <IPlayer, SheepCard>() { { new Mock <IPlayer>().Object, SheepCard.N9_CLUBS }, { new Mock <IPlayer>().Object, SheepCard.ACE_HEARTS }, { new Mock <IPlayer>().Object, SheepCard.N8_SPADES }, { new Mock <IPlayer>().Object, SheepCard.N9_HEARTS }, { new Mock <IPlayer>().Object, SheepCard.N10_DIAMONDS }, }); hand.Setup(m => m.ITricks).Returns(new List <ITrick>() { previousTrick.Object }); hand.Setup(m => m.Players).Returns(new List <IPlayer>() { partner }); hand.Setup(m => m.IGame.PartnerMethodEnum).Returns(PartnerMethod.CalledAce); hand.Setup(m => m.PartnerCardEnum).Returns(SheepCard.ACE_HEARTS); var calculator = new Mock <IStartingPlayerCalculator>(); calculator.Setup(m => m.GetStartingPlayer(hand.Object, It.IsAny <ITrick>())).Returns(partner); var trick = new Trick(hand.Object, calculator.Object); Assert.IsTrue(partner.Cards.All(c => trick.IsLegalAddition(c, partner)), "Ace of Hearts has been played; partner can lead with anything."); }
public void Trick_IsLegal_PartnerLeads_OtherTrickLeadWithSameSuit() { var partner = new Participant() { Cards = "T♥;7♥;A♥;J♦;7♠;A♠" }.Player; var previousTrick = new Mock <ITrick>(); previousTrick.Setup(m => m.CardsByPlayer).Returns(new Dictionary <IPlayer, SheepCard>() { { new Mock <IPlayer>().Object, SheepCard.N7_DIAMONDS } }); previousTrick.Setup(m => m.CardsByPlayer).Returns(new Dictionary <IPlayer, SheepCard>() { { new Mock <IPlayer>().Object, SheepCard.N7_HEARTS } }); var hand = new Mock <IHand>(); hand.Setup(m => m.IGame.PartnerMethodEnum).Returns(PartnerMethod.CalledAce); hand.Setup(m => m.PartnerCardEnum).Returns(SheepCard.ACE_HEARTS); hand.Setup(m => m.ITricks).Returns(new List <ITrick>() { previousTrick.Object }); hand.Setup(m => m.Players).Returns(new List <IPlayer>() { partner }); var calculator = new Mock <IStartingPlayerCalculator>(); calculator.Setup(m => m.GetStartingPlayer(hand.Object, It.IsAny <ITrick>())).Returns(partner); var trick = new Trick(hand.Object, calculator.Object); Assert.IsTrue(trick.IsLegalAddition(SheepCard.ACE_HEARTS, partner), "Previous trick lead with heart, so this is legal."); }
public void Trick_IsLegal_PickerLeads_OtherTrickLedWithSameSuit() { var picker = new Participant() { Cards = "9♥;9♦;Q♥;9♣;A♣;K♣" }.Player; var previousTrick = new Mock <ITrick>(); previousTrick.Setup(m => m.CardsByPlayer).Returns(new Dictionary <IPlayer, SheepCard>() { { new Mock <IPlayer>().Object, SheepCard.N7_HEARTS } }); var hand = new Mock <IHand>(); hand.Setup(m => m.IGame.PartnerMethodEnum).Returns(PartnerMethod.CalledAce); hand.Setup(m => m.PartnerCardEnum).Returns(SheepCard.ACE_HEARTS); hand.Setup(m => m.Picker).Returns(picker); hand.Setup(m => m.ITricks).Returns(new List <ITrick>() { previousTrick.Object }); hand.Setup(m => m.Players).Returns(new List <IPlayer>()); var calculator = new Mock <IStartingPlayerCalculator>(); calculator.Setup(m => m.GetStartingPlayer(hand.Object, It.IsAny <ITrick>())).Returns(picker); var trick = new Trick(hand.Object, calculator.Object); Assert.IsTrue(trick.IsLegalAddition(SheepCard.N9_HEARTS, picker), "Picker has no other hearts, but hearts were led in a previous trick."); }
public void Trick_IsLegal_PickerBeAllowedToLeadWithLastCardOfCalledSuit() { var picker = new Participant() { Cards = "9♥;9♦;Q♥;9♣;A♣;K♣" }.Player; var hand = new Mock <IHand>(); hand.Setup(m => m.Buried).Returns(new List <SheepCard>() { SheepCard.N10_CLUBS, SheepCard.N10_SPADES }); hand.Setup(m => m.IGame.PartnerMethodEnum).Returns(PartnerMethod.CalledAce); hand.Setup(m => m.PartnerCardEnum).Returns(SheepCard.ACE_HEARTS); hand.Setup(m => m.Picker).Returns(picker); hand.Setup(m => m.ITricks).Returns(new List <ITrick>()); hand.Setup(m => m.Players).Returns(new List <IPlayer>() { picker }); var calculator = new Mock <IStartingPlayerCalculator>(); calculator.Setup(m => m.GetStartingPlayer(hand.Object, It.IsAny <ITrick>())).Returns(picker); var trick = new Trick(hand.Object, calculator.Object); Assert.IsTrue(trick.IsLegalAddition(SheepCard.N9_HEARTS, picker), "Picker has no other hearts, so this cannot be the lead card."); }
public void Trick_IsLegal_MustMatchStartingCard() { var firstPlayer = new Participant() { Cards = CardUtil.GetAbbreviation(SheepCard.N9_HEARTS) }.Player; var startingPlayerCalcMock = new Mock <IStartingPlayerCalculator>(); startingPlayerCalcMock.Setup(m => m.GetStartingPlayer(It.IsAny <IHand>(), It.IsAny <ITrick>())).Returns(firstPlayer); var player = new Participant() { Cards = "K♥;7♥;Q♦;8♣" }.Player; var handMock = new Mock <IHand>(); handMock.Setup(m => m.ITricks).Returns(new List <ITrick>()); handMock.Setup(m => m.Players).Returns(new List <IPlayer>() { firstPlayer, player }); handMock.Setup(m => m.IGame.PartnerMethodEnum).Returns(PartnerMethod.JackOfDiamonds); handMock.Setup(m => m.PartnerCardEnum).Returns(SheepCard.JACK_DIAMONDS); var trick = new Trick(handMock.Object, startingPlayerCalcMock.Object) { TrickPlays = new List <TrickPlay>() { new TrickPlay() { Participant = new Participant(), Card = CardUtil.GetAbbreviation(SheepCard.N9_CLUBS), SortOrder = 2 }, new TrickPlay() { Participant = firstPlayer.Participant, Card = CardUtil.GetAbbreviation(SheepCard.N9_HEARTS), SortOrder = 1 } } }; Assert.IsTrue(trick.IsLegalAddition(SheepCard.N7_HEARTS, player), "A hearts is part of the same suite."); Assert.IsFalse(trick.IsLegalAddition(SheepCard.N8_CLUBS, player), "A clubs is not part of the same suite."); Assert.IsFalse(trick.IsLegalAddition(SheepCard.QUEEN_DIAMONDS, player), "A trump is not part of the same suite."); Assert.IsFalse(trick.IsLegalAddition(SheepCard.N10_CLUBS, player), "A card outside of the hand is not legal."); }
public void Trick_IsLegal_PartnerMustFollowWithPartnerCard() { var partner = new Participant() { Cards = "T♥;T♠;A♥;J♦;7♠;A♠" }.Player; var curTrick = new Mock <ITrick>(); var hand = new Mock <IHand>(); hand.Setup(m => m.IGame.PartnerMethodEnum).Returns(PartnerMethod.CalledAce); hand.Setup(m => m.PartnerCardEnum).Returns(SheepCard.ACE_SPADES); hand.Setup(m => m.ITricks).Returns(new List <ITrick>()); hand.Setup(m => m.Players).Returns(new List <IPlayer>() { partner }); var calculator = new Mock <IStartingPlayerCalculator>(); calculator.Setup(m => m.GetStartingPlayer(hand.Object, It.IsAny <ITrick>())).Returns(partner); var trick = new Trick(hand.Object, calculator.Object); trick.Add(new Participant().Player, SheepCard.N8_SPADES); Assert.IsTrue(trick.IsLegalAddition(SheepCard.ACE_SPADES, partner), "Partner must follow suit and must place partner card before anything else in this suit."); Assert.IsFalse(trick.IsLegalAddition(SheepCard.N10_HEARTS, partner), "No other cards can be played."); Assert.IsFalse(trick.IsLegalAddition(SheepCard.N10_SPADES, partner), "No other cards can be played."); Assert.IsFalse(trick.IsLegalAddition(SheepCard.ACE_HEARTS, partner), "No other cards can be played."); Assert.IsFalse(trick.IsLegalAddition(SheepCard.JACK_SPADES, partner), "No other cards can be played."); Assert.IsFalse(trick.IsLegalAddition(SheepCard.N7_SPADES, partner), "No other cards can be played."); }
public void Trick_IsLegal_PartnerCannotLeadWithFailCardExceptAceAtFirst() { var partner = new Participant() { Cards = "T♥;7♥;A♥;J♦;7♠;A♠" }.Player; var previousTrick = new Mock <ITrick>(); previousTrick.Setup(m => m.CardsByPlayer).Returns(new Dictionary <IPlayer, SheepCard>() { { new Mock <IPlayer>().Object, SheepCard.N9_CLUBS }, { new Mock <IPlayer>().Object, SheepCard.KING_HEARTS }, { new Mock <IPlayer>().Object, SheepCard.N8_SPADES }, { new Mock <IPlayer>().Object, SheepCard.N9_HEARTS }, { new Mock <IPlayer>().Object, SheepCard.N10_DIAMONDS }, }); var hand = new Mock <IHand>(); hand.Setup(m => m.ITricks).Returns(new List <ITrick>() { previousTrick.Object }); hand.Setup(m => m.ITricks).Returns(new List <ITrick>()); hand.Setup(m => m.Players).Returns(new List <IPlayer>() { partner }); hand.Setup(m => m.IGame.PartnerMethodEnum).Returns(PartnerMethod.CalledAce); hand.Setup(m => m.PartnerCardEnum).Returns(SheepCard.ACE_HEARTS); var calculator = new Mock <IStartingPlayerCalculator>(); calculator.Setup(m => m.GetStartingPlayer(hand.Object, It.IsAny <ITrick>())).Returns(partner); var trick = new Trick(hand.Object, calculator.Object); Assert.IsTrue(trick.IsLegalAddition(SheepCard.ACE_HEARTS, partner), "Partner can only lead with called ace or a different fail suit."); Assert.IsTrue(trick.IsLegalAddition(SheepCard.N7_SPADES, partner), "Partner can only lead with called ace or a different fail suit."); Assert.IsFalse(trick.IsLegalAddition(SheepCard.N7_HEARTS, partner), "Partner cannot lead with 7 of hearts."); }
public void Trick_IsLegal_LastCardLeft() { var partner = new Participant() { Cards = CardUtil.GetAbbreviation(SheepCard.ACE_SPADES) }.Player; var otherTrick = new Mock <ITrick>().Object; var hand = new Mock <IHand>(); hand.Setup(m => m.ITricks).Returns(new List <ITrick>() { otherTrick, otherTrick, otherTrick, otherTrick }); hand.Setup(m => m.IGame.PartnerMethodEnum).Returns(PartnerMethod.CalledAce); hand.Setup(m => m.PartnerCardEnum).Returns(SheepCard.ACE_SPADES); var calculator = new Mock <IStartingPlayerCalculator>(); calculator.Setup(m => m.GetStartingPlayer(hand.Object, It.IsAny <ITrick>())).Returns(partner); var trick = new Trick(hand.Object, calculator.Object); Assert.IsTrue(trick.IsLegalAddition(SheepCard.ACE_SPADES, partner), "Cannt normally lead with the partner card, but can do so for last trick."); }
public void Trick_IsLegal_PickerCanLeadWithCardOfCalledSuit1() { var picker = new Participant() { Cards = "9♦;Q♥;8♥;A♣;K♣;9♥" }.Player; var hand = new Mock <IHand>(); hand.Setup(m => m.IGame.PartnerMethodEnum).Returns(PartnerMethod.CalledAce); hand.Setup(m => m.PartnerCardEnum).Returns(SheepCard.ACE_HEARTS); hand.Setup(m => m.ITricks).Returns(new List <ITrick>()); hand.Setup(m => m.Players).Returns(new List <IPlayer>() { picker }); var calculator = new Mock <IStartingPlayerCalculator>(); calculator.Setup(m => m.GetStartingPlayer(hand.Object, It.IsAny <ITrick>())).Returns(picker); var trick = new Trick(hand.Object, calculator.Object); Assert.IsTrue(trick.IsLegalAddition(SheepCard.N9_HEARTS, picker)); }
public void Trick_IsLegal_FirstCardInSuit() { var firstPlayer = new Participant().Player; var startingPlayerCalcMock = new Mock <IStartingPlayerCalculator>(); startingPlayerCalcMock.Setup(m => m.GetStartingPlayer(It.IsAny <IHand>(), It.IsAny <ITrick>())).Returns(firstPlayer); var handMock = new Mock <IHand>(); handMock.Setup(h => h.Players).Returns(new List <IPlayer>() { firstPlayer }); handMock.Setup(h => h.ITricks).Returns(new List <ITrick>()); handMock.Setup(h => h.IGame.PartnerMethodEnum).Returns(PartnerMethod.JackOfDiamonds); handMock.Setup(h => h.PartnerCardEnum).Returns(SheepCard.JACK_DIAMONDS); var trick = new Trick(handMock.Object, startingPlayerCalcMock.Object); var hand = new List <SheepCard>() { SheepCard.KING_HEARTS, SheepCard.N7_HEARTS, SheepCard.QUEEN_CLUBS, SheepCard.N8_CLUBS }; var player = GetPlayer(hand); Assert.IsTrue(trick.IsLegalAddition(SheepCard.N7_HEARTS, player), "Adding a card to an empty trick is always okay."); }