Skip to content

Instantly share code, notes, and snippets.

@CasonBarnhill
Last active October 22, 2015 21:46
Show Gist options
  • Save CasonBarnhill/312bf58767fe33731f35 to your computer and use it in GitHub Desktop.
Save CasonBarnhill/312bf58767fe33731f35 to your computer and use it in GitHub Desktop.
Create a 'Pig Dice' game for the console
Gameplay
Each turn, a player repeatedly rolls a die until either a 1 is rolled or the player decides to "hold":
If the player rolls a 1, they score nothing and it becomes the next player's turn. If the player rolls any other number, it is added to their turn total and the player's turn continues. If a player chooses to "hold", their turn total is added to their score, and it becomes the next player's turn. The first player to score 100 or more points wins.
For example, the first player, Ann, begins a turn with a roll of 5. Ann could hold and score 5 points, but chooses to roll again. Ann rolls a 2, and could hold with a turn total of 7 points, but chooses to roll again. Ann rolls a 1, and must end her turn without scoring. The next player, Bob, rolls the sequence 4-5-3-5-5, after which he chooses to hold, and adds his turn total of 22 points to his score.
Normal
Submit your game design notes with the gist. Submit a working game with only one player. I.e. one player rolls unitl he hits 100 or more. Use Functions as necessary.
Hard
Mutiple Players can play also construct classes with properties and methods representing the game (i.e. dice, player, etc class).
Nightmare
Construct an AI that plays based on 'optimal play' as defined here: Pig Dice Game Wiki
{
//create intro and make variables to plug in
Console.WriteLine("Let's Get Started With Pig Dice!!");
Console.WriteLine("Type roll to start game");
Console.ReadLine();
int hand = 0;
int bank = 0;
Random r = new Random();
//create while loop
while (true)
{
while (true)
{
//role dice
var roll = r.Next(1, 7);
//print roll
Console.WriteLine(roll);
//check if bust
if (roll == 1)
{
hand = 0;
break;
}
//otherwise update hand total
hand = hand + roll;
Console.WriteLine($"Hand: {hand}, Bank {bank}");
//ask bank or roll
Console.WriteLine("Do you wish to roll or bank?");
string response = Console.ReadLine();
//if roll
if (response == "roll")
{
continue;
}
//if bank
if (response == "bank")
{
bank = bank + hand;
continue;
}
{
}
}
Console.WriteLine($"WINNER {bank}");
Console.ReadLine();
//add safety net for when user responds wrong (not "bank" or "roll")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment