Пример #1
0
        bool CheckAllStreet(Card c1, Card c2, Card c3, Card c4, Card c5, Card card1, Card card2)
        {
            if (c4 == null && c5 == null)
            {
                return CheckStreet(c1, c2, c3, card1, card2);
            }
            if (c4 != null && c5 == null)
            {
                return
                    (
                    CheckStreet(c1, c2, c3, card1, card2)
                    ||
                    CheckStreet(c1, c2, c4, card1, card2)
                    ||
                    CheckStreet(c2, c3, c4, card1, card2)
                    ||
                    CheckStreet(c1, c3, c4, card1, card2)
                    );
            }
            if (c4 != null && c5 != null)
            {
                return
                    (
                    CheckStreet(c1, c2, c3, card1, card2)
                    ||
                    CheckStreet(c1, c3, c4, card1, card2)
                    ||
                    CheckStreet(c1, c4, c5, card1, card2)
                    ||
                    CheckStreet(c2, c3, c4, card1, card2)
                    ||

                    CheckStreet(c2, c4, c5, card1, card2)
                    ||
                    CheckStreet(c3, c4, c5, card1, card2)
                    ||
                    CheckStreet(c1, c2, c4, card1, card2)
                    ||

                    CheckStreet(c1, c2, c5, card1, card2)
                    ||
                    CheckStreet(c2, c3, c5, card1, card2)
                    ||
                    CheckStreet(c2, c4, c5, card1, card2)
                    ||
                    CheckStreet(c1, c3, c5, card1, card2)
                    );
            }
            return false;
        }
Пример #2
0
        bool CheckDrawBoard(Card c1, Card c2, Card c3, Card c4)
        {
            if (c4 == null)
            {
                var lsAll = GetRankCount(new[] { c1, c2, c3 });

                if (lsAll.Any(obj => obj.Value >= 2 && obj.Key >= c3.Rank))
                    return true;

                if (lsAll.Any(obj => obj.Value >= 2 && obj.Key >= c2.Rank))
                    return true;

                if (c1.Suit == c2.Suit && c2.Suit == c3.Suit
                    ||
                    CheckStreetAlgo(new[] { c1, c2, c3 }, 3)
                    ||
                    c1.Rank == c2.Rank && c2.Rank == c3.Rank
                    )
                    return true;
            }

            if (c4 != null)
            {
                var lsAll = GetRankCount(new[] { c1, c2, c3, c4 });

                if (lsAll.Any(obj => obj.Value >= 2 && obj.Key >= c4.Rank))
                    return true;

                if (lsAll.Any(obj => obj.Value >= 2 && obj.Key >= c3.Rank))
                    return true;

                if (c1.Suit == c2.Suit && c2.Suit == c4.Suit
                    ||
                    c1.Suit == c4.Suit && c4.Suit == c3.Suit
                    ||
                    c2.Suit == c3.Suit && c3.Suit == c4.Suit

                    ||

                    CheckStreetAlgo(new[] { c1, c2, c3 }, 3)
                    ||
                    CheckStreetAlgo(new[] { c1, c2, c4 }, 3)
                    ||
                    CheckStreetAlgo(new[] { c1, c3, c4 }, 3)
                    ||
                    CheckStreetAlgo(new[] { c2, c3, c4 }, 3)
                    )
                    return true;
            }

            return false;
        }
Пример #3
0
        /// <summary>
        /// Дровяной борд
        /// </summary>
        /// <returns></returns>
        bool CheckDrawBoard(Card c1, Card c2, Card c3)
        {
            if (CheckStreetAlgo(new[] {c1, c2, c3}, 3))
                return true;

            if (
                (c3.Rank - c2.Rank == 1 || c2.Rank - c1.Rank == 1)
                &&
                (c1.Suit == c2.Suit || c2.Suit == c3.Suit || c1.Suit == c3.Suit)
                )
                return true;

            if (c1.Suit == c2.Suit && c2.Suit == c3.Suit)
                return true;

            return false;
        }
Пример #4
0
 bool CheckFlush(Card c1, Card c2, Card c3, Card card1, Card card2)
 {
     return c1.Suit == c2.Suit && c2.Suit == c3.Suit && c3.Suit == card1.Suit && c3.Suit == card2.Suit;
 }
