Ejemplo n.º 1
0
        //判断我出的牌是否合法
        internal static bool IsInvalid(MainForm mainForm, ArrayList[] currentSendedCards, int who)
        {
            
            CurrentPoker[] cp = new CurrentPoker[4];
            int suit = mainForm.currentState.Suit;
            int first = mainForm.firstSend;

            int rank = mainForm.currentRank;

            cp[who-1] = new CurrentPoker();
            cp[who - 1].Suit = suit;
            cp[who - 1].Rank = rank;

            ArrayList list = new ArrayList();
            CurrentPoker tmpCP = new CurrentPoker();
            tmpCP.Suit = suit;
            tmpCP.Rank = rank;

            for (int i = 0; i < mainForm.myCardIsReady.Count; i++)
            {
                if ((bool)mainForm.myCardIsReady[i])
                {
                    cp[who - 1].AddCard((int)mainForm.myCardsNumber[i]);
                    list.Add((int)mainForm.myCardsNumber[i]);
                }
                else
                {
                    tmpCP.AddCard((int)mainForm.myCardsNumber[i]);
                }
            }
            int[] users = CommonMethods.OtherUsers(who);

            cp[users[0] - 1] = CommonMethods.parse(mainForm.currentSendCards[users[0] - 1], suit, rank);
            cp[users[1] - 1] = CommonMethods.parse(mainForm.currentSendCards[users[1] - 1], suit, rank);
            cp[users[2] - 1] = CommonMethods.parse(mainForm.currentSendCards[users[2] - 1], suit, rank);
            cp[0].Sort();
            cp[1].Sort();
            cp[2].Sort();
            cp[3].Sort();

            

            //如果我出牌
            if (first == who)
            {
                if (cp[who -1].Count ==0)
                {
                    return false;
                }

                if (cp[who-1].IsMixed())
                {
                    return false;
                }

                return true;
            }
            else
            {
                if (list.Count != currentSendedCards[first - 1].Count)
                {
                    return false;
                }


                //得到第一个家伙出的花色
                int previousSuit = CommonMethods.GetSuit((int)currentSendedCards[first - 1][0], suit, rank);
               
                //0.如果我是混合的,则判断我手中是否还剩出的花色,如果剩,false;如果不剩;true
                if (cp[who-1].IsMixed())
                {
                    if (tmpCP.HasSomeCards(previousSuit))
                    {
                        return false;
                    }
                    else
                    {
                        return true;
                    }
                }


                //如果出的花色不一致
                int mysuit = CommonMethods.GetSuit((int)list[0], suit, rank);


                //如果确实花色不一致
                if (mysuit != previousSuit) 
                {
                    //而且确实没有此花色
                    if (tmpCP.HasSomeCards(previousSuit))
                    {
                        return false;
                    }
                    else
                    {
                        return true;
                    }
                }


                //3.别人如果出对,我也应该出对
                int firstPairs = cp[first - 1].GetPairs().Count;
                int mypairs = cp[who - 1].GetPairs().Count;
                int myCurrentPairs = mainForm.currentPokers[who - 1].GetPairs(previousSuit).Count;


                //2.如果别人出拖拉机,我如果有,也应该出拖拉机
                if (cp[first-1].HasTractors())
                {
                    if ((!cp[who - 1].HasTractors()) && (mainForm.currentPokers[who-1].GetTractor(previousSuit) > -1))
                    {
                        return false;
                    }
                    else if ((mypairs == 1) && (myCurrentPairs> 1)) //出了单个对,但是实际多于1个对
                    {
                        return false;
                    }
                    else if ((mypairs == 0) && (myCurrentPairs > 0)) //没出对,但实际有对
                    {
                        return false;
                    }
                    else
                    {
                        return true;
                    }
                }

                

                if (firstPairs > 0)
                {
                    if ((myCurrentPairs >= firstPairs) && (mypairs < firstPairs))
                    {
                        return false;
                    }
                    else
                    {
                        return true;
                    }
                }

            }
            return true;

        }