コード例 #1
0
        public static RoyalFlush TryGetRoyalFlush(Card[] cards)
        {
            if (cards.First().CardNomination.Is(MajorCardType.Ace) && TryGetStraightFlush(cards) != null)
                return new RoyalFlush();

            return null;
        }
コード例 #2
0
 public static StraightFlush TryGetStraightFlush(Card[] cards)
 {
     var straight = TryGetStraight(cards);
     return straight != null && TryGetFlush(cards) != null
                 ? new StraightFlush(straight.MainCard)
                 : null;
 }
コード例 #3
0
 public static Flush TryGetFlush(Card[] cards)
 {
     var first = cards.First();
     return cards.Skip(1).All(c => c.Suit == first.Suit)
             ? new Flush(cards.Select(c => c.CardNomination).ToArray())
             : null;
 }
コード例 #4
0
 public static Tuple<Pair, Card[]> TryGetPair(Card[] cards)
 {
     var tuple = GetNominationWithLength(2, cards);
     return (tuple != null)
         ? new Tuple<Pair, Card[]>(new Pair(tuple.Item1), tuple.Item2)
         : null;
 }
コード例 #5
0
 public static Tuple<FourOfAKind, Card[]> TryGetFourOfAKind(Card[] cards)
 {
     var tuple = GetNominationWithLength(4, cards);
     return (tuple != null)
         ? new Tuple<FourOfAKind, Card[]>(new FourOfAKind(tuple.Item1), tuple.Item2)
         : null;
 }
コード例 #6
0
        public static FullHouse TryGetFullHouse(Card[] cards)
        {
            var threeCardTuple = GetNominationWithLength(3, cards);
            var pairCardTuple = GetNominationWithLength(2, cards);

            return (threeCardTuple != null && pairCardTuple != null)
                ? new FullHouse(threeCardTuple.Item1, pairCardTuple.Item1)
                : null;
        }
コード例 #7
0
 public static Flush TryGetFlush(Card[] cards)
 {
     return cards.Skip(1).Aggregate(
         new {Flush = true, cards.First().Suit},
         (acc, card) => new { Flush = acc.Flush && acc.Suit == card.Suit, card.Suit }
         ).Flush
             ? new Flush(cards.Select(c => c.CardNomination).ToArray())
             : null;
 }
コード例 #8
0
        public static Tuple<TwoPairs, Card[]> TryGetTwoPairs(Card[] cards)
        {
            var tuple1 = GetNominationWithLength(2, cards);

            if (tuple1 == null)
                return null;

            var tuple2 = GetNominationWithLength(2, cards, tuple1.Item1);
            return (tuple2 != null)
                ? new Tuple<TwoPairs, Card[]>(new TwoPairs(new[] { tuple1.Item1, tuple2.Item1 }), tuple2.Item2)
                : null;
        }
コード例 #9
0
ファイル: Deck.cs プロジェクト: jckccc/Fun
 private void createDeck()
 {
     currentCardIndex = 0;
     deck = new List<Card>();
     foreach (Suit suit in Enum.GetValues(typeof(Suit)))
     {
         foreach (Value value in Enum.GetValues(typeof(Value)))
         {
             Card currentCard = new Card(suit, value);
             deck.Add(currentCard);
         }
     }
 }
コード例 #10
0
 public static Straight TryGetStraight(Card[] cards)
 {
     var first = cards.First();
     return cards.Skip(1).Aggregate(new {IsStraight = true, Card = first}, (acc, card) => new
         {
             IsStraight = acc.IsStraight && acc.Card.CardNomination.Value - card.CardNomination.Value == 1, Card = card
         }).IsStraight
                 ? new Straight(first.CardNomination)
                 // A,5,4,3,2
                 : cards.Select(c => c.CardNomination)
                     .Except(new CardNomination[] { new MajorCardNomination(MajorCardType.Ace), new MinorCardNomination(5), new MinorCardNomination(4), new MinorCardNomination(3), new MinorCardNomination(2) }).Any()
                         ? null
                         : new Straight(new MinorCardNomination(5));
 }
コード例 #11
0
 private static Hand GetHand(Card[] cardSet)
 {
     return
         new Hand(CombinationFactory.TryGetRoyalFlush(cardSet))
             .Or(() => new Hand(CombinationFactory.TryGetStraightFlush(cardSet)))
             .Or(()=> CreateHand(CombinationFactory.TryGetFourOfAKind(cardSet)))
             .Or(() => new Hand(CombinationFactory.TryGetFullHouse(cardSet)))
             .Or(() => new Hand(CombinationFactory.TryGetFlush(cardSet)))
             .Or(() => new Hand(CombinationFactory.TryGetStraight(cardSet)))
             .Or(() => CreateHand(CombinationFactory.TryGetThreeOfAKind(cardSet)))
             .Or(() => CreateHand(CombinationFactory.TryGetTwoPairs(cardSet)))
             .Or(() => CreateHand(CombinationFactory.TryGetPair(cardSet)))
             .Or(() => new Hand(null, new OddCards(cardSet.Select(c => c.CardNomination).ToArray())));
 }
コード例 #12
0
ファイル: Hand.cs プロジェクト: altnetberlin/Coding-Dojo
 public Hand(Card one, Card two, Card three, Card four, Card five)
 {
     _cards = new[] { one, two, three, four, five };
     Rank = GetRank();
 }
コード例 #13
0
        private static Tuple<CardNomination, Card[]> GetNominationWithLength(int length, Card[] cards, CardNomination exclude = null)
        {
            var group = (exclude == null
                                ? cards
                                : cards.Where(c => c.CardNomination != exclude))
                .GroupBy(c => c.CardNomination).FirstOrDefault(g => g.Count() == length);

            var card = group == null? null : group.FirstOrDefault();
            return card == null
                ? null
                : new Tuple<CardNomination, Card[]>(card.CardNomination, cards.Where(c => c.CardNomination != card.CardNomination).ToArray());
        }
コード例 #14
0
 public static bool IsPlayer1Wins(Card[][] cardSets)
 {
     return GetHand(cardSets.First().OrderByDescending(c => c.CardNomination).ToArray())
         .CompareTo(GetHand(cardSets.Skip(1).First().OrderByDescending(c => c.CardNomination).ToArray()))
         == 1;
 }