Exemplo n.º 1
0
    public MeldType MostUselessType(CardsInHand handCards)  //This function is used to find the most useless meld type from a group of cards(hand cards)
    {
        for (int i = 0; i < (int)MeldType.Count; i++)
        {
            int numOfCurrentTypeInHand    = handCards.NumOfCardsOfType((MeldType)i);
            int numOfCurrentTypeInDiscard = state.discardDeck.NumOfCardsOfType((MeldType)i);
            int numOfCardsRevealed        = numOfCurrentTypeInHand + numOfCurrentTypeInDiscard;
            int numOfCardsUnRevealed      = 0;
            if (numOfCurrentTypeInHand % 3 != 0) //If cards of current type is not times of 3(cannot form a meld)
            {
                if (i < 3)                       //For the three special card type(each type only has 4 cards in total)
                {
                    numOfCardsUnRevealed = 4 - numOfCardsRevealed;

                    if (numOfCurrentTypeInDiscard > 1)  //If you can never form a meld with the remainning card
                    {
                        return((MeldType)i);
                    }
                }
                else if (i > 3)         //For other value card types(12 cards for each type in total)
                {
                    numOfCardsUnRevealed = 12 - numOfCardsRevealed;
                    if (numOfCurrentTypeInDiscard > 9)  //If it can never form a meld with the remainning card
                    {
                        return((MeldType)i);
                    }
                }
            }
        }

        //If none of the cards fit the above condition
        for (int i = 0; i < (int)MeldType.Count; i++)    //find the type which u have only 1 card of, loop from low value to high value
        {
            int numOfCurrentTypeInHand = handCards.NumOfCardsOfType((MeldType)i);
            if (numOfCurrentTypeInHand % 3 == 1)
            {
                return((MeldType)i);
            }
        }

        //If none of the cards fit the above condition
        for (int i = 0; i < (int)MeldType.Count; i++)    //find any type that has not formed a meld yet, loop from low value to high value
        {
            int numOfCurrentTypeInHand = handCards.NumOfCardsOfType((MeldType)i);
            if (numOfCurrentTypeInHand % 3 > 0)
            {
                return((MeldType)i);
            }
        }
        Debug.Log("Error, No useless type found");
        return(MeldType.WhiteFlower);
    }
Exemplo n.º 2
0
    public static bool CheckVictory(CardsInHand mCardsInHand)   //Check if there are 3 completed meld
    {
        int numOfCurrentMeldType = 0;
        int completeSetCount     = 0;

        for (int i = 0; i < 12; i++)
        {
            numOfCurrentMeldType = mCardsInHand.NumOfCardsOfType((MeldType)i);

            if (numOfCurrentMeldType == 3)
            {
                completeSetCount += 1;
            }
            else if (numOfCurrentMeldType > 3)
            {
                completeSetCount += (numOfCurrentMeldType - (numOfCurrentMeldType % 3)) / 3;
            }
            if (numOfCurrentMeldType == 8 && completeSetCount == 2)  //2 completeSetCount + 2numOfCurrentMeldType = 0
            {
                Debug.Log("CHERKI");
            }
        }

        if (completeSetCount == 3)
        {
            return(true);
        }
        return(false);
    }
Exemplo n.º 3
0
    public void AnalyseHand(CardsInHand mCardsInHand)//Analyse what melds are currently in the hand  eg.Ones, Nines
    {
        int numOfCurrentCardsOfType = 0;

        for (int i = 0; i < 12; i++)
        {
            numOfCurrentCardsOfType = mCardsInHand.NumOfCardsOfType((MeldType)i);

            //foreach (Card card in mCards)
            if (numOfCurrentCardsOfType == 3)
            {
                foreach (Card card in mCards)
                {
                    #region meldtype
                    if (card.MeldType == MeldType.RedFlower && bRedFlower == false) //so only if it is false then it executes (to prevent spamming of the update and if statement)
                    {
                        iRedFlower++;                                               //this will increase whenever there is a card type
                        if (iRedFlower == 3)                                        //when there is three of the same card (A Meld) then it will add the score
                        {
                            bRedFlower = true;                                      //the bool is set to true so that the condition only occurs once.
                            score     += 3;
                            //Debug.Log("RedFlower detected score is" + score);
                        }
                    }

                    if (card.MeldType == MeldType.WhiteFlower && bWhiteFlower == false)
                    {
                        iWhiteFlower++;
                        if (iWhiteFlower == 3)
                        {
                            bWhiteFlower = true;
                            score       += 3;
                            //Debug.Log("WF" + score);
                        }
                    }

                    if (card.MeldType == MeldType.OldThousand && bOldThousand == false)
                    {
                        iOldThousand++;
                        if (iOldThousand == 3)
                        {
                            bOldThousand = true;
                            score       += 3;
                            //Debug.Log("OT" + score);
                        }
                    }

                    if (card.MeldType == MeldType.Count && bCount == false)
                    {
                        iCount++;
                        if (iCount == 3)
                        {
                            bCount = true;
                            score += 3;
                            //Debug.Log("C" + score);
                        }
                    }

                    if (card.MeldType == MeldType.One && bOne == false)
                    {
                        iOne++;
                        if (iOne == 3)
                        {
                            bOne   = true;
                            score += 3;
                            //Debug.Log("Ones detected score is" + score);
                        }
                    }

                    if (card.MeldType == MeldType.Two && bTwo == false)
                    {
                        iTwo++;
                        if (iTwo == 3)
                        {
                            bTwo   = true;
                            score += 6;
                            //Debug.Log("Twos detected score is" + score);
                        }
                    }

                    if (card.MeldType == MeldType.Three && bThree == false)
                    {
                        iThree++;
                        if (iThree == 3)
                        {
                            bThree = true;
                            score += 9;
                            //Debug.Log("Threes detected score is" + score);
                        }
                    }

                    if (card.MeldType == MeldType.Four && bFour == false)
                    {
                        iFour++;
                        if (iFour == 3)
                        {
                            bFour  = true;
                            score += 12;
                            //Debug.Log("Fours detected " + score);
                        }
                    }

                    if (card.MeldType == MeldType.Five && bFive == false)
                    {
                        iFive++;
                        if (iFive == 3)
                        {
                            bFive  = true;
                            score += 15;
                        }
                    }

                    if (card.MeldType == MeldType.Six && bSix == false)
                    {
                        iSix++;
                        if (iSix == 3)
                        {
                            bSix   = true;
                            score += 18;
                        }
                    }

                    if (card.MeldType == MeldType.Seven && bSeven == false)
                    {
                        iSeven++;
                        if (iSeven == 3)
                        {
                            bSeven = true;
                            score += 21;
                        }
                    }

                    if (card.MeldType == MeldType.Eight && bEight == false)
                    {
                        iEight++;
                        if (iEight == 3)
                        {
                            bEight = true;
                            score += 24;
                        }
                    }

                    if (card.MeldType == MeldType.Nine && bNine == false)
                    {
                        iNine++;
                        if (iNine == 3)
                        {
                            bNine  = true;
                            score += 27;
                        }
                    }
                    #endregion meldtype
                }
                iRedFlower   = 0;
                iWhiteFlower = 0;
                iOldThousand = 0;
                iCount       = 0;
                iOne         = 0;
                iTwo         = 0;
                iThree       = 0;
                iFour        = 0;
                iFive        = 0;
                iSix         = 0;
                iSeven       = 0;
                iEight       = 0;
                iNine        = 0;
            }
        }
    }