1. Problem Description
Language: JAVA
The game of Poker Dice is a bit like standard poker but played with dice instead of cards. In this game, five fair dice are rolled. We will recognize one of seven different hands, in order of increasing value:
None alike: Five distinct die values occur. Example: 1, 3, 4, 5, 6
One Pair: Four distinct die values occur; one die value occurs twice and the other three die
values occur once each. Example: 1, 2, 3, 3, 5
Two Pairs: Three distinct die values occur; two different die values occurs twice and the other
die value occurs once each. Example: 1, 1, 3, 4, 4
Three of a Kind: Three distinct die values occur; one die value occurs three times and the other
two die values occur once each. Example: 2, 3, 4, 4, 4
Full House: Two distinct die values occur; one die value occurs three times and the other die
value occurs twice. Example: 4, 4, 6, 6, 6
Four of a kind: Two distinct die values occur; one die value occurs four times and the other
die value occurs once. Example: 3, 5, 5, 5, 5
Five of a kind: Once die value occurs five times. Example: 2, 2, 2, 2, 2
In our simplified version of the game, this is a one-roll sudden death. You are not given another chance to re-roll some of your dice to improve your hand. When played between two people, the higher hand wins (e.g. Three of a Kind beats Two Pair, Five of a Kind beats all, etc.).
However, we aren’t concerns with actually playing the game, but calculating the odds of each particular hand. The program will roll the dice a number of times and keep track of how many times each hand occurs. Afterwards, display the % of times that each hand occurs.
Run the application with 100 trials, 1000 trials, 10,000 trials and finally 1,000,000 trials. As the number of trials goes up, you will get closer and closer to the mathematical answers shown below:
Case |
Description |
Approx. Calculated Value |
None 0.09259
One Pair 0.46296
Two Pairs 0.23148
Three of a Kind 0.15432
Full House 0.03858
Four of a Kind 0.01929
Five of a Kind 0.00077
For this problem you will build on the Die class you created.
Your source code should be set to roll the dice 1,000,000 times.
Turn in only your source files.
Do not use a package.
Required Main Class
- PokerDice
Required Input
None
Required Output
Your output should look something like the following example. It must include your name, number of trials, name of each hand and its probability (as a decimal with six digits after the decimal point).
Your numbers will likely be a little different since this simulation is based on random numbers. However, as your number of trials increases, they should get closer and closer to the mathematically calculated values estimated in the table above.
Poker Dice Probability Calculator - E. Eckert Running 1,000,000 trials
Case 1, None alike, is 0.092533 Case 2, One pair, is 0.462799 Case 3, Two pair, is 0.231789 Case 4, Three of a kind, is 0.154192 Case 5, Full house, is 0.038595 Case 6, Four of a kind, is 0.019316 Case 7, Five of a kind is 0.000776
If you have any problem with the code feel free to comment.
Program
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
/*Die class*/
class Die {
private int sides;
private int value;
public Die() {
sides = 6;
}
public Die(int sides) {
this.sides = sides;
}
public int getSides() {
return sides;
}
public int getValue() {
return value;
}
public void roll() {//roll method
value = (int) (Math.random() *
(sides - 1) + 1);
}
}
public class Test {//driver class for testing
public static void main(String[] args) {
double case1, case2, case3, case4,
case5, case6, case7;
case1 = case2 = case3 = case4 =
case5 = case6 = case7 = 0;
int[] hand = new int[5];
//objects of Die
Die die1 = new Die();
Die die2 = new Die();
Die die3 = new Die();
Die die4 = new Die();
Die die5 = new Die();
int runtime = 1000000;//runtime of the loop
for (int i = 0; i < runtime; i++) {
//rolling the
die
die1.roll();
die2.roll();
die3.roll();
die4.roll();
die5.roll();
//storing the
result in an array
hand[0] =
die1.getValue();
hand[1] =
die2.getValue();
hand[2] =
die3.getValue();
hand[3] =
die4.getValue();
hand[4] =
die5.getValue();
//checking the
condition
if
(fullHouse(hand)) {
case5++;
} else if
(onePair(hand)) {
case2++;
} else if
(twoPair(hand)) {
case3++;
} else if
(threeOfAKind(hand)) {
case4++;
} else if
(fourOfAKind(hand)) {
case6++;
} else if
(fiveOfAKind(hand)) {
case7++;
} else {
case1++;
}
}
//calculating rationadn printing
the result
System.out.println("Poker Dice
Probablity Calculator - trails: " + runtime);
System.out.println("Case 1, None
alike, is " + (case1 / runtime));
System.out.println("Case 2, One
pair, is " + (case2 / runtime));
System.out.println("Case 3, Two
pair, is " + (case3 / runtime));
System.out.println("Case 4, Three
of a kind, is " + (case4 / runtime));
System.out.println("Case 5, Full
house, is " + (case5 / runtime));
System.out.println("Case 6, Four of
a kind, is " + (case6 / runtime));
System.out.println("Case 7, Five of
a kind, is " + (case7 / runtime));
}
//all conditions
private static boolean fullHouse(int[] hand) {
if (onePair(hand) &&
threeOfAKind(hand))
return
true;
else
return
false;
}
private static boolean fiveOfAKind(int[] hand)
{
int tempCount = -1;
int[] distinct = getDistinct(hand);
for (int i = 0; i <
distinct.length; i++) {
for (int j = 0;
j < hand.length; j++) {
if (distinct[i] == hand[j]) {
tempCount++;
}
}
if (tempCount ==
4)
return true;
tempCount =
-1;
}
return false;
}
private static boolean fourOfAKind(int[] hand)
{
int tempCount = -1;
int[] distinct = getDistinct(hand);
for (int i = 0; i <
distinct.length; i++) {
for (int j = 0;
j < hand.length; j++) {
if (distinct[i] == hand[j]) {
tempCount++;
}
}
if (tempCount ==
3)
return true;
tempCount =
-1;
}
return false;
}
private static boolean threeOfAKind(int[] hand)
{
int tempCount = -1;
int[] distinct = getDistinct(hand);
for (int i = 0; i <
distinct.length; i++) {
for (int j = 0;
j < hand.length; j++) {
if (distinct[i] == hand[j]) {
tempCount++;
}
}
if (tempCount ==
2)
return true;
tempCount =
-1;
}
return false;
}
private static boolean twoPair(int[] hand) {
int count = 0;
int tempCount = -1;
int[] distinct = getDistinct(hand);
for (int i = 0; i <
distinct.length; i++) {
for (int j = 0;
j < hand.length; j++) {
if (distinct[i] == hand[j]) {
tempCount++;
}
}
if (tempCount ==
1)
count += tempCount;
tempCount =
-1;
}
if (count == 2)
return
true;
return false;
}
private static boolean onePair(int[] hand) {
int count = 0;
int tempCount = -1;
int[] distinct = getDistinct(hand);
for (int i = 0; i <
distinct.length; i++) {
for (int j = 0;
j < hand.length; j++) {
if (distinct[i] == hand[j]) {
tempCount++;
}
}
if (tempCount ==
1)
count += tempCount;
tempCount =
-1;
}
if (count == 1)
return
true;
return false;
}
//getting the distinct elemenets from the hand
array
private static int[] getDistinct(int[] hand) {
Set<Integer> set = new
TreeSet<>();
for (int i = 0; i < hand.length;
i++) {
set.add(hand[i]);
}
Iterator<Integer> itr =
set.iterator();
int[] ar = new
int[set.size()];
int i=0;
while(itr.hasNext()) {
ar[i++] =
itr.next();
}
return ar;
}
}
Output
1. Problem Description Language: JAVA The game of Poker Dice is a bit like standard poker...
Develop a C++ program which will play a simplified version of the dice game Yahtzee For simplicity, this version of the game only uses four dice No prompting of the user for input values is required Simply use four variables called A, B, C, D to maintain dice roll values int A = 2; No input validation is required as well From the input you will determine if the player rolled 4 of a kind, 3 of a kind, 2...
The Dice game of "Pig" can be played with the following rules. 1. Roll two six-sided dice. Add the face values together. 2. Choose whether to roll the dice again or pass the dice to your opponent. 3. If you pass, then you get to bank any points earned on your turn. Those points become permanent. If you roll again, then add your result to your previous score, but you run the risk of losing all points earned since your...
In a dice game, you roll a fair die three times, independently. If you don’t roll any sixes, you lose 1 dollar. If you roll a six exactly once, you win one dollar. If you roll a six exactly twice, you win two dollars. If you roll a six all three times, you win k dollars. (A) Let k = 3. What is the expected value of the amount you would win by playing this game (rounded to the nearest...
Complete each problem separately and perform in python. 1. Create a script that will roll five dice and print out their values. Allow the user to roll the dice three times. Prompt them to hit enter to roll. Ex: Hit enter to roll 1,4,3,6,6 Hit enter to roll 3,5,1,2,1 Hit enter to roll 4,3,4,2,6 2. Write a script that will roll five dice (just one time). The user's score will be the sum of the values on the dice. Print...
A dice game is played with two distinct 12 sided dice. It costs $3 to roll the pair of dice one time. The payout scheme is as follows 1. Sum of 13 pays $10 Sum of 11 or 15 pays $6 Sum of 7, 9, 17, or 19 pays $3 Any other roll doesn't pay. What is the expected gain/loss after playing the game one time? A "fair" game is one in which the expected gain/loss after playing once is...
1. In a standard five-card draw poker, each player receives 5 cards from a standard deck of 52 cards. Some possible hands in this game are su d in Table 1 below1 (a) Create a sample space to describe all possible hands Bill can play with Let E be the event that the hand contains at least two cards of the same rank and F be the event that the hand contains at least three cards of the same rank...
Problem 9 A single game of craps (a dice game) consists of at most two rolls of a pair of six sided dice. The ways to win are as follows: Win-the first roll of the pair of dice sums to either 7 or 1 (you win, game over, no second roll Win the first roll of the pair of dice does NOT sum to either 7 or 1 but the sum of the second roll is equal to the sum...
Create a Dice Game: PYTHON This game is between two people. They will roll a pair of dice each 10 times. Each roll will be added to a total, and after 10 rolls the player with the highest total will be the Winner! You will use the RANDOM class RANDRANGE to create a random number from 1 to 6. You'll need a function for "rollDice" to roll a pair of dice and return a total of the dice. You must...
I need to write a vb program for a poker game that uses a two-dimensional array... Here is the problem: A poker hand can be stored in a two-dimensional array. The statement Dim hand(3, 12) As Integer declares an array with 52 elements, where the first subscript ranges over the four suits and the second subscript ranges over the thirteen denominations. A poker hand is specified by placing 1%u2019s in the elements corresponding to the cards in the hand. Write...
Problem 6. (20 pts) By definition, a poker hand is a set of 5 cards from a standard French deck of 52 cards1. Solve the following two problems (a) A poker hand is said to be a four of a kind if it has four cards with the same value. For instance, four sevens, four Queens or four Aces. Compute the prob- ability of drawing a four of a kind hand. (b) A poker hand is said to be a...