Dice Game

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   hear noise   go to next page

Answer:

Yes.

Dice Game

Here are the rules to a dice game:

  1. The game consists of several "rounds."
  2. In each round, the computer plays first by throwing two six-sided dice and adding the spots.
  3. The player must now try to beat that sum.
  4. The player may choose to throw two six-sided dice or one 11-sided die (with sides numbered 2-12).
  5. If the player's throw beats the computer, then the player wins the round. Otherwise the computer wins the round.
  6. The game continues until either the player or the computer has won ten rounds.

Here are the first four rounds of a game:

The Computer tosses: 10
Toss 1 eleven-sided die, or 2 six-sided dice (enter 1 or 2)? 1
You throw 1 die and get: 7
You loose the round!
Score: computer 1, you 0

The Computer tosses: 4
Toss 1 eleven-sided die, or 2 six-sided dice (enter 1 or 2)? 2
You throw 2 dice and get: 9
You win the round!
Score: computer 1, you 1

The Computer tosses: 10
Toss 1 eleven-sided die, or 2 six-sided dice (enter 1 or 2)? 1
You throw 1 die and get: 3
You loose the round!
Score: computer 2, you 1

The Computer tosses: 5
Toss 1 eleven-sided die, or 2 six-sided dice (enter 1 or 2)? 2
You throw 2 dice and get: 5
You loose the round!
Score: computer 3, you 1

Eleven-sided dice are hard to find in the real world. If you wanted to play this game with physical dice, use a twelve-sided or sixteen-sided die (which do exist, ask any Dungeon Master) and discard rolls other than 2 through 12.

QUESTION 17:

What advantage does the computer have in this game?

What advantage does the player have in this game?