# APCS: AP Computer Science A @sfhs

### Sidebar

greed_game

This is an old revision of the document!

Greed Game The Greed Game is something I was told was invented by Rex Bogs. It is a fun party game that is based on “pressing your luck” on five rounds of throwing a die. The points accumulate until the number 2 is cast. Before the die is cast, players have an option of banking the total. If they think the next roll is not a 2, they keep standing. But if it is a 2, they get zero points for that round.

Overview:

• 5 rounds
• your score is the sum of scores from the five rounds
• highest score wins

A “round”:

• Everyone stands
• a six-sided die is rolled twice, and if a 2 was not rolled, the sum is everybody’s current score for this round.
• If you are happy with this score, sit down writing the number on your score card
• If you want more, keep standing, and the die is rolled again

What's next:

• If a 2 was not rolled, add the number to your score card
• If you like the score sit down and write it to your score card
• If you want more, remain standing

What if it is a 2?

If you are sitting down, this is merely the end of the round If you are standing, you must score a zero for this round.

Here are two BlueJ project zipped up with some code:

Greed Game Sim

Since the chances of rolling a 2 is 1/6, then why not modify the game that so two die are cast, and the “loosing” roll would be doubles. Rolling doubles occurs 6/36 times, the same probability as rolling a single die and casting a 2. Of course, for a game, the fun is based on the variety of outcomes, not the average outcome.

It takes a while to play a game, so why not have the computer simulate the game many many times? We can then compare the original game to the modified game and see if the variation is about the same, or if one games seems different.

The code above can be changed to be verbose, and with any number of players (see the first two lines of the `main` method.

Greed Game Contest

You can now design and test Game strategies with this one. You can design subclasses of player that will sit down based on a strategy. A timid player would always sit down right away, while a greedy player will press his or her luck.