Пример #5
0
        private bool ValidatePair(Card c1, Card c2, Card c3, Card c4, Card c5, Card card1, Card card2, Card maxCard)
        {
            if (_table.IsPreFlop)
            {
                return card1.Rank == card2.Rank;
            }
            if (_table.IsFlop)
            {
                return
                    (card1.Rank == card2.Rank && card2.Rank >= c3.Rank)
                    ||
                    (c3.Rank == card1.Rank)
                    ||
                    (c3.Rank == card2.Rank)

                    ||
                    (c2.Rank == card1.Rank)
                    ||
                    (c2.Rank == card2.Rank)

                    ||
                    (c1.Rank == card1.Rank)
                    ||
                    (c1.Rank == card2.Rank);
            }
            if (_table.IsTurn)
            {
                return
                    (card1.Rank == card2.Rank && card2.Rank >= c4.Rank)
                    ||
                    (c4.Rank == card1.Rank)
                    ||
                    (c4.Rank == card2.Rank);
            }
            if (_table.IsRiver)
            {
                return (card1.Rank == card2.Rank && card2.Rank >= c5.Rank)
                    ||
                    (c5.Rank == card1.Rank)
                    ||
                    (c5.Rank == card2.Rank);
            }
            //(card1.Rank == card2.Rank)
            //|| (c1.Rank == card1.Rank)
            //|| (c1.Rank == card2.Rank)
            //|| (c2.Rank == card1.Rank)
            //|| (c2.Rank == card2.Rank)
            //|| (c3.Rank == card1.Rank)
            //|| (c3.Rank == card2.Rank)
            //|| (c4 != null && (
            //    (c4.Rank == card1.Rank)
            //    || (c4.Rank == card2.Rank)
            //    ))
            //|| (c5 != null && (
            //    (c5.Rank == card1.Rank)
            //    || (c5.Rank == card2.Rank)
            //    ))

            //(card1.Rank == card2.Rank && card1.Rank >= maxCard.Rank)
            //|| (c1.Rank == card1.Rank && card1.Rank >= maxCard.Rank)
            //|| (c1.Rank == card2.Rank && card2.Rank >= maxCard.Rank)
            //|| (c2.Rank == card1.Rank && card1.Rank >= maxCard.Rank)
            //|| (c2.Rank == card2.Rank && card2.Rank >= maxCard.Rank)
            //|| (c3.Rank == card1.Rank && card1.Rank >= maxCard.Rank)
            //|| (c3.Rank == card2.Rank && card2.Rank >= maxCard.Rank)
            //|| (c4 != null && (
            //    (c4.Rank == card1.Rank && card1.Rank >= maxCard.Rank)
            //    || (c4.Rank == card2.Rank && card2.Rank >= maxCard.Rank)
            //    ))
            //|| (c5 != null && (
            //    (c5.Rank == card1.Rank && card1.Rank >= maxCard.Rank)
            //    || (c5.Rank == card2.Rank && card2.Rank >= maxCard.Rank)
            //    ))
            return false;
        }
Пример #6
0
 bool CheckTriple(Card c1, Card c2, Card c3, Card c4, Card c5, Card card1, Card card2)
 {
     var lsMine = GetRankCount(new[] { card1, card2 });
     int cnt = 3;
     if (c4 == null && c5 == null)
     {
         var lsAll = GetRankCount(new[] { c1, c2, c3 });
         foreach (Rank rank in Enum.GetValues(typeof(Rank)))
         {
             if (rank != Rank.NOT_RECOGNIZED)
                 if (lsAll[rank] + lsMine[rank] >= cnt && lsMine[rank] > 0)
                 {
                     return true;
                 }
         }
     }
     if (c4 != null && c5 == null)
     {
         var lsAll = GetRankCount(new[] { c1, c2, c3, c4 });
         foreach (Rank rank in Enum.GetValues(typeof(Rank)))
         {
             if (rank != Rank.NOT_RECOGNIZED)
                 if (lsAll[rank] + lsMine[rank] >= cnt && lsMine[rank] > 0)
                 {
                     return true;
                 }
         }
     }
     if (c4 != null && c5 != null)
     {
         var lsAll = GetRankCount(new[] { c1, c2, c3, c4, c5 });
         foreach (Rank rank in Enum.GetValues(typeof(Rank)))
         {
             if (rank != Rank.NOT_RECOGNIZED)
                 if (lsAll[rank] + lsMine[rank] >= cnt && lsMine[rank] > 0)
                 {
                     return true;
                 }
         }
     }
     return false;
 }
Пример #7
0
 bool CheckStreet(Card c1, Card c2, Card c3, Card c4, Card c5, Card card1, Card card2)
 {
     if (c4 == null && c5 == null)
     {
         return CheckStreetAlgo(new[] {c1, c2, c3, card1, card2 }, 5);
     }
     if (c4 != null && c5 == null)
     {
         return CheckStreetAlgo(new[] { c1, c2, c3, c4, card1, card2 }, 5);
     }
     if (c4 != null && c5 != null)
     {
         return
             CheckStreetAlgo(new[] { c1, c2, c3, c5, card1, card2 }, 5)
             ||
             CheckStreetAlgo(new[] { c1, c2, c3, c4, card1, card2 }, 5)
             ||
             CheckStreetAlgo(new[] { c1, c2, c3, c5, card1, card2 }, 5)
             ||
             CheckStreetAlgo(new[] { c1, c2, c4, c5, card1, card2 }, 5)
             ||
             CheckStreetAlgo(new[] { c2, c3, c4, c5, card1, card2 }, 5);
     }
     return false;
 }
Пример #8
0
 bool CheckOesdStreet(Card c1, Card c2, Card c3, Card c4, Card card1, Card card2)
 {
     if (c4 == null)
     {
         return CheckStreetAlgo(new[] { c1, c2, c3, card1, card2 }, 4);
     }
     if (c4 != null)
     {
         return
             CheckStreetAlgo(new[] { c1, c2, c3, card1, card2 }, 4)
             ||
             CheckStreetAlgo(new[] { c1, c2, c4, card1, card2 }, 4)
             ||
             CheckStreetAlgo(new[] { c1, c2, c3, c4, card1 }, 4)
             ||
             CheckStreetAlgo(new[] { c1, c2, c3, c4, card2 }, 4)
             ;
     }
     return false;
 }
Пример #9
0
 bool CheckStreetLine(Card c1, Card c2, Card c3, Card c4, Card c5)
 {
     return
     (
     c5.Rank - c4.Rank == 1 && c4.Rank - c3.Rank == 1 && c3.Rank - c2.Rank == 1 && c2.Rank - c1.Rank == 1
     ||
     c1.Rank - c2.Rank == 1 && c2.Rank - c3.Rank == 1 && c3.Rank - c4.Rank == 1 && c4.Rank - c5.Rank == 1
     );
 }
Пример #10
0
 bool CheckStreetDraw(Card c1, Card c2, Card c3, Card c4)
 {
     return
     (
     c4.Rank - c3.Rank == 1 && c3.Rank - c2.Rank == 1 && c2.Rank - c1.Rank == 1
     ||
     c1.Rank - c2.Rank == 1 && c2.Rank - c3.Rank == 1 && c3.Rank - c4.Rank == 1
     );
 }
Пример #11
0
        bool CheckStreet(Card c1, Card c2, Card c3, Card c4, Card card1, Card card2)
        {
            return
            (
                            CheckStreetLine(c1, c2, c3, card1, card2)
                            ||
                            CheckStreetLine(card1, card2, c1, c2, c3)
                            ||
                            CheckStreetLine(c1, card1, card2, c2, c3)
                            ||
                            CheckStreetLine(c1, c2, card1, card2, c3)
                            ||

                            CheckStreetLine(c1, c2, c4, card1, card2)
                            ||
                            CheckStreetLine(card1, card2, c1, c2, c4)
                            ||
                            CheckStreetLine(c1, card1, card2, c2, c4)
                            ||
                            CheckStreetLine(c1, c2, card1, card2, c4)
                            ||

                            CheckStreetLine(c1, c3, c4, card1, card2)
                            ||
                            CheckStreetLine(card1, card2, c1, c3, c4)
                            ||
                            CheckStreetLine(c1, card1, card2, c3, c4)
                            ||
                            CheckStreetLine(c1, c3, card1, card2, c4)
                            ||

                            CheckStreetLine(c2, c3, c4, card1, card2)
                            ||
                            CheckStreetLine(card1, card2, c2, c3, c4)
                            ||
                            CheckStreetLine(c2, card1, card2, c3, c4)
                            ||
                            CheckStreetLine(c2, c3, card1, card2, c4)
                            );
        }
Пример #12
0
        bool CheckHalfStreet(Card c1, Card c2, Card c3, Card c4, Card card1, Card card2)
        {
            if (c4 == null)
            {
                return
                    (
                        CheckStreetDraw(c1, c2, c3, card1)
                        ||
                        CheckStreetDraw(c1, c2, card1, c3)
                        ||
                        CheckStreetDraw(c1, card1, c2, c3)
                        ||
                        CheckStreetDraw(card1, c1, c2, c3)

                        ||
                        CheckStreetDraw(c1, c2, c3, card2)
                        ||
                        CheckStreetDraw(c1, c2, card2, c3)
                        ||
                        CheckStreetDraw(c1, card2, c2, c3)
                        ||
                        CheckStreetDraw(card2, c1, c2, c3)

                        ||
                        CheckStreetDraw(c1, c2, card1, card2)
                        ||
                        CheckStreetDraw(c1, card1, card2, c2)
                        ||
                        CheckStreetDraw(c1, card1, c2, card2)
                        ||
                        CheckStreetDraw(card1, card2, c1, c2)

                        ||
                        CheckStreetDraw(c1, c3, card1, card2)
                        ||
                        CheckStreetDraw(c1, card1, card2, c3)
                        ||
                        CheckStreetDraw(c1, card1, c3, card2)
                        ||
                        CheckStreetDraw(card1, card2, c1, c3)

                        ||
                        CheckStreetDraw(c2, c3, card1, card2)
                        ||
                        CheckStreetDraw(c2, card1, card2, c3)
                        ||
                        CheckStreetDraw(c2, card1, c3, card2)
                        ||
                        CheckStreetDraw(card1, card2, c2, c3)

                    );
            }
            if (c4 != null)
            {
                return
                    (
                    //=========================
                        CheckStreetDraw(c1, c2, c3, card1)
                        ||
                        CheckStreetDraw(c1, c2, card1, c3)
                        ||
                        CheckStreetDraw(c1, card1, c2, c3)
                        ||
                        CheckStreetDraw(card1, c1, c2, c3)

                        ||
                        CheckStreetDraw(c1, c2, c3, card2)
                        ||
                        CheckStreetDraw(c1, c2, card2, c3)
                        ||
                        CheckStreetDraw(c1, card2, c2, c3)
                        ||
                        CheckStreetDraw(card2, c1, c2, c3)

                        ||
                        CheckStreetDraw(c1, c2, c4, card2)
                        ||
                        CheckStreetDraw(c1, c2, card2, c4)
                        ||
                        CheckStreetDraw(c1, card2, c2, c4)
                        ||
                        CheckStreetDraw(card2, c1, c2, c4)

                        ||
                        CheckStreetDraw(c1, c3, c4, card2)
                        ||
                        CheckStreetDraw(c1, c3, card2, c4)
                        ||
                        CheckStreetDraw(c1, card2, c3, c4)
                        ||
                        CheckStreetDraw(card2, c1, c3, c4)

                        ||
                        CheckStreetDraw(c2, c3, c4, card2)
                        ||
                        CheckStreetDraw(c2, c3, card2, c4)
                        ||
                        CheckStreetDraw(c2, card2, c3, c4)
                        ||
                        CheckStreetDraw(card2, c2, c3, c4)

                        //===============
                        ||
                        CheckStreetDraw(c1, c2, card1, card2)
                        ||
                        CheckStreetDraw(c1, card1, card2, c2)
                        ||
                        CheckStreetDraw(c1, card1, c2, card2)
                        ||
                        CheckStreetDraw(card1, card2, c1, c2)

                        ||
                        CheckStreetDraw(c1, c3, card1, card2)
                        ||
                        CheckStreetDraw(c1, card1, card2, c3)
                        ||
                        CheckStreetDraw(c1, card1, c3, card2)
                        ||
                        CheckStreetDraw(card1, card2, c1, c3)

                        ||
                        CheckStreetDraw(c2, c3, card1, card2)
                        ||
                        CheckStreetDraw(c2, card1, card2, c3)
                        ||
                        CheckStreetDraw(c2, card1, c3, card2)
                        ||
                        CheckStreetDraw(card1, card2, c2, c3)

                        ||
                        CheckStreetDraw(c2, c4, card1, card2)
                        ||
                        CheckStreetDraw(c2, card1, card2, c4)
                        ||
                        CheckStreetDraw(c2, card1, c4, card2)
                        ||
                        CheckStreetDraw(card1, card2, c2, c4)

                        ||
                        CheckStreetDraw(c3, c4, card1, card2)
                        ||
                        CheckStreetDraw(c3, card1, card2, c4)
                        ||
                        CheckStreetDraw(c3, card1, c4, card2)
                        ||
                        CheckStreetDraw(card1, card2, c3, c4)
                    );
            }
            return false;
        }
Пример #13
0
 bool CheckHalfFlushLine(Card c1, Card c2, Card card1, Card card2)
 {
     return c1.Suit == c2.Suit && c2.Suit == card1.Suit && c2.Suit == card2.Suit;
 }
Пример #14
0
        bool CheckHalfFlush(Card c1, Card c2, Card c3, Card c4, Card card1, Card card2)
        {
            if (c4 == null)
            {
                return
                    (
                    CheckHalfFlushLine(c1, c2, c3, card1)
                    ||
                    CheckHalfFlushLine(c1, c2, c3, card2)
                    ||
                    CheckHalfFlushLine(c1, c2, card1, card2)
                    ||
                    CheckHalfFlushLine(c2, c3, card1, card2)
                    ||
                    CheckHalfFlushLine(c1, c3, card1, card2)
                    );
            }
            if (c4 != null)
            {
                return
                    (
                    CheckHalfFlushLine(c1, c2, c3, card1)
                    ||
                    CheckHalfFlushLine(c1, c2, c3, card2)
                    ||
                    CheckHalfFlushLine(c1, c2, card1, card2)
                    ||
                    CheckHalfFlushLine(c2, c3, card1, card2)
                    ||
                    CheckHalfFlushLine(c1, c3, card1, card2)

                    ||
                    CheckHalfFlushLine(c1, c2, c4, card1)
                    ||
                    CheckHalfFlushLine(c1, c2, c4, card2)
                    ||
                    CheckHalfFlushLine(c1, c2, card1, card2)
                    ||
                    CheckHalfFlushLine(c2, c4, card1, card2)
                    ||
                    CheckHalfFlushLine(c1, c4, card1, card2)

                    ||
                    CheckHalfFlushLine(c1, c4, c3, card1)
                    ||
                    CheckHalfFlushLine(c1, c4, c3, card2)
                    ||
                    CheckHalfFlushLine(c1, c4, card1, card2)
                    ||
                    CheckHalfFlushLine(c4, c3, card1, card2)
                    ||
                    CheckHalfFlushLine(c1, c3, card1, card2)

                    ||
                    CheckHalfFlushLine(c4, c2, c3, card1)
                    ||
                    CheckHalfFlushLine(c4, c2, c3, card2)
                    ||
                    CheckHalfFlushLine(c4, c2, card1, card2)
                    ||
                    CheckHalfFlushLine(c2, c3, card1, card2)
                    ||
                    CheckHalfFlushLine(c4, c3, card1, card2)
                    );
            }
            return false;
        }
Пример #15
0
 bool CheckHalfFlush(Card c1, Card c2, Card c3, Card c4, Card card1, Card card2)
 {
     var lsMine = GetSuitCount(new[] { card1, card2 });
     int cnt = 4;
     if (c4 == null)
     {
         var lsAll = GetSuitCount(new[] { c1, c2, c3 });
         foreach (Suit rank in Enum.GetValues(typeof(Suit)))
         {
             if (rank != Suit.NOT_RECOGNIZED)
                 if (lsAll[rank] + lsMine[rank] >= cnt && lsMine[rank] > 0)
                 {
                     return true;
                 }
         }
     }
     if (c4 != null)
     {
         var lsAll = GetSuitCount(new[] { c1, c2, c3, c4 });
         foreach (Suit rank in Enum.GetValues(typeof(Suit)))
         {
             if (rank != Suit.NOT_RECOGNIZED)
                 if (lsAll[rank] + lsMine[rank] >= cnt && lsMine[rank] > 0)
                 {
                     return true;
                 }
         }
     }
     return false;
 }
