0

I'm trying to create a poker dice game. There are comp player and user player. Each player will roll dice 5 times. Basically, it likes create 2 random array, with 5 elements in each array. I'm trying to compare the outcome of these 2 arrays. For example; 2 pairs beat 1 pair/ 3 of a kind beat 2 pair/Fullhouse beat 3 of a kind and 2 pair...

I'm stuck at the comparing part. Don't know how to do it in the shortest way.

```
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DiceRoller
{
class Program
{
//Declare and initilize variables
static int[] userDiceCount = { 1, 1, 1, 1, 1, 0 };
static int[] userDice = { 1, 2, 3, 4, 5 };
static int[] compDiceCount = { 1, 1, 1, 1, 1, 0 };
static int[] compDice = { 1, 2, 3, 4, 5 };
//main Method runs first and contains main loop
static void Main(string[] args)
{
Console.WriteLine("Let's play some poker dice game"); //Output to inform user
userRollDice();
System.Threading.Thread.Sleep(20);
Console.WriteLine();
compRollDice();
}
//Rolls the vitual dice
static void userRollDice()
{
Random rand = new Random();//Declare and initilize random number
Array.Clear(userDiceCount, 0, 6);//Clear dice count array
Console.WriteLine("You rolled:");//Inform user what they rolled
for (int i = 0; i < userDice.Length; i++)
{
userDice[i] = rand.Next(6) + 1;//Gets a random number from 1 to 6
Console.Write("{0} ", userDice[i]); //output each dice
userDiceCount[userDice[i] - 1]++; //Increment that dice's number counter
}
Console.WriteLine();
Console.WriteLine("You have:");//Inform user
Console.WriteLine(checkHandUser());//Output results of checkHand Function
}
static void compRollDice()
{
Random rand = new Random();//Declare and initilize random number
Array.Clear(compDiceCount, 0, 6);//Clear dice count array
Console.WriteLine("Computer rolled:");//Inform user what they rolled
for (int i = 0; i < compDice.Length; i++)
{
compDice[i] = rand.Next(6) + 1;//Gets a random number from 1 to 6
Console.Write("{0} ", compDice[i]); //output each dice
compDiceCount[compDice[i] - 1]++; //Increment that dice's number counter
}
Console.WriteLine();
Console.WriteLine("Computer have:");//Inform user
Console.WriteLine(checkHandComp());//Output results of checkHand Function
}
//Determines the poker hand based on the dice the user has
static String checkHandUser()
{
//Declare and initialize local variables
String result = "Nothing";
int numberOfPairs = 0;
Boolean threeOfKind = false;
int highestCount = 0;
//Loop thorugh the counted dice list
for (int i = 0; i < userDiceCount.Length; i++)
{
if (userDiceCount[i] == 2) //If there are 2 of a dice number
{
numberOfPairs++; //Increment the amount of pairs
if (numberOfPairs >= 1 && numberOfPairs <= 2)
{//If one pair or two pairs
result = numberOfPairs + " Pair(s)"; //output the number of pairs
}
}
else if (userDiceCount[i] >= 3) //If 3 or more of a dice number
{
result = userDiceCount[i] + " of a kind"; //Output the number of a kind
if (userDiceCount[i] == 3) //If its a 3 of a kind,
{
threeOfKind = true;//set a flag to true, used to check for full house
}
}
//Check for highest number of a single dice number, used to check for straight
if (userDiceCount[i] > highestCount)
{
highestCount = userDiceCount[i];
}
}
if (threeOfKind && numberOfPairs >= 1)//if a three of a kind and a pair is found,
{
result = "Full House"; //it must be a full house
}
//if the highest amount of a dice number is 1, and there are no ones or no sixs,
if (highestCount == 1 && (userDiceCount[0] == 0 || userDiceCount[5] == 0))
{
result = "Straight"; //It must be a straight
}
return result;
}//Return the determined hand
static String checkHandComp()
{
//Declare and initialize local variables
String result = "Nothing";
int numberOfPairs = 0;
Boolean threeOfKind = false;
int highestCount = 0;
//Loop thorugh the counted dice list
for (int i = 0; i < compDiceCount.Length; i++)
{
if (compDiceCount[i] == 2) //If there are 2 of a dice number
{
numberOfPairs++; //Increment the amount of pairs
if (numberOfPairs >= 1 && numberOfPairs <= 2)
{//If one pair or two pairs
result = numberOfPairs + " Pair(s)"; //output the number of pairs
}
}
else if (compDiceCount[i] >= 3) //If 3 or more of a dice number
{
result = compDiceCount[i] + " of a kind"; //Output the number of a kind
if (compDiceCount[i] == 3) //If its a 3 of a kind,
{
threeOfKind = true;//set a flag to true, used to check for full house
}
}
//Check for highest number of a single dice number, used to check for straight
if (compDiceCount[i] > highestCount)
{
highestCount = compDiceCount[i];
}
}
if (threeOfKind && numberOfPairs >= 1)//if a three of a kind and a pair is found,
{
result = "Full House"; //it must be a full house
}
//if the highest amount of a dice number is 1, and there are no ones or no sixs,
if (highestCount == 1 && (compDiceCount[0] == 0 || compDiceCount[5] == 0))
{
result = "Straight"; //It must be a straight
}
return result;
}//Return the determined hand
}
}
```