Hello I am in need of help with my java programming class project. I am able to start the project but some parts I'm having major problems with. I need some hints to solving my problems. The description is so long because I want everyone to understand exactly what the project consist of. Thank you for any assistance you can give me. The project is named the Dice Game Horses and the Description of the game is:
Introduction
So, how is a loser determined? Well each player takes his turn at the dice. The player with the highest score for the turn is the winner for that turn and is out of the game. In the event of a tie score, there is no winner, and the turn is considered void. The remaining players take another turn where a second winner is determined. That winner does not roll the dice anymore, and is therefore not the loser. Eventually there are just two people left in the game. The player who wins this last
turn is exempt from buying the drinks. The player who loses the turn is the loser and must buy the drinks.
Who wins the turn?
The player with the “winning score wins the turn. What is a “winning score? It is the roll that has the highest count of individual dice with the same pips. For example, if one player rolled where four of the dice were fives, and the other player rolled where just three of the dice were sixes, the player with the four fives would win. When, however, two players have the same count of individual dice with the same pips, the player with the higher pip count per die wins. Thus, if one player rolls four sixes and the other player rolls four fives, the player with the four sixes is the winner. How is a turn played? The game is played with five dice where, at the start of a turn the first player is allowed a maximum of three rolls. If, after the first roll, he likes his results, he may choose to stop rolling. In this case, all remaining players must attempt to beat his score
with a single roll of the dice. If, however, the player feels that he would like to keep some dice and roll others, he may do so. He keeps the dice he wants to count for his score on the second roll (clearly you will be using the SelectableDice object on this project), and then rolls the other dice. If he likes his score after the second roll, he may stop, thus requiring all other players tobeat his score in two rolls. Suppose, though, that he feels he wants to roll again. He selects the dice he wants to
keep for the third roll, and then rolls. Once he is done with this third turn, he has no more rolls. Whatever score he got is the score to beat where his opponents are allowed three turns to beat it. It is now the second player’s turn. He rolls the dice. If he beats the high score with
this first roll, he may choose to let the score stand where all other players must attempt to beat this score with just one roll. If, however, he doesn’t beat the previous high score and he is allowed another roll, he must roll again. If, on the other hand, he is allowed no further rolls, he must pass the dice to the next player. Suppose he is allowed a second roll. He can select as many dice as he wishes to keep for this second roll. If, on the second roll, he beats the best score rolled so far, he can choose to stop and require all remaining players to beat this score in two rolls. If he is allowed only two rolls and has not beaten the best score, he must pass the dice to the next opponent for him to take his turn. If the present player has beaten the best score and chooses to roll again, he may do so, keeping whatever dice he wishes for the next turn. Regardless of whether his score is a new best score or, he must pass the dice on to the next player after the third turn. The process continues where each succeeding player seeks to beat the best score
rolled so far in the number of rolls that were set by the high scorer. If the given player does not achieve that score in the rolls required, he must pass the dice to the next player for his turn. If the present player does beat the previous best score in less than the required rolls, he may choose to set this new score as the one to beat with the number of
rolls it took him to achieve the score. Or he may roll again. Regardless of whether he wins, loses or ties the best score, once he has finished with the number of allowed rolls, he must surrender the dice to the next player. How is a score determined?
Before we discuss this, let us first point out that 1s are “wild dice, that is, a die with a pip count of 1 can serve as any other die. The wild dice 1s are then counted in with whichever is the biggest occurrence count of the remaining dice. If two pip results have the same count, it is the dice with the higher pips that “get the 1s. Here are a number of
examples:[/CENTER]
5 6 3 5 1 makes a score of 3 5s
1 2 2 6 6 makes a score of 3 6s
4 3 4 3 3 makes a score of 3 3s
1 1 1 4 6 makes a score of 4 6s
6 4 4 3 2 makes a score of 2 4s
And so forth… There are more examples with the sample runs. I may post more sample
runs on Blackboard, just for the fun of it. I enjoy playing the game (idiot’s delight??)
FIRST SAMPLE RUN:
How many people are playing? 3
Enter name of player: Fast Eddie
Enter name of player: Speedo
Enter name of player: Diceman Don
Enter good-luck number: 11223344
Fast Eddie rolls the dice: __
The roll is 2 4 5 2 6
Finished (Yes, No)? No
How many dice do you want to keep? 1
Enter die numbers (1 through 5) you want to keep: 5
Here are the dice you are keeping: 6
Selection OK (Y or N)? Y
Roll the dice: __
The roll is 1 1 6 4 6
Finished (Yes, No)? Yes
Fast Eddie rolled 4 6s.
Speedo rolls the dice: __
The roll is 2 1 4 6 3
Finished (Yes, No)? No
How many dice do you want to keep? 2
Enter die numbers (1 through 5) you want to keep: 2 4
Here are the dice you are keeping: 1 6
Selection OK (Y or N)? Y
Roll the dice: __
The roll is 5 1 2 6 3
There are no more rolls left.
Speedo rolled 2 6s.
Diceman Don rolls the dice: __
The roll is 5 3 3 1 3
Finished (Yes, No)? No
How many dice do you want to keep? 4
Enter die numbers (1 through 5) you want to keep: 2 3 4 5
Here are the dice you are keeping: 3 3 1 3
Selection OK (Y or N)? Y
Roll the dice: __
The roll is 4 3 3 1 3
There are no more rolls left.
Diceman Don rolled 4 3s.
Fast Eddie won the turn with a roll of 4 6s.
===========================================================
Speedo rolls the dice: __
The roll is 3 5 4 4 1
Finished (Yes, No)? Yes
Speedo rolled 3 4s.
Diceman Don rolls the dice: __
The roll is 6 2 6 2 1
There are no more rolls left.
Diceman Don rolled 3 6s.
Diceman Don won the turn with a roll of 3 6s.
===========================================================
Speedo lost the game and has to sign for all the drinks.
SECOND SAMPLE RUN:
How many people are playing? 4
Enter name of player: Vegas Vinnie
Enter name of player: Ladyfingers
Enter name of player: Shooter
Enter name of player: The Cincinatti Kid
Enter good-luck number: 56873
Vegas Vinnie rolls the dice: __
The roll is 3 6 4 3 5
Finished (Yes, No)? No
How many dice do you want to keep? 1
Enter die numbers (1 through 5) you want to keep: 2
Here are the dice you are keeping: 6
Selection OK (Y or N)? Y
Roll the dice: __
The roll is 2 6 5 4 1
Finished (Yes, No)? No
How many dice do you want to keep? 2
Enter die numbers (1 through 5) you want to keep: 2 5
Here are the dice you are keeping: 6 1
Selection OK (Y or N)? Y
Roll the dice: __
The roll is 3 6 1 1 1
There are no more rolls left.
Vegas Vinnie rolled 4 6s.
Ladyfingers rolls the dice: __
The roll is 1 6 4 2 2
Finished (Yes, No)? No
How many dice do you want to keep? 2
Enter die numbers (1 through 5) you want to keep: 1 2
Here are the dice you are keeping: 1 6
Selection OK (Y or N)? Y
Roll the dice: __
The roll is 1 6 3 5 5
Finished (Yes, No)? No
How many dice do you want to keep? 2
Enter die numbers (1 through 5) you want to keep: 1 2
Here are the dice you are keeping: 1 6
Selection OK (Y or N)? Y
Roll the dice: __
The roll is 1 6 1 6 6
There are no more rolls left.
Ladyfingers rolled 5 6s.
Shooter rolls the dice: __
The roll is 6 4 4 1 2
Finished (Yes, No)? No
How many dice do you want to keep? 2
Enter die numbers (1 through 5) you want to keep: 1 4
Here are the dice you are keeping: 6 1
Selection OK (Y or N)? Y
Roll the dice: __
The roll is 6 3 2 1 2
Finished (Yes, No)? No
How many dice do you want to keep? 2
Enter die numbers (1 through 5) you want to keep: 1 4
Here are the dice you are keeping: 6 1
Selection OK (Y or N)? Y
Roll the dice: __
The roll is 6 3 6 1 3
There are no more rolls left.
Shooter rolled 3 6s.
The Cincinatti Kid rolls the dice: __
The roll is 1 1 5 4 5
Finished (Yes, No)? No
How many dice do you want to keep? 2
Enter die numbers (1 through 5) you want to keep: 1 2
Here are the dice you are keeping: 1 1
Selection OK (Y or N)? Y
Roll the dice: __
The roll is 1 1 6 4 1
Finished (Yes, No)? No
How many dice do you want to keep? 4
Enter die numbers (1 through 5) you want to keep: 1 2 3 5
Here are the dice you are keeping: 1 1 6 1
Selection OK (Y or N)? Y
Roll the dice: __
The roll is 1 1 6 3 1
There are no more rolls left.
The Cincinatti Kid rolled 4 6s.
Ladyfingers won the turn with a roll of 5 6s.
===========================================================
Vegas Vinnie rolls the dice: __
The roll is 3 3 6 5 6
Finished (Yes, No)? No
How many dice do you want to keep? 2
Enter die numbers (1 through 5) you want to keep: 3 5
Here are the dice you are keeping: 6 6
Selection OK (Y or N)? Y
Roll the dice: __
The roll is 6 2 6 5 6
Finished (Yes, No)? No
How many dice do you want to keep? 3
Enter die numbers (1 through 5) you want to keep: 1 3 5
Here are the dice you are keeping: 6 6 6
Selection OK (Y or N)? Y
Roll the dice: __
The roll is 6 5 6 4 6
There are no more rolls left.
Vegas Vinnie rolled 3 6s.
Shooter rolls the dice: __
The roll is 4 4 3 5 5
Finished (Yes, No)? No
How many dice do you want to keep? 0
You have chosen to roll all the dice again.
Selection OK (Y or N)? Y
Roll the dice: __
The roll is 2 5 4 2 1
Finished (Yes, No)? No
How many dice do you want to keep? 1
Enter die numbers (1 through 5) you want to keep: 5
Here are the dice you are keeping: 1
Selection OK (Y or N)? Y
Roll the dice: __
The roll is 6 1 6 3 1
There are no more rolls left.
Shooter rolled 4 6s.
The Cincinatti Kid rolls the dice: __
The roll is 1 6 6 5 4
Finished (Yes, No)? No
How many dice do you want to keep? 3
Enter die numbers (1 through 5) you want to keep: 1 2 3
Here are the dice you are keeping: 1 6 6
Selection OK (Y or N)? Y
Roll the dice: __
The roll is 1 6 6 5 3
Finished (Yes, No)? No
How many dice do you want to keep? 3
Enter die numbers (1 through 5) you want to keep: 1 2 3
Here are the dice you are keeping: 1 6 6
Selection OK (Y or N)? Y
Roll the dice: __
The roll is 1 6 6 6 4
There are no more rolls left.
The Cincinatti Kid rolled 4 6s.
That last turn was a tie. Nobody won that turn.
===========================================================
Vegas Vinnie rolls the dice: __
The roll is 5 1 2 2 2
Finished (Yes, No)? _
Vegas Vinnie rolled 4 2s.
Shooter rolls the dice: __
The roll is 5 3 1 6 2
There are no more rolls left.
Shooter rolled 2 6s.
The Cincinatti Kid rolls the dice: __
The roll is 5 5 6 6 5
There are no more rolls left.
The Cincinatti Kid rolled 3 5s.
Vegas Vinnie won the turn with a roll of 4 2s.
===========================================================
Shooter rolls the dice: __
The roll is 2 5 3 2 6
Finished (Yes, No)? No
How many dice do you want to keep? 1
Enter die numbers (1 through 5) you want to keep: 5
Here are the dice you are keeping: 6
Selection OK (Y or N)? Y
Roll the dice: __
The roll is 6 4 5 2 6
Finished (Yes, No)? No
How many dice do you want to keep? 2
Enter die numbers (1 through 5) you want to keep: 1 5
Here are the dice you are keeping: 6 6
Selection OK (Y or N)? Y
Roll the dice: __
The roll is 6 5 3 4 6
There are no more rolls left.
Shooter rolled 2 6s.
The Cincinatti Kid rolls the dice: __
The roll is 1 6 3 2 5
Finished (Yes, No)? No
How many dice do you want to keep? 2
Enter die numbers (1 through 5) you want to keep: 1 2
Here are the dice you are keeping: 1 6
Selection OK (Y or N)? Y
Roll the dice: __
The roll is 1 6 3 2 5
Finished (Yes, No)? No
How many dice do you want to keep? 2
Enter die numbers (1 through 5) you want to keep: 1 2
Here are the dice you are keeping: 1 6
Selection OK (Y or N)? Y
Roll the dice: __
The roll is 1 6 6 3 4
There are no more rolls left.
The Cincinatti Kid rolled 3 6s.
The Cincinatti Kid won the turn with a roll of 3 6s.
===========================================================
Shooter lost the game and has to sign for all the drinks.
THIRD SAMPLE RUN:
How many people are playing? 2
Enter name of player: The Iceman
Enter name of player: The Dice Charmer
Enter good-luck number: 987654
The Iceman rolls the dice: __
The roll is 2 3 4 6 5
Finished (Yes, No)? No
How many dice do you want to keep? 1
Enter die numbers (1 through 5) you want to keep: 4
Here are the dice you are keeping: 6
Selection OK (Y or N)? Y
Roll the dice: __
The roll is 3 5 6 6 5
Finished (Yes, No)? No
How many dice do you want to keep? 2
Enter die numbers (1 through 5) you want to keep: 3 4
Here are the dice you are keeping: 6 6
Selection OK (Y or N)? Y
Roll the dice: __
The roll is 5 2 6 6 6
There are no more rolls left.
The Iceman rolled 3 6s.
The Dice Charmer rolls the dice: __
The roll is 2 5 1 6 2
Finished (Yes, No)? No
How many dice do you want to keep? 1 3 5
Enter die numbers (1 through 5) you want to keep: 2
Here are the dice you are keeping: 5
Selection OK (Y or N)? N
How many dice do you want to keep? 3
Enter die numbers (1 through 5) you want to keep: 1 3 5
Here are the dice you are keeping: 2 1 2
Selection OK (Y or N)? Y
Roll the dice: __
The roll is 2 2 1 3 2
Finished (Yes, No)? Yes
The Dice Charmer rolled 4 2s.
The Dice Charmer won with a roll of 4 2s.
===========================================================
The Iceman lost the game and has to sign for all the drinks.
Note: bad selection[/LEFT]
The Project
Clearly you can see from the handout sheets of the Game of Horses that you are required to code an application that simulates the game of horses. You will be doing this work in two parts. The horses game itself requires three objects: SelectableDice, IntegerPair, and HorsesPlayer.
You are required in the first part of the project to build and debug an object of type HorsesPlayer. This work is due on 12 April. Even though I will be giving you feedback, you should try to get this part done as near to perfection as possible, because the second part of the project, the actual play of the game will be handed out. This part will be due on 26 April. The HorsesPlayer object: semantics on the instance variables/objects As you can see, this object has for instance variables/objects:
• playersName, clearly the name of the player
• stillInGame, true when the player is still rolling the dice and a contender for the game’s loser
• presentScore, an IntegerPair object where first with take on the value of the count of the number of dice with the same pips and second takes on the value of the pips for these dice (e.g. 3 2s ↔ first is 3, and second is 2; 4 6s ↔ first is 4 and second is 6)
• OFFSET, a final value used to give proper semantics to the index value of the counter array. The need for this value was determined when we coded the scoreIt method. The constructors These are very straightforward. Both constructors initialize stillInGame to true and set the values of first and second (use calls to setFirst and setSecond methods of the IntegerPair class!) to 0. The default constructor sets playersName to a null string, and the other constructor sets playersName to the value of name.
The accessors Their names (getName, stillInGame, getCount and getPips) reflect their purpose. They are the usual one-liner sort of accessors. The modifiers The removeFromGame modifier clearly sets stillInGame to false. This method is called when a given player has been determined as having the best roll. The method scoreIt uses the
values of the five dice in dice) to set values to the presentScore integer pair. How to do it? Use recyclable strategies! An array of counters will determine how many of each die occurred. Then you us a significant event recorder to determine which element represents the pips that have the highest count and value. The code that carries out these strategies is found in the helper methods
of scoreIt. To use or ignore. It worked fine for me!
The predicates The two methods hasBetterScore and hasSameScore compare the presentScore values of the calling object (this) with the other object. Straightforward application of the rules of horses
will lead you to the proper expressions to code in these methods.
Testing the methods I will leave the details of testing the methods up to each team. A simple word to the wise, though: You can instantiate a HorsesPlayer object and then use the code of TestSelectableDice
to generate some dice. Pass the dice into the scoreIt method, then use getCount and getPips to see what score the given roll gives the player. You can loop through this code, testing your logic as often as you want with the seeking loop instantiate a HorsePlayer object and a Dice or a SelectableDice object for data generation
do
{
generate data
test it
promptRead finished
} while (!finished)
Once you know that scoreIt works, you can instantiate a second player, simulate rolls, and
compare results
Machine Project 2, Part II
The project
The rest of the project, code that actually simulates the game of horses, is due on 26 April. You are familiar with the rules of the game from the first hand out. Now, you have seen three sample games that were played. It is your job to write the rest of the project where games are
simulated and run. You are therefore to write the code that simulates a game of horses, and then you are to test the code with the same sample data that I used for my three runs. The main method
main requires just two objects and one variable to get the job done. The two objects (actually an array of objects and another object) are an array of HoresePlayer objects referenced by player, a SelectableDice object whose reference is dice, and an int variable playersInGame
that holds the count of the number of players still left in the game.
Before the game starts, clearly the array referenced by player must be filled with elements. Do so with a call to the getPlayers method, one whose return result is a reference to the array of players that will make up the game. After the number of elements have been determined (number of players in the game), you can use the length of the array to determine the value for playersInGame. Here is the loop that main uses to play the game:
do
{
int winnerIndex = playOneRound(player, dice)
if winnerIndex < player.length) // return player.length in case of tie
{
processWinner(player[winnerIndex]);
playersInGame--;
}
else
display tie message
display some kind of game separator // I used =====================
} while(playersInGame > 1);
showLoser(player);
The code for processWinner is very straightforward with a display of the winner’s name and score. The removeFromGame method is called to remove the player from the game. showLoser is equally straightforward. The index of the player who is still in the game is found, and that player’s name is displayed. The method playOneRound The code for the method playOneRound requires some thought. You need to use a for loop
to get the index of the player with the highest score, where the update for the index is made after each player (who is still in the game) rolls the dice. Before the loop is started, a bogus HorsesPlayer object, winnerSoFar, is constructed (where the default object is constructed with
a null score). The maximum turns allowed at the start is 3 (use a variable maximumTurns), and the winningIndex that gets returned is initialized to player.length. Here’s the pseudocode for the for loop:
for (int i = 0; i < player.length; i++
if (player.isStillInGame( ))
{
set return result of method rollem to turnsTaken use dice to score player showScore(player)
if (player has a better score than winnerSoFar)
{
change reference to winnerSoFar, value of winningIndex, and value of maxTurns
}
else if (player has same score as winnerSoFar)
set winningIndex to player.length // tie result
}
The return result when this loop is exited is the value of winningIndex.
The method rollem The code for rollem’s header is as follows:
private static int rollem(String name, SelectableDice dice, int maxTurns)
You need to figure out what arguments get passed into this method. Yes, there is a lot of code involved in this method, but much of it is recyclable.
I didn’t cover the code for the class DriveSelectableDice for a reason: I am leaving it up to you to figure it out and modify it. Most of it can be copied verbatim to arrive at the code for the method rollem. It is your job to figure out what must be change.