Пример #16
0
 private bool CheckMiddlePair(Card c1, Card c2, Card c3, Card card1, Card card2)
 {
     return CheckPair(c1, c2, c3, null, null, card1, card2, c2.Rank)
         ||
         card1.Rank == card2.Rank && card1.Rank >= c2.Rank
         ;
 }
Пример #17
0
 bool CheckTripleLine(Card c1, Card c2, Card c3)
 {
     return c1.Rank == c2.Rank && c2.Rank == c3.Rank;
 }
Пример #18
0
        bool CheckPair(Card c1, Card c2, Card c3, Card c4, Card c5, Card card1, Card card2, Rank maxRank)
        {
            if (card1.Rank == card2.Rank && card1.Rank >= maxRank)
                return true;

            if (c4 == null && c5 == null)
            {
                var lsAll = GetRankCount(new[] { c1, c2, c3 });
                if (
                    lsAll[card1.Rank] >= 1 && card1.Rank >= maxRank
                    ||
                    lsAll[card2.Rank] >= 1 && card2.Rank >= maxRank
                    )
                    return true;

            }
            if (c4 != null && c5 == null)
            {
                var lsAll = GetRankCount(new[] { c1, c2, c3, c4 });
                if (
                    lsAll[card1.Rank] >= 1 && card1.Rank >= maxRank
                    ||
                    lsAll[card2.Rank] >= 1 && card2.Rank >= maxRank
                    )
                    return true;
            }
            if (c4 != null && c5 != null)
            {
                var lsAll = GetRankCount(new[] { c1, c2, c3, c4, c5 });
                if (
                    lsAll[card1.Rank] >= 1 && card1.Rank >= maxRank
                    ||
                    lsAll[card2.Rank] >= 1 && card2.Rank >= maxRank
                    )
                    return true;
            }
            return false;
        }
Пример #19
0
        //bool CheckAllFour(Card c1, Card c2, Card c3, Card c4, Card c5, Card card1, Card card2)
        //{
        //    if (c4 == null && c5 == null)
        //    {
        //        return c1.Rank == c2.Rank && c2.Rank == c3.Rank
        //                    && (card1.Rank == c1.Rank || card2.Rank == c1.Rank);
        //    }
        //    if (c4 != null && c5 == null)
        //    {
        //        return
        //            c1.Rank == c2.Rank && c2.Rank == c3.Rank && (card1.Rank == c1.Rank || card2.Rank == c1.Rank)
        //            ||
        //            c4.Rank == c2.Rank && c2.Rank == c3.Rank && (card1.Rank == c4.Rank || card2.Rank == c4.Rank)
        //            ||
        //            c1.Rank == c4.Rank && c4.Rank == c3.Rank && (card1.Rank == c1.Rank || card2.Rank == c1.Rank)
        //            ||
        //            c1.Rank == c2.Rank && c2.Rank == c4.Rank && (card1.Rank == c1.Rank || card2.Rank == c1.Rank)
        //            ;
        //    }
        //    if (c4 != null && c5 != null)
        //    {
        //        return false; // не играем такое
        //    }
        //    return false;
        //}
        //bool CheckHouse(Card c1, Card c2, Card c3, Card card1, Card card2)
        //{
        //    var cnt = GetRankCount(new[] { c1, c2, c3, card1, card2 });
        //    return cnt.Exists((i) => i == 2) && cnt.Exists((i) => i == 3);
        //}
        //bool CheckAllHouse(Card c1, Card c2, Card c3, Card c4, Card c5, Card card1, Card card2)
        //{
        //    if (c4 == null && c5 == null)
        //    {
        //        return CheckHouse(c1, c2, c3, card1, card2);
        //    }
        //    if (c4 != null && c5 == null)
        //    {
        //        var cnt1 = GetRankCount(new[] { c1, c2, c3, c4, card1 });
        //        var cnt2 = GetRankCount(new[] { c1, c2, c3, c4, card2 });
        //        return
        //            cnt1.Exists((i) => i == 2) && cnt1.Exists((i) => i == 3)
        //            ||
        //            ;
        //    }
        //    if (c4 != null && c5 != null)
        //    {
        //        return false; // не играем такое
        //    }
        //    return false;
        //}
        bool CheckTriple_(Card c1, Card c2, Card c3, Card c4, Card c5, Card card1, Card card2)
        {
            if (c4 == null && c5 == null)
            {
                return
                    CheckTripleLine(c1, c2, card1)
                    ||
                    CheckTripleLine(c1, c3, card1)
                    ||
                    CheckTripleLine(c2, c3, card1)
                    ||
                    CheckTripleLine(c1, c2, card2)
                    ||
                    CheckTripleLine(c1, c3, card2)
                    ||
                    CheckTripleLine(c2, c3, card2)
                    ||
                    CheckTripleLine(c1, card1, card2)
                    ||
                    CheckTripleLine(c2, card1, card2)
                    ||
                    CheckTripleLine(c3, card1, card2)

                    ;

            }
            if (c4 != null && c5 == null)
            {
                return
                    CheckTripleLine(c1, c2, card1)
                    ||
                    CheckTripleLine(c1, c3, card1)
                    ||
                    CheckTripleLine(c2, c3, card1)
                    ||
                    CheckTripleLine(c1, c2, card2)
                    ||
                    CheckTripleLine(c1, c3, card2)
                    ||
                    CheckTripleLine(c2, c3, card2)
                    ||
                    CheckTripleLine(c1, card1, card2)
                    ||
                    CheckTripleLine(c2, card1, card2)
                    ||
                    CheckTripleLine(c3, card1, card2)
                    ||

                    CheckTripleLine(c1, c4, card1)
                    ||
                    CheckTripleLine(c4, c3, card1)
                    ||
                    CheckTripleLine(c1, c4, card2)
                    ||
                    CheckTripleLine(c4, c3, card2)
                    ||
                    CheckTripleLine(c1, card1, card2)
                    ||
                    CheckTripleLine(c4, card1, card2)
                    ||
                    CheckTripleLine(c3, card1, card2)

                    ||
                    CheckTripleLine(c4, c2, card1)
                    ||
                    CheckTripleLine(c4, c3, card1)
                    ||
                    CheckTripleLine(c2, c3, card1)
                    ||
                    CheckTripleLine(c4, c2, card2)
                    ||
                    CheckTripleLine(c4, c3, card2)
                    ||
                    CheckTripleLine(c2, c3, card2)
                    ||
                    CheckTripleLine(c4, card1, card2)
                    ||
                    CheckTripleLine(c2, card1, card2)
                    ||
                    CheckTripleLine(c3, card1, card2)

                    ||
                    CheckTripleLine(c1, c4, card1)
                    ||
                    CheckTripleLine(c2, c4, card1)
                    ||
                    CheckTripleLine(c1, c4, card2)
                    ||
                    CheckTripleLine(c2, c4, card2)
                    ||
                    CheckTripleLine(c1, card1, card2)
                    ||
                    CheckTripleLine(c2, card1, card2)
                    ||
                    CheckTripleLine(c4, card1, card2);
            }
            if (c4 != null && c5 != null)
            {
                return false;
            }
            return false;
        }
