Project description

This project will require students to simulate the board game Mastermind. Students will have to work through a series of programming implementations in order to complete the project. The project will include the use of primitive data type variables, arrays, user defined functions, and functions from the C library.

Mastermind

Test your code-cracking prowess with Mastermind, the challenging game of logic and deduction. Can you crack the code in 10 moves or less? Can you create a code than can't be cracked? It's easy to learn and fast to play, and with more than 2,000 possible codes its different every time.

The Codemaker sets a secret code, then the Codebreaker tries to match the code using logic, deduction, and maybe even a little bit of luck. After each move, the Codemaker gives clues to the Codebreaker.

Assignment Naming Convention

It is highly recommended that for each iteration of the project students copy the previous assignment and rename it for additional functionality. The purpose of this implementation is two-fold. First, if there is a grading discrepancy, students have evidence of functioning source code worked as designed respective to what the grading rubric required. Second, the current implementation of Webcourses automatically renames a student's assignment submission. The first submission would be "mastermind.c", the second submission automatically gets renamed to mastermind-1.c, the third submission automatically gets renamed to mastermind-2.c, etc and causes concern for students.

Assignment Scope

  • Update a C source code file
  • Create and use a constant
  • Modify functions
  • Use decision making logic (i.e. if, if/else, if/elseif/else, switch)
  • Use looping constructs (e.g. while, do/while, for)
  • Compile and run a file

Tasks

mastermind.c

1. Copy C source code file mastermind4.c as mastermind5.c

2. Update C source code file mastermind5.c

3. Define the following global constant(s)

3.a NINE as value 9

3.b. ZERO as value 0

3.c. INVALID as value -1

4. Modify the function declaration or prototype for function displayBoard based on the updated function signature

5. Update the main function to do the following

5.a. Comment out or remove the call to function displayBoard that is before function call populateColorArray

5.b. After the call to function initializeArray(guesses), call function initializeArray again, passing array clues as an argument

5.c. Call function displayBoard; update the arguments passed to include array guesses and clues

5.d. Write a loop to iterate 10 times (i.e. TEN) for each turn of the game

5.d.a. Nest the call to function getGuess inside the loop; maintain the arguments passed to include array guesses and colors

5.d.b. Nest the call to function displayBoard inside the loop; update the arguments passed to include array guesses and clues

5.e. Comment out or remove the previous loop that displayed the updated array guesses in Assignment 4

6. Update function displayBoard to do the following

6.a. Return type void

6.b. Parameter list includes

6.b.a. Array guesses[TEN][FOUR]

6.b.b. Array clues[TEN][FOUR]

6.c.Maintain the first seven printf statements so the following lines are still hardcoded.

6.c.a. SECRET CODE

6.c.b. ? ? ? ?

6.c.c PLAYER GUESS | CLUES

6.d d. Modify the remaining printf hardcoded lines to do the following

6.d.a. Loop for the 10 turns of the game; the LAST guess should be at the top; the FIRST guess should be at the bottom

6.d.a.i. Loop through the guesses array, for each element

6.d.a.i.1. If the value stored in the array is invalid (i.e. equals -1; INVALID), display a '?'

6.d.a.i.2. If the value stored in the array is valid (i.e. does not equal -1; INVALID), display the character stored in the array

6.d.a.ii. Loop through the clues array, for each element

6.d.a.ii.1. If the value stored in the array is invalid (i.e. equals -1; INVALID), display a '?'

6.d.a.ii.2. If the value stored in the array is valid (i.e. does not equal -1; INVALID), display the character stored in the array

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.