talha23
03-02-2007, 02:00 PM
Description
Your entire project submission is due on Friday, March 2, 2007. You will submit a single document electronically, your java solution, called P3.java. Include your name, section number, group number, and group partner's name in a comment at the top of the program. You also need to describe the program you are implementing at the top of the page and comment within the program as you add new parts that are significant to the program. At the start of your program, print your name, section number, group number, and group partner's name to the screen.
In some of our projects this semester, we will incorporate and update functionality to the game Mastermind. In the game, there are two players: the code-maker and the code-breaker. For right now, the user will always be the code-breaker and the computer will be the code-maker. The code-maker creates a four-color code sequence using six potential colors. For our application the six colors will be Black, Blue, Green, Red, White, & Yellow. These colors will be represented by the characters 'K'/'k', 'B'/'b', 'G'/'g', 'R'/'r', 'W'/'w', & 'Y'/'y' respectively. For this project, we will use the code: R K K R every time the user plays the game.
Once the code has been established, the code-breaker (you) is allowed 10 guesses to break the code. After each guess, the code-maker is required to give code-breaker hints. First, the code-maker must inform the code-breaker if they have successfully identified a color in the sequence and placed it appropriately. Second, the code-maker must inform the code-breaker if they've successfully identified a color in the sequence even if it's not placed appropriately. The first situation is referred to as an exact match. The second situation is referred to as an other match. We will indicate an exact match by using the hint 'E' and an other match by using the hint 'O'. Note that the code-maker is not required to identify which color in the sequence is the exact match or the other match. If the code-breaker successfully guesses the code in 10 guesses or less they win, otherwise the code-maker wins.
In Project 3, you will create the basic game interaction and control in the text based environment. You will use three character arrays in your solution: hints, pegs, and solution, storing the hint response given to the user, the current peg guesses, and the solution. Use a for loop to control printing the hints, pegs, and ultimately the solution lists. Also use for loop to control comparing and determining whether or not peg guesses match the solution, in order to update your hints. Use a while loop to identify if the user has entered bad (un-usable) data. Allow the user to enter upper and lower case values for each possible entry. In your displays, always use upper case for consistency. Use a loop to control the overall flow of the program and the repetition of guesses within the program. You will need to continue to receive four peg guesses, compare against the solution, and display results until the user has guessed ten times or until the solution has been found.
Outline of Steps
This is an outline of the steps you should use to solve this problem. Note these are steps you will need to identify on your own in future program solutions.
Declare and initialize variables
Print your course information
Welcome the user to the program
Use a loop to control program flow
Ask the user to enter four peg guesses
Identify bad input and re-ask
Test if the solution has been found
Update the display showing: a congratulations for winning, try again if the game has been lost, and display the hints if the game is continuing.
Part A
Recommended Completion Data: February 23, 2007.
Create the class P3, create printed messages, declare and initialize variables, including arrays.
Part B
Recommended Completion Data: February 26, 2007.
Ask the user to enter guesses, determine whether guess entries are valid, re-ask as appropriate (accepting upper and lower case values for each of the entries). After four peg guesses have been received, determine whethor the user has won (make this comparison by using a for loop to examine each position) or if the user has lost. If the user has won, print a congratulations message and the number of turns it took for the user to win. If the user has lost, print a try again message and end the program.
Part C
Recommended Completion Data: March 2, 2007.
Create (or add to your existing comparisons) a nested for loop which will compare every peg guess to every portion of the solution (not simply to corresponding locations) so that you can update the hints with the appropriate feedback to the user as the game continues.
Sample Output #1
Name: Pete Dobbins
Section: 1234
Group: 1
Partner: No Partner
Enter a color for Peg 1: G
Enter a color for Peg 2: X
I do not recognize the color: X
Enter a color for Peg 2: O
I do not recognize the color: O
Enter a color for Peg 2: Y
Enter a color for Peg 3: K
Enter a color for Peg 4: L
I do not recognize the color: L
Enter a color for Peg 4: P
I do not recognize the color: P
Enter a color for Peg 4: B
Guess 1: G Y K B
Hints: E _ _ _
Enter a color for Peg 1: W
Enter a color for Peg 2: R
Enter a color for Peg 3: K
Enter a color for Peg 4: R
Guess 2: W R K R
Hints: O E E _
Enter a color for Peg 1: R
Enter a color for Peg 2: K
Enter a color for Peg 3: K
Enter a color for Peg 4: R
Guess 3: R K K R
Hints: E E E E
Solution: R K K R
Congratulations! You broke the code in 3 guesses.
Sample Output #2
Name: Pete Dobbins
Section: 1234
Group: 1
Partner: No Partner
Enter a color for Peg 1: r
Enter a color for Peg 2: K
Enter a color for Peg 3: k
Enter a color for Peg 4: R
Guess 1: R K K R
Hints: E E E E
Solution: R K K R
Congratulations! You broke the code in 1 guess.
Sample Output #3
Name: Pete Dobbins
Section: 1234
Group: 1
Partner: No Partner
Enter a color for Peg 1: r
Enter a color for Peg 2: r
Enter a color for Peg 3: w
Enter a color for Peg 4: r
Guess 1: R R W R
Hints: E E _ _
Enter a color for Peg 1: r
Enter a color for Peg 2: R
Enter a color for Peg 3: R
Enter a color for Peg 4: r
Guess 2: R R R R
Hints: E E _ _
Enter a color for Peg 1: k
Enter a color for Peg 2: R
Enter a color for Peg 3: w
Enter a color for Peg 4: g
Guess 3: K R W G
Hints: O O _ _
Enter a color for Peg 1: w
Enter a color for Peg 2: g
Enter a color for Peg 3: r
Enter a color for Peg 4: k
Guess 4: W G R K
Hints: O O _ _
Enter a color for Peg 1: r
Enter a color for Peg 2: g
Enter a color for Peg 3: b
Enter a color for Peg 4: k
Guess 5: R G B K
Hints: E O _ _
Enter a color for Peg 1: r
Enter a color for Peg 2: y
Enter a color for Peg 3: w
Enter a color for Peg 4: b
Guess 6: R Y W B
Hints: E _ _ _
Enter a color for Peg 1: b
Enter a color for Peg 2: b
Enter a color for Peg 3: g
Enter a color for Peg 4: w
Guess 7: B B G W
Hints: _ _ _ _
Enter a color for Peg 1: g
Enter a color for Peg 2: k
Enter a color for Peg 3: w
Enter a color for Peg 4: b
Guess 8: G K W B
Hints: E _ _ _
Enter a color for Peg 1: r
Enter a color for Peg 2: w
Enter a color for Peg 3: w
Enter a color for Peg 4: k
Guess 9: R W W K
Hints: E O _ _
Enter a color for Peg 1: k
Enter a color for Peg 2: r
Enter a color for Peg 3: r
Enter a color for Peg 4: k
Guess 10: K R R K
Hints: O O O O
Solution: R K K R
You have lost. Please try again
Your entire project submission is due on Friday, March 2, 2007. You will submit a single document electronically, your java solution, called P3.java. Include your name, section number, group number, and group partner's name in a comment at the top of the program. You also need to describe the program you are implementing at the top of the page and comment within the program as you add new parts that are significant to the program. At the start of your program, print your name, section number, group number, and group partner's name to the screen.
In some of our projects this semester, we will incorporate and update functionality to the game Mastermind. In the game, there are two players: the code-maker and the code-breaker. For right now, the user will always be the code-breaker and the computer will be the code-maker. The code-maker creates a four-color code sequence using six potential colors. For our application the six colors will be Black, Blue, Green, Red, White, & Yellow. These colors will be represented by the characters 'K'/'k', 'B'/'b', 'G'/'g', 'R'/'r', 'W'/'w', & 'Y'/'y' respectively. For this project, we will use the code: R K K R every time the user plays the game.
Once the code has been established, the code-breaker (you) is allowed 10 guesses to break the code. After each guess, the code-maker is required to give code-breaker hints. First, the code-maker must inform the code-breaker if they have successfully identified a color in the sequence and placed it appropriately. Second, the code-maker must inform the code-breaker if they've successfully identified a color in the sequence even if it's not placed appropriately. The first situation is referred to as an exact match. The second situation is referred to as an other match. We will indicate an exact match by using the hint 'E' and an other match by using the hint 'O'. Note that the code-maker is not required to identify which color in the sequence is the exact match or the other match. If the code-breaker successfully guesses the code in 10 guesses or less they win, otherwise the code-maker wins.
In Project 3, you will create the basic game interaction and control in the text based environment. You will use three character arrays in your solution: hints, pegs, and solution, storing the hint response given to the user, the current peg guesses, and the solution. Use a for loop to control printing the hints, pegs, and ultimately the solution lists. Also use for loop to control comparing and determining whether or not peg guesses match the solution, in order to update your hints. Use a while loop to identify if the user has entered bad (un-usable) data. Allow the user to enter upper and lower case values for each possible entry. In your displays, always use upper case for consistency. Use a loop to control the overall flow of the program and the repetition of guesses within the program. You will need to continue to receive four peg guesses, compare against the solution, and display results until the user has guessed ten times or until the solution has been found.
Outline of Steps
This is an outline of the steps you should use to solve this problem. Note these are steps you will need to identify on your own in future program solutions.
Declare and initialize variables
Print your course information
Welcome the user to the program
Use a loop to control program flow
Ask the user to enter four peg guesses
Identify bad input and re-ask
Test if the solution has been found
Update the display showing: a congratulations for winning, try again if the game has been lost, and display the hints if the game is continuing.
Part A
Recommended Completion Data: February 23, 2007.
Create the class P3, create printed messages, declare and initialize variables, including arrays.
Part B
Recommended Completion Data: February 26, 2007.
Ask the user to enter guesses, determine whether guess entries are valid, re-ask as appropriate (accepting upper and lower case values for each of the entries). After four peg guesses have been received, determine whethor the user has won (make this comparison by using a for loop to examine each position) or if the user has lost. If the user has won, print a congratulations message and the number of turns it took for the user to win. If the user has lost, print a try again message and end the program.
Part C
Recommended Completion Data: March 2, 2007.
Create (or add to your existing comparisons) a nested for loop which will compare every peg guess to every portion of the solution (not simply to corresponding locations) so that you can update the hints with the appropriate feedback to the user as the game continues.
Sample Output #1
Name: Pete Dobbins
Section: 1234
Group: 1
Partner: No Partner
Enter a color for Peg 1: G
Enter a color for Peg 2: X
I do not recognize the color: X
Enter a color for Peg 2: O
I do not recognize the color: O
Enter a color for Peg 2: Y
Enter a color for Peg 3: K
Enter a color for Peg 4: L
I do not recognize the color: L
Enter a color for Peg 4: P
I do not recognize the color: P
Enter a color for Peg 4: B
Guess 1: G Y K B
Hints: E _ _ _
Enter a color for Peg 1: W
Enter a color for Peg 2: R
Enter a color for Peg 3: K
Enter a color for Peg 4: R
Guess 2: W R K R
Hints: O E E _
Enter a color for Peg 1: R
Enter a color for Peg 2: K
Enter a color for Peg 3: K
Enter a color for Peg 4: R
Guess 3: R K K R
Hints: E E E E
Solution: R K K R
Congratulations! You broke the code in 3 guesses.
Sample Output #2
Name: Pete Dobbins
Section: 1234
Group: 1
Partner: No Partner
Enter a color for Peg 1: r
Enter a color for Peg 2: K
Enter a color for Peg 3: k
Enter a color for Peg 4: R
Guess 1: R K K R
Hints: E E E E
Solution: R K K R
Congratulations! You broke the code in 1 guess.
Sample Output #3
Name: Pete Dobbins
Section: 1234
Group: 1
Partner: No Partner
Enter a color for Peg 1: r
Enter a color for Peg 2: r
Enter a color for Peg 3: w
Enter a color for Peg 4: r
Guess 1: R R W R
Hints: E E _ _
Enter a color for Peg 1: r
Enter a color for Peg 2: R
Enter a color for Peg 3: R
Enter a color for Peg 4: r
Guess 2: R R R R
Hints: E E _ _
Enter a color for Peg 1: k
Enter a color for Peg 2: R
Enter a color for Peg 3: w
Enter a color for Peg 4: g
Guess 3: K R W G
Hints: O O _ _
Enter a color for Peg 1: w
Enter a color for Peg 2: g
Enter a color for Peg 3: r
Enter a color for Peg 4: k
Guess 4: W G R K
Hints: O O _ _
Enter a color for Peg 1: r
Enter a color for Peg 2: g
Enter a color for Peg 3: b
Enter a color for Peg 4: k
Guess 5: R G B K
Hints: E O _ _
Enter a color for Peg 1: r
Enter a color for Peg 2: y
Enter a color for Peg 3: w
Enter a color for Peg 4: b
Guess 6: R Y W B
Hints: E _ _ _
Enter a color for Peg 1: b
Enter a color for Peg 2: b
Enter a color for Peg 3: g
Enter a color for Peg 4: w
Guess 7: B B G W
Hints: _ _ _ _
Enter a color for Peg 1: g
Enter a color for Peg 2: k
Enter a color for Peg 3: w
Enter a color for Peg 4: b
Guess 8: G K W B
Hints: E _ _ _
Enter a color for Peg 1: r
Enter a color for Peg 2: w
Enter a color for Peg 3: w
Enter a color for Peg 4: k
Guess 9: R W W K
Hints: E O _ _
Enter a color for Peg 1: k
Enter a color for Peg 2: r
Enter a color for Peg 3: r
Enter a color for Peg 4: k
Guess 10: K R R K
Hints: O O O O
Solution: R K K R
You have lost. Please try again