Пример #20
0
        bool CheckStreetAlgo(Card[] data, int streetLength)
        {
            var ls = new List<Card>(data);
            ls.Sort((x, y) => x.Rank.CompareTo(y.Rank));

            var ids = new List<int>();
            ids.Add(ls.FindAll((i) => i.Rank == Rank.Two).Count > 0 ? 1 : 0);
            ids.Add(ls.FindAll((i) => i.Rank == Rank.Three).Count > 0 ? 1 : 0);
            ids.Add(ls.FindAll((i) => i.Rank == Rank.Four).Count > 0 ? 1 : 0);
            ids.Add(ls.FindAll((i) => i.Rank == Rank.Five).Count > 0 ? 1 : 0);
            ids.Add(ls.FindAll((i) => i.Rank == Rank.Six).Count > 0 ? 1 : 0);
            ids.Add(ls.FindAll((i) => i.Rank == Rank.Seven).Count > 0 ? 1 : 0);
            ids.Add(ls.FindAll((i) => i.Rank == Rank.Eight).Count > 0 ? 1 : 0);
            ids.Add(ls.FindAll((i) => i.Rank == Rank.Nine).Count > 0 ? 1 : 0);
            ids.Add(ls.FindAll((i) => i.Rank == Rank.Ten).Count > 0 ? 1 : 0);
            ids.Add(ls.FindAll((i) => i.Rank == Rank.Jack).Count > 0 ? 1 : 0);
            ids.Add(ls.FindAll((i) => i.Rank == Rank.Queen).Count > 0 ? 1 : 0);
            ids.Add(ls.FindAll((i) => i.Rank == Rank.King).Count > 0 ? 1 : 0);
            ids.Add(ls.FindAll((i) => i.Rank == Rank.Ace).Count > 0 ? 1 : 0);

            bool d = false;
            int lineCnt = 0;
            for (int i = 0; i < ids.Count; i++)
            {
                if (d && (ids[i] == 1))
                    lineCnt++;

                if (lineCnt + 1 >= streetLength)
                    return true;

                if (ids[i] == 1)
                    d = true;
                else
                {
                    d = false;
                    lineCnt = 0;
                }

            }

            return false;
        }
