Y12 FP Mastermind
Y12 FP Mastermind
Y12 FP Mastermind
For the final project you are asked to write a program that plays Mastermind. Mastermind is a two-player board game in which one player thinks of a secret code and the second player is allowed a number of attempts to guess the code. Each guess is marked, to indicate how close it is to the correct answer. There are several variations of the game, altering the complexity of the code and the number of guesses allowed. The board game uses large coloured pegs to represent the code, and smaller black and white pegs to mark each guess (some versions of the game used red instead of black pegs, including the online example below). We will use integers as these are easier to manipulate and display on the computer. Rules of the board game can be viewed at http://en.wikipedia.org/wiki/Mastermind_(board_game) and an online version can be played at http://www.web-games-online.com/mastermind/ We will start with a game that allows 10 guesses and uses a 4 digit code, where each digit is in the range 0-7. Lets assume the codemaker selects 7 6 1 3 as the code, and the codebreaker makes a first guess of 3 2 1 0 The marking process is as follows. For each digit in the guess: one black peg is awarded if it has the correct value and position (e.g. the digit 1 in the example) one white peg is awarded if it has the correct value but is in the wrong position (such as 3 in the example). no pegs are awarded if the digit does not appear in the code
A maximum of one peg is awarded per digit in the guess. If the guess contains duplicate digits, white pegs can only be awarded for digits in the code that havent been matched already. For example code = 0 1 2 3 guess = 0 0 1 1 would score 1 black peg (for the 0) and 1 white peg (for the matching 1 in the wrong position). The remaining digits in the guess (0, 1) do not match the remaining digits in the code (2, 3) and so are not awarded pegs. Similarly code = 0 0 1 1 guess = 0 0 0 1 would score 3 black and no white. Once the guess has been marked, the codebreaker makes another guess; this continues until the code has been found or the codebreaker has made the maximum number of guesses. For example, if the code is 7 6 1 3 we might guess as follows: 0) 3 2 1 0 : correct 1 wrongPlace 1 1) 5 2) 7 3) 6 4) 7 4 3 3 6 2 1 1 1 0 6 7 3 : correct 0 : correct 2 : correct 1 : correct 4 wrongPlace 0 wrongPlace 2 wrongPlace 3 wrongPlace 0
Various scoring schemes are possible - we will award the codemaker one point for each guess plus an additional point if the code is not broken by the end of the game. In the example above, the codemaker gains 5 points. Players take it in turns to be codemaker and codebreaker, for an agreed (even) number of games.
The program
Your program should be able to play as codebreaker or as codemaker. Initially you can treat these as separate problems and make simplifying assumptions (e.g. no duplicate digits, only valid inputs are given, 10 guesses are allowed to find a 4 digit code, where each digit is in the range 0-7). When the computer is playing as codebreaker, you can choose whether the human player or the computer marks each guess. The final project will not be automarked, so you have considerable freedom in how to display the state of the game, etc. (the example output above is just for illustration, you are under no obligation to follow this output convention). However, note that your code may be compiled on a computer running something other than Visual Studio. Use of non-standard C libraries (particularly for input and output) may result in loss of marks if your program is not portable. As part of the assessment you are asked to 1. Fill out an assessment form, where you indicate the mark you think your program should get (see PDF form). 2. Write a small user guide. Here you can discuss for instance How to run the program (what input is expected from the user; what is output by your program and how should that be interpreted). Does your program support any variants (such as allowing the user to choose the number of guesses, the number of digits to guess or the range of allowed digits)?
3. Write documentation about the code itself. Here you can think about some of the following (you do not necessarily need to address all these issues) An explanation of the most important or most interesting functions that you are using. An explanation of your main data structure(s), e.g. to keep track of which codes have been guessed so far, or which digits are currently still possible. Brief explanation of what different files do . Acknowledgment of sources. This is an individual assessment and you have to write your own code. However, you are allowed and indeed encouraged to use online and written sources to investigate strategies for breaking the code, and to discuss the problem with each other. If you use a strategy that was jointly worked out, or you have implemented an algorithm found on the web, please give an indication here. This is especially relevant when `cleverness' (see assessment sheet) is considered. Specific programming techniques you are particularly proud of (e.g. good use of pointers, advanced analysis of the possible solutions). Challenging bugs that you encountered and how you dealt with them. Possible room for improvement.
The user guide and documentation should not take more than 2 pages in total. Their main goal is to help us assess your program as accurately as possible and to allow you to explain what you think is good (or open for improvement) about your program. In particular, the code documentation will feed into how we mark the cleverness of your program. The user guide and documentation will be marked as well, but mainly on content and not on style (however, if the style is so poor it becomes hard to read, you might drop points on style). Submission will be through SAFE in the normal way. Submit all C files that are needed to compile your code (take extra care if you use your own header files). The user guide and documentation should be submitted as PDF or text files (NOT as word files or in any other format). Please also complete and submit the self-assessment form as a PDF.