Homework 1: Mastermind Intro
The goal of this homework assignment is to create the basic infrastructure for the game Mastermind (a code guessing game between two human players). Player 1 provides a secret code and Player 2 tries to guess what it is using feedback she received from previous guesses.
Player 1 first enters the secret code by entering a response to an “ask” block. A secret code is 4 letters long (no spaces), where each letter is one of ROYGBV (the first letters of the standard colors of the game: Red, Orange, Yellow, Green, Blue, Violet). You are allowed to have repeated letters in your code. Example possible secret codes: RRBG, OYOO, BROY, VVVV, etc. The word is immediately hidden from view after Player 1 finishes entering it. The computer then starts by telling Player 2 to try to guess the code. After Player 2 makes a guess, the computer should tell the player whether their guess was right or wrong (guesses should be case-insensitive). If Player 2 was wrong, the computer should also tell Player 2 in what places the letters matched the solution (if any). The conversation alternates back and forth until Player 2 guesses the code correctly and the number of guesses it took to reach the correct answer is displayed. Assume the user always types a four-letter code made up of these letters: ROYGBV. That is, we don’t ask that you do any error checking.
Here is an example of the game [the words in square brackets are our commentary]:
Computer: Welcome, BJC encoder. What is the secret code?
Player 1: RRBG
Computer: Welcome, BJC decoder. Try to guess the code!
Player 2: VBOG
Computer: No, but you have the following slot(s) correct: 4
[G is in the correct position]
Player 2: OYRO
Computer: No, and none of the slots are correct.
Player 2: RRVG
Computer: No, but you have the following slot(s) correct: 1 2 4
[R, R and G are in the correct position, all the correct slots are given at once]
Player 2: RRBG
Computer: Yes, that is correct! You figured it out in 4 guesses.
[…and the game ends]
Your game should have at least one sprite, but there are no graphical requirements other than that. Feel free to develop the graphics more if you’d like!
Starting Materials and Requirements
You should start from a blank Snap! project. You are required to make the following helper reporter block. Solutions that do not build and use this block will be penalized. Also, please note that this reporter has inputs. You should be giving your block inputs as demonstrated.
- Calculate the slots of the guess and the secret key that match. All of the correct slots should be returned at once. This is done by authoring the following reporter block: