Beispiel #1
0
 private static int[] nhacsam(int indexFocus, int[] cardHand, int[] cardFire)
 {
     int[] indexCardNhac = null;
     if (cardHand == null || cardHand.Length < 3)
     {
         return(null);
     }
     int[] sam    = null;
     int[] cardUp = null;
     for (int i = 0; i < cardHand.Length; i++)
     {
         if (getValue(cardHand[i]) == getValue(cardHand[indexFocus]))
         {
             sam    = RTL.insertArray(sam, i);
             cardUp = RTL.insertArray(cardUp, cardHand[i]);
         }
         if (sam != null && sam.Length == 3)
         {
             break;
         }
     }
     if (sam != null && sam.Length == 3 && compareCard(cardUp, cardFire))
     {
         indexCardNhac = sam;
     }
     return(indexCardNhac);
 }
Beispiel #2
0
    private static int[] nhac4doithong(int indexFocus, int[] cardHand, int[] cardFire)
    {
        int[] indexCardNhac = null;
        if (cardHand == null || cardHand.Length < 8)
        {
            return(null);
        }
        int[] pearList = null;
        int[] cardUp   = null;
        int   temp     = getValue(cardHand[indexFocus]);

        for (int i = indexFocus; i < cardHand.Length - 1; i += 2)
        {
            if ((getValue(cardHand[i]) == 1 ? 14 : getValue(cardHand[i])) == temp &&
                (getValue(cardHand[i + 1]) == 1 ? 14 : getValue(cardHand[i + 1])) == temp)
            {
                pearList = RTL.insertArray(pearList, i);
                pearList = RTL.insertArray(pearList, i + 1);
                cardUp   = RTL.insertArray(cardUp, cardHand[i]);
                cardUp   = RTL.insertArray(cardUp, cardHand[i + 1]);
                temp    += 1;
            }
        }
        if (pearList != null && pearList.Length == 8 && compareCard(cardUp, cardFire))
        {
            indexCardNhac = pearList;
        }
        return(indexCardNhac);
    }
Beispiel #3
0
 private static int[] nhactuquy(int indexFocus, int[] cardHand, int[] cardFire)
 {
     int[] indexCardNhac = null;
     if (cardHand == null || cardHand.Length < 4)
     {
         return(null);
     }
     int[] tyquy  = null;
     int[] cardUp = null;
     for (int i = 0; i < cardHand.Length; i++)
     {
         if (getValue(cardHand[i]) == getValue(cardHand[indexFocus]))
         {
             tyquy  = RTL.insertArray(tyquy, i);
             cardUp = RTL.insertArray(cardUp, cardHand[i]);
         }
         if (tyquy != null && tyquy.Length == 4)
         {
             break;
         }
     }
     if (tyquy != null && tyquy.Length == 4 && compareCard(cardUp, cardFire))
     {
         indexCardNhac = tyquy;
     }
     return(indexCardNhac);
 }
Beispiel #4
0
    private static int[] nhacdoithong(int indexFocus, int[] cardHand, int[] cardFire)
    {
        int[] indexCardNhac = null;
        if (getValue(cardHand[indexFocus]) == 2 || cardHand.Length < 6)
        {
            return(null);
        }
        int[] pearList = null;
        int   temp     = getValue(cardHand[indexFocus]);

        for (int i = indexFocus; i < cardHand.Length - 1; i++)
        {
            if ((getValue(cardHand[i]) == 1 ? 14 : getValue(cardHand[i])) == temp &&
                (getValue(cardHand[i + 1]) == 1 ? 14 : getValue(cardHand[i + 1])) == temp)
            {
                pearList = RTL.insertArray(pearList, i);
                pearList = RTL.insertArray(pearList, i + 1);
                temp    += 1;
            }
        }

        if (pearList != null && (pearList.Length == 6 || pearList.Length == 8))
        {
            indexCardNhac = pearList;
        }
        return(indexCardNhac);
    }