Пример #21
0
        bool CheckTwoPairOld(Card c1, Card c2, Card c3, Card c4, Card c5, Card card1, Card card2)
        {
            if (c4 == null && c5 == null)
            {
                return c1.Rank == card1.Rank && (c2.Rank == card2.Rank || c3.Rank == card2.Rank)
                        ||
                        c2.Rank == card1.Rank && (c1.Rank == card2.Rank || c3.Rank == card2.Rank)
                        ||
                        c3.Rank == card1.Rank && (c1.Rank == card2.Rank || c2.Rank == card2.Rank);
            }
            if (c4 != null && c5 == null)
            {
                return
                    c1.Rank == card1.Rank && (c2.Rank == card2.Rank || c3.Rank == card2.Rank)
                    ||
                    c2.Rank == card1.Rank && (c1.Rank == card2.Rank || c3.Rank == card2.Rank)
                    ||
                    c3.Rank == card1.Rank && (c1.Rank == card2.Rank || c2.Rank == card2.Rank)
                    ||

                    c4.Rank == card1.Rank && (c2.Rank == card2.Rank || c3.Rank == card2.Rank)
                    ||
                    c2.Rank == card1.Rank && (c4.Rank == card2.Rank || c3.Rank == card2.Rank)
                    ||
                    c3.Rank == card1.Rank && (c4.Rank == card2.Rank || c2.Rank == card2.Rank)
                    ||

                    c1.Rank == card1.Rank && (c4.Rank == card2.Rank || c3.Rank == card2.Rank)
                    ||
                    c4.Rank == card1.Rank && (c1.Rank == card2.Rank || c3.Rank == card2.Rank)
                    ||
                    c3.Rank == card1.Rank && (c1.Rank == card2.Rank || c4.Rank == card2.Rank)
                    ||

                    c1.Rank == card1.Rank && (c2.Rank == card2.Rank || c4.Rank == card2.Rank)
                    ||
                    c2.Rank == card1.Rank && (c1.Rank == card2.Rank || c4.Rank == card2.Rank)
                    ||
                    c4.Rank == card1.Rank && (c1.Rank == card2.Rank || c2.Rank == card2.Rank);
            }
            if (c4 != null && c5 != null)
            {
                return
                    c1.Rank == card1.Rank && (c2.Rank == card2.Rank || c3.Rank == card2.Rank)
                    ||
                    c2.Rank == card1.Rank && (c1.Rank == card2.Rank || c3.Rank == card2.Rank)
                    ||
                    c3.Rank == card1.Rank && (c1.Rank == card2.Rank || c2.Rank == card2.Rank)
                    ||

                    c4.Rank == card1.Rank && (c2.Rank == card2.Rank || c3.Rank == card2.Rank)
                    ||
                    c2.Rank == card1.Rank && (c4.Rank == card2.Rank || c3.Rank == card2.Rank)
                    ||
                    c3.Rank == card1.Rank && (c4.Rank == card2.Rank || c2.Rank == card2.Rank)
                    ||

                    c1.Rank == card1.Rank && (c4.Rank == card2.Rank || c3.Rank == card2.Rank)
                    ||
                    c4.Rank == card1.Rank && (c1.Rank == card2.Rank || c3.Rank == card2.Rank)
                    ||
                    c3.Rank == card1.Rank && (c1.Rank == card2.Rank || c4.Rank == card2.Rank)
                    ||

                    c1.Rank == card1.Rank && (c2.Rank == card2.Rank || c4.Rank == card2.Rank)
                    ||
                    c2.Rank == card1.Rank && (c1.Rank == card2.Rank || c4.Rank == card2.Rank)
                    ||
                    c4.Rank == card1.Rank && (c1.Rank == card2.Rank || c2.Rank == card2.Rank)
                    ||

                    c1.Rank == card1.Rank && (c2.Rank == card2.Rank || c3.Rank == card2.Rank)
                    ||
                    c2.Rank == card1.Rank && (c1.Rank == card2.Rank || c3.Rank == card2.Rank)
                    ||
                    c3.Rank == card1.Rank && (c1.Rank == card2.Rank || c2.Rank == card2.Rank)
                    ||

                    c5.Rank == card1.Rank && (c2.Rank == card2.Rank || c3.Rank == card2.Rank)
                    ||
                    c2.Rank == card1.Rank && (c5.Rank == card2.Rank || c3.Rank == card2.Rank)
                    ||
                    c3.Rank == card1.Rank && (c5.Rank == card2.Rank || c2.Rank == card2.Rank)
                    ||

                    c1.Rank == card1.Rank && (c5.Rank == card2.Rank || c3.Rank == card2.Rank)
                    ||
                    c5.Rank == card1.Rank && (c1.Rank == card2.Rank || c3.Rank == card2.Rank)
                    ||
                    c3.Rank == card1.Rank && (c1.Rank == card2.Rank || c5.Rank == card2.Rank)
                    ||

                    c1.Rank == card1.Rank && (c2.Rank == card2.Rank || c5.Rank == card2.Rank)
                    ||
                    c2.Rank == card1.Rank && (c1.Rank == card2.Rank || c5.Rank == card2.Rank)
                    ||
                    c5.Rank == card1.Rank && (c1.Rank == card2.Rank || c2.Rank == card2.Rank)
                    ;
            }
            return false;
        }
Пример #22
0
        bool CheckTwoPair(Card c1, Card c2, Card c3, Card c4, Card c5, Card card1, Card card2)
        {
            if (c4 == null && c5 == null)
            {
                var lsAll = GetRankCount(new[] { c1, c2, c3 });
                if (lsAll[card1.Rank] >= 1 && lsAll[card2.Rank] >= 1)
                    return true;

            }
            if (c4 != null && c5 == null)
            {
                var lsAll = GetRankCount(new[] { c1, c2, c3, c4 });
                if (lsAll[card1.Rank] >= 1 && lsAll[card2.Rank] >= 1)
                    return true;
            }
            if (c4 != null && c5 != null)
            {
                var lsAll = GetRankCount(new[] { c1, c2, c3, c4, c5 });
                if (lsAll[card1.Rank] >= 1 && lsAll[card2.Rank] >= 1)
                    return true;
            }
            return false;
        }
