public void IsLegal_ReturnTrueIfThereIsNoStartCard() { var cards = new[] { new Card(CardType.Blue, 1, 0), new Card(CardType.Blue, 2, 0), new Card(CardType.Red, 3, 0) }; var hand = new Hand(cards); Assert.IsTrue(PlayRule.IsLegal(hand, cards[2], null), "All cards should be allowed"); }
public void IsLegal_ReturnsFalseIfCardDoesntExist() { var cards = new[] { new Card(CardType.Blue, 1, 0), new Card(CardType.Blue, 2, 0) }; var hand = new Hand(cards); Assert.IsFalse(PlayRule.IsLegal(hand, new Card(CardType.Red, 1, 0), null), "Different color"); Assert.IsFalse(PlayRule.IsLegal(hand, new Card(CardType.Blue, 3, 0), null), "Different number"); Assert.IsFalse(PlayRule.IsLegal(hand, new Card(CardType.Red, 3, 0), null), "Different color & number"); }
public void IsLegal_ReturnsFalseIfUserHasCorrectColorButPlaysDifferent() { var start = new Card(CardType.Blue, 6, 0); var cards = new[] { new Card(CardType.Blue, 1, 0), new Card(CardType.Blue, 2, 0), new Card(CardType.Red, 3, 0) }; var hand = new Hand(cards); Assert.IsFalse(PlayRule.IsLegal(hand, cards[2], start), "User lied"); }
private List <Play> AskMoves() { var playedCards = new List <Play>(); foreach (var seat in _seats) { var card = seat.Player.Play(playedCards.Select(p => p.Card).ToArray()); //Check rule validity var playerHand = seat.Hand; if (!PlayRule.IsLegal(playerHand, card, playedCards.Select(p => p.Card).FirstOrDefault())) { throw new Exception("Illegal move"); } //Remove card from player playerHand.RemoveCard(card); playedCards.Add(new Play(seat.Index, card)); } return(playedCards); }