8 Replies - 791 Views - Last Post: 06 October 2017 - 05:01 AM Rate Topic: -----

#1 MurcsRoyce  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 02-October 17

Reads Four of Kind when should be full house

Posted 02 October 2017 - 10:20 PM

I have debugged for countless hours. I do not understand why no other part of this code has errors besides four of kind/ full house. So unbelievably frustrating. Full house pops but sometimes it registers as four of a kind.

for (int i = 0 ; i < diceResults.Length; i++)
            {

                if  (diceResults[0] == 1 &&
                     diceResults[1] == 1 &&
                     diceResults[2] == 1 &&
                     diceResults[3] == 1 &&
                     diceResults[4] == 1 &&
                     diceResults[5] == 1)

                    Straight = true;

                else if (diceResults[i] == 6)
                    sixKind = true;

                else if (diceResults[i] == 5)
                    fiveKind = true;

                else if (diceResults[i] == 4)
                {
                    fourKind = true;

                    for (int j = i + 1; j < diceResults.Length; j++)
                    {
                        if (diceResults[j] == 2)
                            fullHouse = true;
                    }
                }

                else if (diceResults[i] == 3)
                {
                    threeKind = true;

                    for (int j = i + 1; j < diceResults.Length; j++)
                    {
                        if (diceResults[j] == 3)
                            twoSets = true;
                    }
                }
                else if (diceResults[i] == 2)
                {
                    onePair = true;

                    for (int j = i + 1; j < diceResults.Length; j++)
                    {
                        if (diceResults[j] == 2)
                        {
                            twoPair = true;

                            for (int h = j + 1; h < diceResults.Length; h++)
                            {
                                if (diceResults[h] == 2) 
                                    threePair = true;
                            }
                        }
                    }
                }
            }

            for (int i = 0; i < dice.Length; i++)
           
                {
                switch (dice[i])
                {
                    case 6:
                        haveSix = true;
                        break;
                    case 5:
                        haveFive = true;
                        break;
                    case 4:
                        haveFour = true;
                        break;
                    case 3:
                        haveThree = true;
                        break;
                    case 2:
                        haveTwo = true;
                        break;
                    case 1:
                        haveOne = true;
                        break;
                }
            }

            if (sixKind)
                lbl_displayResults.Text = "Six of a Kind";
            else if (fiveKind)
                lbl_displayResults.Text = "Five of a Kind";
            else if (fullHouse)
                lbl_displayResults.Text = "Full House";
            else if (fourKind)
                lbl_displayResults.Text = "Four of a Kind";
            else if (Straight)
                lbl_displayResults.Text = "High Straight";
            else if (twoSets)
                lbl_displayResults.Text = "Two Sets of Three";
            else if (threeKind)
                lbl_displayResults.Text = "Three of a Kind";
            else if (threePair)
                lbl_displayResults.Text = "Three Pair";
            else if (twoPair)
                lbl_displayResults.Text = "Two Pair";
            else if (onePair)
                lbl_displayResults.Text = "One Pair";
            else if (haveSix)
                lbl_displayResults.Text = "Six High";
            else if (haveFive)
                lbl_displayResults.Text = "Five High";
            else if (haveFour)
                lbl_displayResults.Text = "Four High";
            else if (haveThree)
                lbl_displayResults.Text = "Three High";
            else if (haveTwo)
                lbl_displayResults.Text = "Two High";
            else if (haveOne)
                lbl_displayResults.Text = "One High";
        }




just when you think you got no errors . BOOM! SCREEN SHOT!

Is This A Good Question/Topic? 0
  • +

Replies To: Reads Four of Kind when should be full house

#2 JapanDave  Icon User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 366
  • Joined: 01-February 16

Re: Reads Four of Kind when should be full house

Posted 03 October 2017 - 01:16 AM

What are the rules? How many times can you roll the dice? What constitutes a full house?

With that code , I was able to return true for each variable, so there has to be a set of rules to make this work.
Was This Post Helpful? 0
  • +
  • -

#3 MurcsRoyce  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 02-October 17

Re: Reads Four of Kind when should be full house

