Mastermind Mastermind is a code-breaking game (https://en.wikipedia.org/wiki/Mastermind_(board_game)). The goal of the game is to discover a hidden code that consists of 4 colours. The board game is...

Copy and Paste Your Assignment Here


Mastermind Mastermind is a code-breaking game (https://en.wikipedia.org/wiki/Mastermind_(board_game)). The goal of the game is to discover a hidden code that consists of 4 colours. The board game is played using: 1. a decoding board, with a shield at one end covering a row of four large holes, and a set of rows containing four large holes next to a set of four small holes. 1. code marbles of six different colours (Red, Green, Blue, Yellow, White, Black) are used to represent a code and placed in the large holes on the board; and 1. key pegs, some coloured black, some white, are for providing feedback on the guessed code placed in the small holes on the board. Played between two players in a board game, one player becomes the codemaker, the other the codebreaker. The codemaker chooses a code, a pattern of four code marbles. Duplicates are allowed depending on player choice, so the player could even choose four code marbles of the same colour. The chosen code is placed in the four large holes covered by the shield, visible to the codemaker but not to the codebreaker. The codebreaker tries to guess the code, in both order and colour, within a certain number of attempts (e.g., 10 in the picture above). Each guess is made by placing a row of code marbles on the decoding board. Once placed, the codemaker provides feedback by placing from zero to four key pegs in the small holes of the row next to the guess. A black key peg is placed for each code marble from the guess which is correct in both colour and position. A white key peg indicates the existence of a correct colour code marble placed in the wrong position. If there are duplicate colours in the guess, they cannot all be awarded a key peg unless they correspond to the same number of duplicate colours in the hidden code. For example, if the hidden code is white-white-black-black and the player guesses white-white-white-black, the codemaker will award two black key pegs for the two correct whites, nothing for the third white as there is not a third white in the code, and a black key peg for the black. No indication is given of the fact that the code also includes a second black. Once feedback is provided, another guess is made by the codebreaker; guesses and feedback continue to alternate until either the codebreaker guesses correctly, or the number of incorrect guesses reach the number of attempts allowed. If the code is not guessed correctly within the number of attempts allowed, then the shield is uncovered to reveal the code. The following video clip may be also helpful to understand the concept: https://www.youtube.com/watch?v=wsYPsrzCKiA The Assignment Task Specification As a text-based application software, WoM will use a command line interface where users type in a command or input and the relevant output is printed onto the screen in text. When the software is executed, it will show a greeting message and a list of commands, followed by a command prompt ‘>’ indicating the system is ready to take user’s input. At the prompt, users can give one of the following commands: 1. r: register a new user, which will create a new user 1. s: show the score board, which will print the list of the users and their scores 1. p: play a game, which will start a new game 1. q: quit, which will quit the application For registering a new user, the system will ask for the name of the new user. The username is not allowed to be changed after being registered, and also the name must be unique (i.e. not allowed to have the same name as an existing user). A new user will always start with a score of 0 point. Below is an example of the output on the screen (user’s input in bold italic). Welcome to the World of Mastermind! Developed by Alan Turing COMP 1048 UO Object-Oriented Programming What would you like to do? (r) register a new user (s) show the score board (p) play a game (q) quit > r What is the name of the new user? > Alan Welcome, Alan! What would you like to do? (r) register a new user (s) show the score board (p) play a game (q) quit > r What is the name of the new user? > Alan Sorry, the name is already taken. What would you like to do? (r) register a new user (s) show the score board (p) play a game (q) quit > r What is the name of the new user? > Steve Welcome, Steve! Once the users are registered, they can play the game of Mastermind. Only one game will be played at a time, i.e., the game must be finished before playing another game. Before starting the game, users will be asked questions for setting it up. First, users will be asked how many players (between 2 to 4, inclusive) will play the game, followed by asking for the name of each player. If the name does not match to a valid registered user or if the user with the name is already in the game, an error message will be shown and asked again. There will be a special built-in name “HAL9000” and “VIKI” that are for players controlled by the computer. Users are not allowed to register with these names assigned to computer players. After the players are selected, the users will be asked to choose how many attempts (between 5 to 10, inclusive) of guessing the code will be allowed. What would you like to do? (r) register a new user (s) show the score board (p) play a game (q) quit > p Let’s play the game of Mastermind! How many players (2-4)? > 2 What is the name of player #1? > Bill Invalid user name. What is the name of player #1? > Alan What is the name of player #2? > Alan Alan is already in the game. What is the name of player #2? > HAL9000 How many attempts will be allowed for each player (5-10)? > 5 After it’s all set, the game will start. The game is played in a round-robin manner where each player takes a turn. First, each player will take a turn to make a code for the next player who has to break it. Think of it as if each player has a decoding board, and each player sets the code hidden behind the shield for the next player if it were in an actual board game. For example, if there are three players, first player sets the code for the second player to break, the second player sets the code for the third player, and the third player sets the code for the first player. To set the code, users will enter a string of four characters, each character representing a colour that consists the code. The characters representing colours are, ‘R’ for red, ‘G’ for green, ‘B’ for blue, ‘Y’ for yellow, ‘W’ for White, and ‘K’ for black. For example, ‘RGBK’ will be a code of red, green, blue, and black. If the code entered is invalid (i.e. either not having four colours or including any invalid colour) an error message is printed and asked for entering the code again. If the player in turn is a computer, it will generate a random code. * Alan's turn to set the code for HAL9000 to break. Please enter the code: > BTWRA Invalid code. It must be exactly four characters, each can be R, G, B, Y, W, or K. Please enter the code: > BYWR The code is now set for HAL9000 to break. * HAL9000's turn to set the code for Alan to break. The code is now set for Alan to break. Once all of the players took turn to set the code for the next player, players take turns to guess the code set for him/her/itself. In each turn, a summary of previous attempts of the player taking the turn is shown on the screen. Users are then asked to enter their guess, while the computer players will randomly generate its guess and print it on the screen. The feedback on a guess is automatically provided by the system. If a player breaks the code (i.e., gives the correct code) the game continues with the rest of the players until everyone either succeeds to break the code or fails by using up all the number of attempts allowed. * Alan's turn to guess the code. Previous attempts: 0 Attempts left: 5 Please enter the code: > BGY Invalid code. It must be exactly four characters, each can be R, G, B, Y, W, or K. Please enter the code: > BGYY Feedback: K * HAL9000's turn to guess the code. Previous attempts: 0 Attempts left: 5 HAL9000’s guess: BRWG Feedback: K K W * Alan's turn to guess the code. Previous attempts: 1 ============== Code Feedback ============== BGYY K ============== Attempts left: 4 Please enter the code: > BKRW Alan broke the code in 2 attempts! * HAL9000's turn to guess the code. Previous attempts: 1 ============== Code Feedback ============== BRWG K K W ============== Attempts left: 4 HAL9000’s guess: GWKG Feedback: W * HAL9000's turn to guess the code. Previous attempts: 2 ============== Code Feedback ============== BRWG K K W GWKG W ============== Attempts left: 3 HAL9000’s guess: WGWK Feedback: K * HAL9000's turn to guess the code. Previous attempts: 3 ============== Code Feedback ============== BRWG K K W GWKG W WGWK K ============== Attempts left: 2 HAL9000’s guess: BYWG Feedback: K K K * HAL9000's turn to guess the code. Previous attempts: 4 ============== Code Feedback ============== BRWG K K W GWKG W WGWK K BYWG K K K ============== Attempts left: 1 HAL9000’s guess: RYWG Feedback: K K W HAL9000 failed to break the code. The game is now finished. Alan receives 4 + 5 = 8 points. What would you like to do? (r) register a new user (s) show the score board (p) play a game (q) quit > _ Once everyone either breaks the code or uses up the number of attempts allowed, the game finishes with showing the results with the points each user receives. Note that the computer players don’t receive any points. Each user receives points according to the number of attempts left + 1 after breaking the code. In addition, users also get points for one less than the number of attempts made by the next player for whom they set the code for. For example, in a game with 10 attempts allowed,
Aug 29, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here