C++ Code:
Suppose there is a game with two options: A and B. Each of these options adds a different amount of points from a range of numbers. You start with 0 points and your goal is to reach 19 or 20 points.
For example, suppose you had the following options:
A = number between 4 through 7.
B = number between 1 through 8.
A sample game might go:
Points = 0, choose option A(add 4-7).
Points = 4, choose option B(add 1-8).
Points = 12, choose option B(add 1-8).
Points = 16, choose option B(add 1-8).
Points = 21, you lose.
Make a program that asks the user to give the ranges for both options A and B. You may assume that both options A and B have a minimum of adding at least one point.
To figure out which moves are the best, simulate 10,000,000 games (this should take about 5 seconds to run) with random choices at each turn. Record how often you won/lost the game for each point value and each option picked. If you won the game, each point/option along the whole game should get a +1 and each loss a -1.
Thus if the sample game above was the first game played, you should keep the tally:
0 Points: A=-1, B=0
1Points: A=0, B=0
2 Points: A=0, B=0
3 Points: A=0, B=0
4 Points: A=0, B=-1
5 Points: A=0, B=0
6 Points: A=0, B=0
7 Points: A=0, B=0
8 Points: A=0, B=0
9 Points: A=0, B=0
10 Points: A=0, B=0
11 Points: A=0, B=0
12 Points: A=0, B=-1
13 Points: A=0, B=0
14 Points: A=0, B=0
15 Points: A=0, B=0
16 Points: A=0, B=-1
17 Points: A=0, B=0
18 Points: A=0, B=0
At the end, show which option is best to play for each point value (i.e. whichever tally is higher). (Note: there is also a mathematical way to figure out the best moves in games like this involving expected values of random variables.)
------------------------------------------------------------------------------------------
Example 1:
Enter Option A range:
4-7
Enter Option B range:
1-8
Points=0, should play B
Points=1, should play A
Points=2, should play A
Points=3, should play A
Points=4, should play B
Points=5, should play B
Points=6, should play B
Points=7, should play A
Points=8, should play A
Points=9, should play A
Points=10,should play B
Points=11, should play B
Points=12, should play B
Points=13, should play A
Points=14, should play A
Points=15, should play A
Points=16, should play B
Points=17, should play B
Points=18, should play B
--------------------------------------
Example 2:
Enter Option A range:
1-10
Enter Option B range:
5-5
Points=0, should play B
Points=1, should play A
Points=2, should play A
Points=3, should play A
Points=4, should play B
Points=5, should play B
Points=6, should play A
Points=7, should play A
Points=8, should play A
Points=9, should play B
Points=10, should play B
Points=11, should play A
Points=12, should play A
Points=13, should play A
Points=14, should play B
Points=15, should play B Points=16, should play A
Points=17, should play A
Points=18, should play A
Executable code
//Include the needed header files
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <limits.h>
#include <time.h>
using namespace std;
//Driver
int main ()
{
//Function srand()
srand(time(NULL));
//Declare the needed variable
int minimumA, maximumA, minimumB,
maximumB;
//Prompt for input
cout << "Enter range for A: ";
//Read input
cin >> minimumA;
//Read input
cin >> maximumA;
//Prompt for input
cout << "Enter range for B: ";
//Read input
cin >> minimumB;
//Read input
cin >> maximumB;
//Declare an array
int pointToACounter[19];
//Declare an array
int pointToBCounter[19];
//Declare and initialize A range
int rangeA = maximumA-minimumA+1;
//Declare and initialize B range
int rangeB = maximumB-minimumB+1;
//Declare and initialize point
int point = 0;
//Loop
for (int inc1=0; inc1<10000; inc1++)
{
//Declare and initialize
listOfPoints
int listOfPoints[100000] =
{-1};
//Declare and initialize
listOfOptions
int listOfOptions[100000] =
{-1};
//Declare and initialize
indices
int index1 = 0, index2=
0;
//Initialize point
point = 0;
//Loop
while (point <= 18)
{
//Initialize
int choice
= rand()%(2);
//Update
listOfPoints
listOfPoints[index1] = point;
//Update
listOfOptions
listOfOptions[index2] = choice;
//Increment index1
index1++;
//Increment index2
index2++;
//Check
condition
if (choice
== 0)
{
//Update point
point += (rand()%(rangeA) + minimumA);
}
//Otherwise
else
{
//Update point
point += (rand()%(rangeB) + minimumB);
}
}
//Update
int totalOffset = -1;
//Check condition
if (point == 19 || point ==
20)
{
//Update
totalOffset = 1;
}
for (int inc2=0; inc2 <
index1; inc2++)
{
//Check
condition
if(
listOfOptions[inc2] != -1)
{
//Check condition
if (listOfOptions[inc2] == 0)
{
//Update
pointToACounter[listOfPoints[inc2]] += totalOffset;
}
//Otherwise
else
{
//Update
pointToBCounter[listOfPoints[inc2]] += totalOffset;
}
}
}
}
//Loop
for (int inc1=0; inc1<=18; inc1++)
{
//Display
cout << "Point="
<< inc1 << ", should play " <<
((pointToACounter[inc1] >= pointToBCounter[inc1] ? "A" : "B"))
<< endl;
}
//Pause
cin.get();cin.get();
//Stop
return 0;
}
C++ Code: Suppose there is a game with two options: A and B. Each of these...
C# Code: Write the code that simulates the gambling game of craps. To play the game, a player rolls a pair of dice (2 die). After the dice come to rest, the sum of the faces of the 2 die is calculated. If the sum is 7 or 11 on the first throw, the player wins and the game is over. If the sum is 2, 3, or 12 on the first throw, the player loses and the game is...
1. Marcus purchased a game card to simulator, which costs 7 points for each play, and the snowboard simulator, which costs 5 points for each play. Marcus came with enough money to buy a 50-point card, and he has time to play 8 play virtual games at the arcade. His favorite games are the race car games. A. Write a system of equations to represent this scenario. B. Solve the system from part A using Cramer's Rule to find the...
We find ourselves at a fancy casino in Las Vegas, and decide to try our luck at a card game played with a standard deck of cards. The card game has a number of options to choose from, and we intend to play the game with the best odds. However, we are going to need to calculate the odds before we play. As a reminder, a "standard" deck of playing cards consists of 52 Cards in each of the 4...
A and B play a series of games. Each game is independently won by A with probability p and by B with probability 1−p. They stop when the total number of wins of one of the players is two greater than that of the other player. The player with the grater number of total wins is declared the winner of the series. Find the probability that a total of 4 games are played. Please explain as much as possible.
8) Suppose your team participate in a football tournament in which you play n games. Since you are a very average team, each game is equally likely to be a win, a loss, or a tie. You collect 3 points for each win, 1 point for each tie, and 0 points for each loss. The outcome of each game is independent of the outcome of every other game. Let X be the number of points you earn for game i...
NEED LAST 2 Two individuals, A and B, are finalists for a chess championship. They will play a sequence of games, each of which can result in a win for A, a win for B, or a draw. Suppose that the outcomes of successive games are independent, with P(A wins game) = 0.3, P(B wins game) = 0.2, and P(draw) = 0.5. Each time a player wins a game, he earns 1 point and his opponent earns no points. The...
Write a c program that will allow two users to play a tic-tac-toe game. You should write the program such that two people can play the game without any special instructions. (assue they know how to play the game). Prompt first player(X) to enter their first move. .Then draw the gameboard showing the move. .Prompt the second player(O) to enter their first move. . Then draw the gameboard showing both moves. And so on...through 9 moves. You will need to:...
2. (25 points) Sekora International Casino (SIC) is launching a new game making use of fair 6-sided dice . In phase 1, roll two 6-sided dice and compute the difference between the rolls. Call this difference . In phase 2, roll r dice, and add up the total of the rolls. This is the payout in dollars of the game. (with the numbers 1-6 on the sides). The game proceeds in two phases as follows: (a) (5 points) In the...
Question 3 [10 points] Bob and Doug play a lot of Ping-Pong, but Doug is a much better player, and wins 90% of their games. To make up for this, if Doug wins a game he will spot Bob tive points in their next game. if Doug wins again he will spot Bob ten points the next game, and if he still wins the next game he will spot him ifteen points, and continue to spot hinm ifteen points as...
This program should be in c++. Rock Paper Scissors: This game is played by children and adults and is popular all over the world. Apart from being a game played to pass time, the game is usually played in situations where something has to be chosen. It is similar in that way to other games like flipping the coin, throwing dice or drawing straws. There is no room for cheating or for knowing what the other person is going to...