Posted 03 October 2017 - 01:19 AM

View PostJapanDave, on 03 October 2017 - 01:16 AM, said:

What are the rules? How many times can you roll the dice? What constitutes a full house?

With that code , I was able to return true for each variable, so there has to be a set of rules to make this work.

Was This Post Helpful? 0
  • +
  • -

#4 JapanDave  Icon User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 366
  • Joined: 01-February 16

Re: Reads Four of Kind when should be full house

Posted 03 October 2017 - 01:30 AM

I don't see a reply???? Just a quote of what I just wrote???
Was This Post Helpful? 0
  • +
  • -

#5 MurcsRoyce  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 02-October 17

Re: Reads Four of Kind when should be full house

Posted 03 October 2017 - 01:30 AM

There are no rules or points and you only roll one time . The six dice readout is taken for face value upon hitting tge role button. Simply trying to achieve zero bugs.

Example is : 366366 Is a full house any 4 of the same and any 2 of the same. You can see that in code in the four of a kind loop. This is mind boggling considering the same looping statements are used for three sets, 2pair,3pair, 2sets of three, which all work perfectly.

I just rolled 366366 and my readout was four of a kind, should be full house. All the loops do the same thing , however four of a kind and fullhouse are producing a bug. Makes no sense and im stumped.
Was This Post Helpful? 0
  • +
  • -

#6 MurcsRoyce  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 02-October 17

Re: Reads Four of Kind when should be full house

Posted 03 October 2017 - 01:38 AM

Id be impressed if anyone has a reason why all the other loops work and fullhouse is bugged
Was This Post Helpful? 0
  • +
  • -

#7 MurcsRoyce  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 02-October 17

Re: Reads Four of Kind when should be full house

Posted 03 October 2017 - 01:51 AM

I forgot to address the fact that its a random bug. 333434 just produced a fullhouse, and position of where the numbers are has no value. Example is the straight statement. No matter where 1-6 land on the board in any order will produce a straight. My fullhouse is randomly broke Wow.
Was This Post Helpful? 0
  • +
  • -

#8 JapanDave  Icon User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 366
  • Joined: 01-February 16

Re: Reads Four of Kind when should be full house

Posted 03 October 2017 - 02:19 AM

OK, just briefly going through your code, you are looping through each char and each time setting a bool to a variable. My opinion is that you are taking the wrong approach here, as you have the possiblity of setting true vaules to many variables and like you are experiencing, which ever comes first in the final if statement will determine what rule was hit.

I personally would make a list of the rules and treat each string as a whole, not one char at a time.

Maybe something like this,

string diceResults = "236366";
            
            List<int> countResult = new List<int>();

            for (int i = 0; i < 10; i++)
            {
                int count = Regex.Matches(diceResults, i.ToString()).Count;
                if (count > 0)
                {
                    countResult.Add(count);
                }
            }

            if (countResult.Count == 1)
            {
                Console.WriteLine("Straight");
            }
            else if (countResult.Count == 2)
            {
                Console.WriteLine(countResult.Any(s => s == 5) ? "five of a kind" : "full house");
            }
            else if (countResult.Count == 3)
            {
                if (countResult.Any(s => s == 4))
                {
                    Console.WriteLine("Four of a kind");
                }
                else if (countResult.Any(s => s == 3 && s == 2))
                {
                    Console.WriteLine("Three of a kind and two of a kind");
                }
            }
            else if (countResult.Count == 4)
            {
                //your rules
            }
            else if (countResult.Count == 5)
            {
                //your rules
            }
            else if (countResult.Count == 6)
            {
                //your rules
            }  



You would have to Finnish the last of the rules according to hgow you want them displayed. But the idea is that you can only EVER return one result for one rule.

This post has been edited by JapanDave: 03 October 2017 - 02:21 AM

Was This Post Helpful? 1
  • +
  • -

#9 JapanDave  Icon User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 366
  • Joined: 01-February 16

Re: Reads Four of Kind when should be full house

Posted 06 October 2017 - 05:01 AM

I would love to know how you got on with this issue? What did you end up doing?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1