Beispiel #5
0
    public static bool checkSanhPK(int[] cards)
    {
        int[] cardS     = null;
        int   cardTemp  = -1;
        int   cardsSize = cards.Length;

        for (int i = 0; i < cardsSize; i++)
        {
            if (cardTemp == -1)
            {
                cardTemp = cards[i];
                cardS    = RTL.insertArray(cardS, cardTemp);
                continue;
            }
            else if (i >= 4 && getValue(cardTemp) == 5)
            {
                if (getValue(cards[i]) == 1 && getValue(cardS[0]) != 1)
                {
                    cardS = RTL.insertArray(cardS, cards[i]);
                }
                else if (getValue(cards[i]) == 6)
                {
                    cardS    = RTL.insertArray(cardS, cards[i]);
                    cardTemp = cards[i];
                }
            }
            else if ((getValue(cardTemp) == 13 ? 0 : getValue(cardTemp)) + 1 == getValue(cards[i]))
            {
                cardS    = RTL.insertArray(cardS, cards[i]);
                cardTemp = cards[i];
            }
            else if (getValue(cardTemp) == getValue(cards[i]))
            {
                cardS    = subArray(cardS, cardTemp);
                cardS    = RTL.insertArray(cardS, cards[i]);
                cardTemp = cards[i];
            }
            else
            {
                if (cardS.Length <= 2)
                {
                    cardS    = null;
                    cardS    = RTL.insertArray(cardS, cards[i]);
                    cardTemp = cards[i];
                }
                else if (cardS.Length < 5)
                {
                    break;
                }
            }
        }
        if (cardS.Length >= 5)
        {
            return(true);
        }
        return(false);
    }
Beispiel #6
0
 public int[] getArrayCardAllTrue()   // không sắp xếp
 {
     int[] arr = null;
     for (int i = 0; i < arrCard.Count; i++)
     {
         arr = RTL.insertArray(arr, arrCard[i].getId());
     }
     if (arr == null)
     {
         return(new int[] { });
     }
     return(arr);
 }
Beispiel #7
0
 public int[] getArrCardAll2()   // có sắp xếp, không trả về null
 {
     int[] arr = null;
     for (int i = 0; i < getSize(); i++)
     {
         arr = RTL.insertArray(arr, arrIntCard[i]);
     }
     if (arr == null)
     {
         return(new int[] { });
     }
     return(arr);
 }
Beispiel #8
0
    private static int[] nhac1doi(int indexFocus, int[] cardHand, int[] cardFire)
    {
        int[] indexCardNhac = null;
        if (cardHand == null || cardHand.Length < 2)
        {
            return(null);
        }
        int cPos = -1;

        int[] arrCardUp = new int[] { cardHand[indexFocus] };
        if (indexFocus + 1 <= cardHand.Length && indexFocus - 1 >= cardHand.Length)
        {
            if (getValue(cardHand[indexFocus + 1]) == cardHand[indexFocus])
            {
                if (compareCard(RTL.insertArray(arrCardUp, cardHand[indexFocus + 1]), cardFire))
                {
                    cPos = indexFocus + 1;
                }
            }
            else if (getValue(cardHand[indexFocus - 1]) == cardHand[indexFocus])
            {
                if (compareCard(RTL.insertArray(arrCardUp, cardHand[indexFocus - 1]), cardFire))
                {
                    cPos = indexFocus - 1;
                }
            }
        }
        int pos = -1;

        if (indexFocus - 1 >= 0 && getValue(cardHand[indexFocus - 1]) == getValue(cardHand[indexFocus]))
        {
            pos = indexFocus - 1;
        }
        if (indexFocus + 1 <= cardHand.Length - 1 &&
            getValue(cardHand[indexFocus + 1]) == getValue(cardHand[indexFocus]) && pos == -1)
        {
            pos = indexFocus + 1;
        }
        if (pos != -1 && compareCard(RTL.insertArray(arrCardUp, cardHand[pos]), cardFire))
        {
            cPos = pos;
        }
        if (cPos != -1)
        {
            indexCardNhac = new int[] { cPos };
        }
        return(indexCardNhac);
    }
