Arrays: Using arrays to help with our mastermind game

28 Feb 2023 - 14:58 | Version 1 |
At the end of this lab, you will almost be done with the mastermind game. You will have almost every tool necessary to get the game running. You will finish the actual game in the next lab

Learning Objective(s)

  1. Learn to use single dimensional integer arrays
  2. Reinforce skills associated with methods

Overview of the Program

Generate two different sets of colors and report how alike they are are.

Details

  1. Use integer arrays to store the colors for the solution and the guess
  2. Generate both using random numbers
  3. Use constants to define how many different colors are allowed and how many colors are in the solution
  4. There is no input for this lab.
  5. You should develop the methods in the order that seems best to you.
  6. Write one method that will receive a size and return an integer array of that size filled with random numbers 0 through the largest number representing a color.
  7. Write a second method that will receive an integer array of a guess or solution and return a second array that counts the number of each colors. For example:
    1. If there are allowed four colors (red, blue, green, white) and six colors in the solution
    2. And the solution array was 1 1 3 3 2 3
    3. This method would return 0 2 1 3 (because there are 0 red, 2 blues, 1 green, and 3 whites)
  8. Write a third method that is sent two integer arrays (i.e. the guess and solution) and returns the number of elements that are the same place. For example
    1. If the guess was 1 2 1 3 and the solution was 1 0 0 1
    2. It would return 1 because the first pair are identical
  9. Write a fourth method that is sent two integer arrays (with the counts of each color) and returns the sums of the min of each. Example will be give in class.
  10. Write a fifth method that will display an array on a single line.
  11. The main method should first be written to generate two arrays of colors (solution and guess), then print each array out and the number identical and the number of colors right but not in the right place.
  12. Only after that is working, place that code inside a loop that executes 10000 times and determine the average number that are guessed perfectly and colors being correct.
  13. Program should be called Mastermind

Example program dialogue:

These are not meant to be sufficient testing. Nor must you follow the exact wording. They are just to demonstrate what an acceptable program might do for certain input. This is for the intermediate main program (not the analysis). This code allows for 5 different colors and 6 colors in a guess/solution
2 0 3 1 3 3 
0 1 1 0 4 1 
0 are perfect
There are 2 other colors properly identified.

Submission

  1. create an empty zip folder
  2. place your java file into it
  3. in Lessons Learned be sure to discuss your statistics generated by the code.
  4. create a pdf document that contains your Software Development Report for this program and place the pdf file into the zip folder
  5. submit the zip folder on canvas

Hints

  1. Each method is not very complex. You are to work these out on your own. Ask for help if you need it.
  2. How to determine the number of good colors

Optional improvements

Optional improvements should ONLY be worked on once the program is completing working. In addition, the work is to be done on your own with little if any help for lab assistants or the instructor. You must score at least 90% on the rest of the program to earn any additional points
  1. Use letters instead of integers for the colors
  2. Get the size of the guess/solution and number of colors from the command line. You will need to research this yourself. (Hint: it is part of the line declaring main. But you also need to know who to give the command line arguments)
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback
This website is using cookies. More info. That's Fine