Mastermind design walkthrough
-
Upload
amir-shadaab-mohammed -
Category
Documents
-
view
447 -
download
0
description
Transcript of Mastermind design walkthrough
Mastermind Design Walkthrough
By Group A
Eman Aldakheel
Mohd Amir Shadaab
Nilesh Yevle
Pradeepa Nagarajan
Qianyu Wang
What the game is all aboutRules
The player enters a secret 4 digit code and the computer selects a 4 digit code too
Aim: To guess the code of the opponent correctly before the opponent guesses your code
Each player makes guesses in turns and gets a feedback related to the guess made which can be used in the next turn to make a more intelligent guess
Feedback:
White pegs: The number of digits that are in the secret code but are in the wrong position
Black pegs: The number of digits that are in the secret code, and are in the right position
Main Menu
• The main menu has three options• New Game – Starts a new game• Rules – Shows instructions on how
to play the game• Quit – Closes the application
• This is the page where the user goes if he clicks “Main Menu” button which is available on the game board
Code setting window
• Number is disabled when clicked to have a code with non repeating digits
• Enter will be enabled when all for digits in the code are ready to be entered
Main Board
Main Architecture
MVC architecture used for Mastermind
Components in MVC architectureController • The Controller is responsible for the flow of the data transmission• It consists of the ‘main’ method which is responsible for starting the game• It is responsible for creating the View classes and Model classes• It maintains instances of the Model classes and invokes various business
methods in them; in response to user’s actions which could be either inputting the data or controlling the Graphical User Interface (GUI) for displaying the data using View classes
View • View classes handle the GUI for the user• The data to be represented will be received from Controller whenever the user
inputs new information or performs specific actions.• The received data from Controller will be presented in different elements such as
Textbox, Label, Button, Table etc. (Some of these widgets can accept input from the user)
• The View is independent from the Model classes; thus, it does not maintain any information about the existing classes in the Model.
Model • The Model is the main component and the heart of the application• It has classes that will perform majority of the game functionality part• The contained objects will have different business methods which are related to different
business events and scenarios that take place in the context of the application• The master class is the Game class which is a concrete class that will keep track of the
player’s turn and the outcome of the game
Advantages of MVC architecture• Display and Processing are separated
• Future enhancements and other maintenance of the code base made very easy and reusable
• Attach multiple views to a model to provide different presentations (view/model decoupling)
• Change the way a view responds to user input without changing its visual presentation” (view/controller decoupling)
• All this combined gives GREAT FLEXIBILITY
How different components interactUser enters his secret code
User guesses computer’s secret code
Computer guesses user’s secret code
Class diagram in MVC architecture
Class diagram in Model
Class diagram in Model
• Used to have flexibility and maintainability• We can increase the difficulty level in the future by adding concrete classes that use a
better version of the algorithm for guessing• New checker functionality can be added when we decide to have a different method of
checking for feedback (Eg: Giving only feedback when the position as well as the number match and not for number only)
Class diagram in Controller
• The controller component handles the entire application and the game starts by running the main method in the controller component(singleton pattern)
• Only instance of the controller should be used to handle the game application• Using a singleton pattern to control the creation of Controller class instances helps us in
this case
Class diagram in View
Class diagram in View
Class diagram in View
Algorithm used by the computer• The algorithm used to play the computer’s chance is based on the famous
five-guess algorithm which was developed by Donald Knuth in 1977. The steps involved in guessing a code given by the user is as follows:
1. Create a set S of remaining possibilities (Which is initially 10*9*8*7). Select the first possibility from this set and use it as the first guess and get the feedback for this guess
2. Remove all possibilities from S that would not give the same score of black and white pegs in the feedback if they were the answer
3. Select the first possible code from S and use it as the next guess and get the feedback.
4. Go back to step 2 until you have got it right
This is the only algorithm being used right now but we can add various
difficulty levels, as we are using strategy pattern to implement the algorithm.
References
1) MVC Pattern: http://msdn.microsoft.com/en-us/library/ff649643.aspx
2) Mastermind algorithm:http://en.wikipedia.org/wiki/Mastermind_(board_game)
Thank You!Any Questions?