Beispiel #9
0
 public int[] getArrCardChoose()   // có sắp xếp, có trả về null
 // return super.getArrCard();
 {
     int[] arr = null;
     for (int i = 0; i < getSize(); i++)
     {
         if (arrCard[i].isChoose)
         {
             arr = RTL.insertArray(arr, arrCard[i].getId());
         }
     }
     if (arr != null)
     {
         arr = RTL.sort(arr);
     }
     return(arr);
 }
Beispiel #10
0
 public static bool isbondoithong(int[] card)
 {
     int[] pearList = null;
     for (int i = 0; i < card.Length - 1; i++)
     {
         if (getValue(card[i]) == getValue(card[i + 1]))
         {
             if (!isContain(pearList, getValue(card[i])))
             {
                 pearList = RTL.insertArray(pearList, getValue(card[i]));
             }
         }
     }
     if (pearList != null && pearList.Length == 4)
     {
         return(true);
     }
     return(false);
 }
Beispiel #11
0
    public void click()
    {
        if (player.getName().Equals(BaseInfo.gI().mainInfo.nick))
        {
            int len = 0;
            if (arrayCard == null)
            {
                return;
            }
            if (arrayCard.getArrCardChoose() != null)
            {
                len = arrayCard.getArrCardChoose().Length;
            }

            if (len != 0)
            {
                if (card.isChoose)
                {
                }
                else
                {
                    int value1 = TLMNChooseCard.getValue(card.getId());
                    int value2 = TLMNChooseCard.getValue(arrayCard.getArrCardChoose()[len - 1]);
                    if (!(value1 == value2) &&
                        !(value1 == value2 + 1) &&
                        !(RTL.getCardInfo(card.getId())[1] == RTL
                          .getCardInfo(arrayCard.getArrCardChoose()[len - 1])[1] - 1))
                    {
                        int valuve3 = RTL.getCardInfo(arrayCard.getArrCardChoose()[0])[1];
                        if (!(value1 == valuve3) && !(value1 == valuve3 + 1) && !(value1 == valuve3 - 1))
                        {
                            if (!TLMNChooseCard.issanh2(TLMNPlayer.sort(RTL.insertArray(arrayCard.getArrCardChoose(),
                                                                                        card.getId()))) &&
                                !TLMNChooseCard
                                .isdoi(RTL.insertArray(arrayCard.getArrCardChoose(), card.getId())) &&
                                !TLMNChooseCard
                                .issam(RTL.insertArray(arrayCard.getArrCardChoose(), card.getId())))
                            {
                                for (int i = 0; i < arrayCard.getSize(); i++)
                                {
                                    arrayCard.getCardbyPos(i).setChoose(false);
                                }
                                len = 0;
                            }
                        }
                    }

                    if (tlmnStage != null && tlmnStage.tableArrCard != null && arrayCard.getArrCardChoose() != null &&
                        arrayCard.getArrCardChoose().Length > 0)
                    {
                        if (!TLMNChooseCard.issanh2(TLMNPlayer.sort(RTL.insertArray(arrayCard.getArrCardChoose(),
                                                                                    card.getId()))) &&
                            !TLMNChooseCard.isdoi(RTL.insertArray(arrayCard.getArrCardChoose(), card.getId())) &&
                            !TLMNChooseCard.issam(RTL.insertArray(arrayCard.getArrCardChoose(), card.getId())))
                        {
                            for (int i = 0; i < arrayCard.getSize(); i++)
                            {
                                arrayCard.getCardbyPos(i).setChoose(false);
                            }
                            len = 0;
                        }
                    }
                }
            }

            card.setChoose(!card.isChoose);

            if (tlmnStage != null && tlmnStage.tableArrCard != null)
            {
                if (tlmnStage.tableArrCard.Length > 0 && len == 0)
                {
                    int indexCardChoose = -1;
                    if (arrayCard.getArrCardChoose() == null)
                    {
                        return;
                    }
                    if (arrayCard.getArrCardChoose().Length == 1)
                    {
                        for (int i = 0; i < arrayCard.getArrCardAll().Length; i++)
                        {
                            if (arrayCard.getArrCardAll()[i] == card.getId())
                            {
                                indexCardChoose = i;
                            }
                        }
                        if (indexCardChoose != -1)
                        {
                            int[] index = TLMNChooseCard.getArrIndexCardNhac(indexCardChoose,
                                                                             arrayCard.getArrCardAll(), tlmnStage.tableArrCard);
                            if (index != null)
                            {
                                for (int i = 0; i < index.Length; i++)
                                {
                                    Card cardNhac = arrayCard.getCardbyPos(index[i]);
                                    if (cardNhac != null)
                                    {
                                        cardNhac.setChoose(true);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                if (arrayCard.getArrCardChoose() == null)
                {
                    return;
                }
                if (arrayCard.getArrCardChoose().Length == 2 && card.isChoose)
                {
                    int[] index = TLMNChooseCard.getArrIndexCardNhac(arrayCard.getArrCardChoose(),
                                                                     arrayCard.getArrCardAll());
                    if (index != null)
                    {
                        for (int i = 0; i < index.Length; i++)
                        {
                            Card cardNhac = arrayCard.getCardbyPos(index[i]);
                            if (cardNhac != null)
                            {
                                cardNhac.setChoose(true);
                            }
                        }
                    }
                    if (index != null && index.Length < 2)
                    {
                        if (!TLMNChooseCard.issanh2(arrayCard.getArrCardChoose()))
                        {
                            for (int i = 0; i < arrayCard.getSize(); i++)
                            {
                                arrayCard.getCardbyPos(i).setChoose(false);
                            }
                            card.setChoose(!card.isChoose);
                        }
                    }
                }
                else if (arrayCard.getArrCardChoose().Length >= 2 && card.isChoose)
                {
                    if (!TLMNChooseCard.issanh2(arrayCard.getArrCardChoose()))
                    {
                        for (int i = 0; i < arrayCard.getSize(); i++)
                        {
                            arrayCard.getCardbyPos(i).setChoose(false);
                        }
                        card.setChoose(!card.isChoose);
                    }
                }
                else if (arrayCard.getArrCardChoose().Length >= 2 && !card.isChoose)
                {
                    // int indexCardChoose = -1;
                    // for (int i = 0; i < arrayCard.getArrCardAll().Length;
                    // i++) {
                    // if (arrayCard.getArrCardAll()[i] == card.getId()) {
                    // indexCardChoose = i;
                    // }
                    // }
                    // if (indexCardChoose != -1) {
                    // for (int i = indexCardChoose; i <
                    // arrayCard.getArrCardAll().Length; i++) {
                    // arrayCard.getCardbyPos(i).setChoose(false);
                    // }
                    // }
                }
            }
        }
    }
Beispiel #12
0
    public static int checkThung(int[] cards)
    {
        int[] y = new int[4];
        int   x = -1;

        int[] cardThung = null;
        for (int i = 0; i < cards.Length; i++)
        {
            switch (getType(cards[i]))
            {
            case 0:
                y[0]++;
                if (y[0] > 4)
                {
                    x = 0;
                }
                break;

            case 1:
                y[1]++;
                if (y[1] > 4)
                {
                    x = 1;
                }
                break;

            case 2:
                y[2]++;
                if (y[2] > 4)
                {
                    x = 2;
                }
                break;

            case 3:
                y[3]++;
                if (y[3] > 4)
                {
                    x = 3;
                }
                break;

            default:
                break;
            }
        }
        if (x != -1)
        {
            for (int i = 0, n = cards.Length; i < n; i++)
            {
                if (getType(cards[i]) == x)
                {
                    cardThung = RTL.insertArray(cardThung, cards[i]);
                }
            }
            if (checkSanhPK(cardThung) && cardThung.Length > 4)
            {
                return(8);
            }
            return(5);
        }
        else
        {
            if (checkSanhPK(cards))
            {
                return(4);
            }
        }
        return(0);
    }
Beispiel #13
0
    private static int[] nhacsanh(int indexFocus, int[] cardHand, int[] cardFire)
    {
        int[] indexCardNhac = null;
        if (cardHand == null || cardHand.Length < cardFire.Length)
        {
            return(null);
        }
        int temp = -1;

        int[] sanh   = null;
        int[] cardUp = null;
        for (int i = indexFocus; i < cardHand.Length; i++)
        {
            if (temp == -1)
            {
                temp   = getValue(cardHand[i]);
                sanh   = RTL.insertArray(sanh, i);
                cardUp = RTL.insertArray(cardUp, cardHand[i]);
            }
            else if ((getValue(cardHand[i]) == 1 ? 14 : getValue(cardHand[i])) == temp + 1)
            {
                sanh   = RTL.insertArray(sanh, i);
                cardUp = RTL.insertArray(cardUp, cardHand[i]);
                temp   = (getValue(cardHand[i]) == 1 ? 14 : getValue(cardHand[i]));
                if (sanh.Length == cardFire.Length)
                {
                    break;
                }
            }
        }
        if (sanh.Length != cardFire.Length &&
            (getValue(cardHand[indexFocus]) >= getValue(cardFire[cardFire.Length - 1]) || getValue(cardHand[indexFocus]) == 1))
        {
            if (getValue(cardHand[indexFocus]) == getValue(cardFire[cardFire.Length - 1]) &&
                cardHand[indexFocus] < cardFire[cardFire.Length - 1])
            {
                return(null);
            }
            sanh = null;
            for (int i = indexFocus; i >= 0; i--)
            {
                if (temp == -1)
                {
                    temp   = getValue(cardHand[i]);
                    sanh   = RTL.insertArray(sanh, i);
                    cardUp = RTL.insertArray(cardUp, cardHand[i]);
                }
                else if ((getValue(cardHand[i]) == 1 ? 14 : getValue(cardHand[i])) == temp - 1)
                {
                    sanh   = RTL.insertArray(sanh, i);
                    cardUp = RTL.insertArray(cardUp, cardHand[i]);
                    temp   = (getValue(cardHand[i]) == 1 ? 14 : getValue(cardHand[i]));
                }
                if (sanh.Length == cardFire.Length)
                {
                    break;
                }
            }
        }
        try {
            if (sanh != null && sanh.Length == cardFire.Length)
            {
                if (getValue(cardHand[sanh[sanh.Length - 1]]) == getValue(cardFire[cardFire.Length - 1]))
                {
                    if (sanh.Length < cardHand.Length)
                    {
                        if (getValue(cardHand[sanh[sanh.Length - 1]]) == getValue(cardHand[sanh[sanh.Length - 1] + 1]))
                        {
                            sanh[sanh.Length - 1]    += 1;
                            cardUp[cardUp.Length - 1] = cardHand[sanh[sanh.Length - 1]];
                        }
                    }
                    if (sanh.Length < cardHand.Length)
                    {
                        if (getValue(cardHand[sanh[sanh.Length - 1]]) == getValue(cardHand[sanh[sanh.Length - 1] + 1]))
                        {
                            sanh[sanh.Length - 1]    += 1;
                            cardUp[cardUp.Length - 1] = cardHand[sanh[sanh.Length - 1]];
                        }
                    }
                    if (sanh.Length < cardHand.Length)
                    {
                        if (getValue(cardHand[sanh[sanh.Length - 1]]) == getValue(cardHand[sanh[sanh.Length - 1] + 1]))
                        {
                            sanh[sanh.Length - 1]    += 1;
                            cardUp[cardUp.Length - 1] = cardHand[sanh[sanh.Length - 1]];
                        }
                    }
                }
            }
        } catch (Exception e) {
            // TODO: handle exception
        }

        if (sanh != null && sanh.Length == cardFire.Length && compareCard(cardUp, cardFire))
        {
            indexCardNhac = new int[cardFire.Length];
            for (int j = 0; j < cardFire.Length; j++)
            {
                indexCardNhac[j] = sanh[j];
            }
        }

        return(indexCardNhac);
    }