Пример #1
0
    //Three or four same, pair
    static void CalculateAmountOfSameDices(SingleLine sl, int threeOrFour)
    {
        int amount = 0; //points to be given if three same dices
        Dictionary <int, int> tempDict = new Dictionary <int, int>();

        foreach (int i in nums)
        {
            if (tempDict.ContainsKey(i))
            {
                tempDict[i] += 1;
            }
            else
            {
                tempDict.Add(i, 1);
            }
            amount += i;
        }

        //if the highest value in tempdict is equal or higher than the checked number, the dice row meets the requirements for giving points
        foreach (KeyValuePair <int, int> kvp in tempDict)
        {
            if (kvp.Value >= threeOrFour)
            {
                sl.SetDicePoints(amount);
                return;
            }
        }
        //HOX if there are enough of the same number code beyond this point(return) will not be executed
        sl.SetDicePoints(0);
    }
Пример #2
0
    //two pairs
    static void CalculateTwoPairs(SingleLine sl)
    {
        int amount = 0; //points to be given two pairs
        Dictionary <int, int> tempDict = new Dictionary <int, int>();

        foreach (int i in nums)
        {
            if (tempDict.ContainsKey(i))
            {
                tempDict[i] += 1;
            }
            else
            {
                tempDict.Add(i, 1);
            }
            amount += i;
        }
        //if tempdict has more than 3 kvps, two pairs is impossible, give 0 points
        if (tempDict.Count > 3)
        {
            sl.SetDicePoints(0);
            return;
        }
        //if the highest kvp value is 4 or more, the dice row is for example 11112, which counts as two pairs (2 sets of 1 1)
        foreach (KeyValuePair <int, int> kvp in tempDict)
        {
            if (kvp.Value >= 4)
            {
                sl.SetDicePoints(amount);
                return;
            }
        }
        //finally checking for two pairs, both with different digit (or a full house)
        int amountOfPairs = 0;

        foreach (KeyValuePair <int, int> kvp in tempDict)
        {
            if (kvp.Value == 2 || kvp.Value == 3)
            {
                amountOfPairs++;
            }
        }
        if (amountOfPairs >= 2)
        {
            sl.SetDicePoints(amount);
        }
        //if dice row is for example one pair or three same
        else
        {
            sl.SetDicePoints(0);
        }
    }
Пример #3
0
    //Random
    static void CalculateRandom(SingleLine sl)
    {
        int amount = 0;

        foreach (int i in nums)
        {
            amount += i;
        }
        sl.SetDicePoints(amount);
    }
Пример #4
0
    //lines 1-6
    static void CalculateUpperPart(SingleLine sl)
    {
        int amount  = 0;
        int lineNum = System.Int32.Parse(sl.lineType.Replace("upper", ""));

        foreach (int i in nums)
        {
            if (i == lineNum)
            {
                amount += i;
            }
        }
        sl.SetDicePoints(amount);
    }