//Farkle, also known as “10, 000” or “Dix Mille, ” requires
//six dice and may take place with several people or as a single
//- player game.A turn in Farkle can last as long as the player wants,
//provided that she sets aside at least one scoring die with each roll.
//Players can also set aside more scoring dice if desired.
//If a player throws no points, his turn is over and he player gets
//no points.If all dice score, the player may pick up all six dice
//and throw them again.A one scores 100 points, a five scores 50 points
//and a roll of three ones scores 1, 000 points.Any other set of three
//numbers scores 100 times that number; a roll of three sixes scores 600
//points, for example.A run from one to six scores 3, 000 points, and a
//roll of three pairs of the same number scores 1, 500 points.The game
//ends when the player reaches 10, 000 points or after 10 rounds.
#include
#include
using namespace std;
int random(int min, int max)
{
int range = max - min + 1;
int result = (rand() % range) + min;
return result;
}
void roll(int dice[], bool keepList[])
{
for (int i = 0; i < 6;i++)
{
if (keepList[i] != true)
{
dice[i] = random(1, 6);
}
}
}
void showRollResults(int dice[], bool keepList[])
{
cout << "Dice:\n";
for (int i = 0; i < 6;i++)
{
cout << "die " << i + 1 << " = " << dice[i];
if (keepList[i] == true)
{
cout << "*";
}
cout << endl;
}
}
void getDiceToKeep(bool keepList[])
{
char input;
for (int i = 0; i < 6;i++)
{
cout << "Do you want to keep die " << i + 1 << "?";
cin >> input;
if (input == 'Y' || input == 'y')
{
keepList[i] = true;
}
else
{
keepList[i] = false;
}
}
}
void resetRound(bool keepList[], int& roundPoints)
{
for (int i = 0; i < 6;i++)
{
keepList[i] = false;
}
roundPoints = 0;
}
void main()
{
srand(time(NULL));
int round = 1;
int points = 0;
int roundPoints = 0;
int dice[6] = { 0 };
bool keepList[6] = { 0 };
while (round <= 10 && points < 10000)
{
bool continueRound = true;
char input;
do
{
roll(dice, keepList);
showRollResults(dice, keepList);
getDiceToKeep(keepList);
cout << "Do you want to continue this round? ";
cin >> input;
if (toupper(input) != 'Y')
{
continueRound = false;
}
} while (continueRound);
//calculate round points
round++;
points += roundPoints;
resetRound(keepList, roundPoints);
}
cout << "Game Over" << endl;
cout << "Score = " << points << endl;
cout << "Round = " << round << endl;
}