Пример #23
0
        bool CheckAllFlush(Card c1, Card c2, Card c3, Card c4, Card c5, Card card1, Card card2)
        {
            if (c4 == null && c5 == null)
            {
                return CheckFlush(c1, c2, c3, card1, card2);
            }
            if (c4 != null && c5 == null)
            {
                return
                    (
                    CheckFlush(c1, c2, c3, card1, card2)
                    ||
                    CheckFlush(c1, c2, c4, card1, card2)
                    ||
                    CheckFlush(c2, c3, c4, card1, card2)
                    ||
                    CheckFlush(c1, c3, c4, card1, card2)
                    //||

                    //CheckFlush(c1, c2, c3, c4, card1)
                    //||
                    //CheckFlush(c1, c2, c3, c4, card2)
                    );
            }
            if (c4 != null && c5 != null)
            {
                return
                    (
                    CheckFlush(c1, c2, c3, card1, card2)
                    ||
                    CheckFlush(c1, c3, c4, card1, card2)
                    ||
                    CheckFlush(c1, c4, c5, card1, card2)
                    ||
                    CheckFlush(c2, c3, c4, card1, card2)
                    ||

                    CheckFlush(c2, c4, c5, card1, card2)
                    ||
                    CheckFlush(c3, c4, c5, card1, card2)
                    ||
                    CheckFlush(c1, c2, c4, card1, card2)
                    ||

                    CheckFlush(c1, c2, c5, card1, card2)
                    ||
                    CheckFlush(c2, c3, c5, card1, card2)
                    ||
                    CheckFlush(c2, c4, c5, card1, card2)
                    ||
                    CheckFlush(c1, c3, c5, card1, card2)
                    //||

                    //CheckFlush(c1, c2, c3, c4, card2)
                    //||
                    //CheckFlush(c1, c3, c4, c5, card2)
                    //||
                    //CheckFlush(c1, c2, c4, c5, card2)
                    //||
                    //CheckFlush(c1, c2, c3, c4, card2)
                    //||

                    //CheckFlush(c1, c2, c3, c4, card1)
                    //||
                    //CheckFlush(c1, c3, c4, c5, card1)
                    //||
                    //CheckFlush(c1, c2, c4, c5, card1)
                    //||
                    //CheckFlush(c1, c2, c3, c4, card1)
                    );
            }
            return false;
        }
Пример #24
0
        /// <summary>
        /// Detects and recognizes cards from source image
        /// </summary>
        /// <param name="source">Source image to be scanned</param>
        /// <returns>Recognized Cards</returns>
        public CardCollection Recognize(Bitmap source, string filePath, int id,
            int minSize, Rectangle suitRect, Rectangle rankRect
            )
        {
            CardCollection collection = new CardCollection();  //Collection that will hold cards
            Bitmap temp = source.Clone() as Bitmap; //Clone image to keep original image

            FiltersSequence seq = new FiltersSequence();
            seq.Add(Grayscale.CommonAlgorithms.BT709);  //First add  grayScaling filter
            seq.Add(new OtsuThreshold()); //Then add binarization(thresholding) filter
            temp = seq.Apply(source); // Apply filters on source image

            //if (!string.IsNullOrEmpty(fileName))
            //{
            //    temp.Save(fileName, ImageFormat.Bmp);
            //}
            //Extract blobs from image whose size width and height larger than 150
            BlobCounter extractor = new BlobCounter();
            extractor.FilterBlobs = true;
            extractor.MinWidth = extractor.MinHeight = minSize;//TODO card size
            //extractor.MaxWidth = extractor.MaxHeight = 70;//TODO card size
            extractor.ProcessImage(temp);

            //Will be used transform(extract) cards on source image
            //QuadrilateralTransformation quadTransformer = new QuadrilateralTransformation();

            foreach (Blob blob in extractor.GetObjectsInformation())
            {
                var cardImg = source.Clone(blob.Rectangle, PixelFormat.DontCare);

                Card card = new Card(cardImg); //Create Card Object

                Bitmap suitBmp = card.GetPart(suitRect);
                char color = ScanColor(suitBmp); //Scan color

                seq.Clear();

                seq.Add(Grayscale.CommonAlgorithms.BT709);
                seq.Add(new OtsuThreshold());
                suitBmp = seq.Apply(suitBmp);

                card.Suit = ScanSuit(suitBmp, color); //Scan suit of face card

                Bitmap rankBmp = card.GetPart(rankRect);
                seq.Clear();

                seq.Add(Grayscale.CommonAlgorithms.BT709);
                seq.Add(new OtsuThreshold());
                rankBmp = seq.Apply(rankBmp);

                //var ext = new BlobsFiltering(0, 0, 40, 40);
                //ext.ApplyInPlace(rankBmp);
                card.Rank = ScanRank(rankBmp); //Scan Rank of non-face card

                //if (card.Rank == Rank.NOT_RECOGNIZED)
                //{
                //    if (!string.IsNullOrEmpty(filePath))
                //    {
                //        while (File.Exists(filePath + id + ".bmp"))
                //            id++;
                //        top.Save(filePath + id + ".bmp", ImageFormat.Bmp);
                //    }
                //}

                if(card.Rank != Rank.NOT_RECOGNIZED && card.Suit != Suit.NOT_RECOGNIZED)
                    collection.Add(card); //Add card to collection
            }

            collection.SortByRank();
            return collection;
        }
Пример #25
0
 public void Add(Card card)
 {
     this.List.Add(card);
 }