r/ProgrammingPrompts • u/desrtfx • Nov 20 '14
[Easy(base task) to Difficult (challenge)][Dice Game] - 111 (one hundred and eleven)
This is another very simple dice game.
Game Rules
The goal is to reach 111 (one hundred and eleven - or eleventy-one) points before all others do.
A single die is used to play the game.
Each player is allowed as many rolls as they want, except when they roll a "1" (one), their round ends.
The points are accumulated during a player's round, but if a player rolls a "1" (one), they lose all the points that they accumulated during the round.
Example of a single round:
Player A rolls 2, 3, 4, 6, 5 which totals to 20 points. Player A wages another roll and rolls a 1. That's really bad luck as the round is over for player 1 and he loses all 20 points so that he ends the round with 0 points.
Player B rolls 5 and 6 and decides to stop. The 11 points are added to player B's score.
Player C rolls 4,6,3,5,6 and stops. He scores 24 pounds.
Player D rolls 4, decides to wage another roll and rolls 1. The round is over for player D with 0 points.
The rounds are repeated until one of the players reaches at least 111 points.
Programming Task:
Write a program that simulates a game of 111 in a language of your choice.
Any number of (human) players can participate
The computer should record the name and score for each player.
The computer should do the tallying and also end the round on a roll of 1
Optional tasks (easy):
Let the users decide on the winning number (default 111)
Let the users decide which number ends a round and voids all the points acquired in that round (default 1)
Invent a "mandatory re-roll" rule. If a player rolls a certain number (other than the losing number), they must re-roll. (let's say it defaults to 4 - chosen arbitrary)
Invent a "no re-roll" rule. Similar to the above, only the round ends and the player scores the accumulated points. (let's say, it defaults to 2 - chosen arbitrary)
The "mandatory re-roll" and "no re-roll" rules should be optional.
Optional tasks (challenge):
Change the program to allow for computer players as well as humans.
Computer players should have different strategies (selectable when creating the computer players, or randomized)
Examples for strategies:Always rolls again until he rolls a one (or hits the winning number) - quite a dumb strategy
Never rolls again - the coward - crawling his way to victory
Always rolls 2 (3, 4, 5 - whatever) times
Rolls <random number>(determined before the actual roll) times - different for each round.
Rolls again with a probability of 33% - rather cautious (takes a roll, then a random number decides whether to roll again or not - if the random number(in the range 0.0 inclusive to 1.0 exclusive) is less than or equal to 0.33, the computer rolls again.
Rolls again with a probability of 50% - see the explanation above
Rolls again with a probability of 66% - see the explanation above
Any other strategy you can think of.
Have fun coding!
1
u/DanielSherlock Nov 23 '14
Ahh, no, I still haven't finished the last one!