Mastermind design walkthrough

22
Mastermind Design Walkthrough By Group A Eman Aldakheel Mohd Amir Shadaab Nilesh Yevle Pradeepa Nagarajan Qianyu Wang

description

This is a design walk through of Mastermind game that we developed using java

Transcript of Mastermind design walkthrough

Page 1: Mastermind design walkthrough

Mastermind Design Walkthrough

By Group A

Eman Aldakheel

Mohd Amir Shadaab

Nilesh Yevle

Pradeepa Nagarajan

Qianyu Wang

Page 2: Mastermind design walkthrough

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

Page 3: Mastermind design walkthrough

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

Page 4: Mastermind design walkthrough

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

Page 5: Mastermind design walkthrough

Main Board

Page 6: Mastermind design walkthrough

Main Architecture

MVC architecture used for Mastermind

Page 7: Mastermind design walkthrough

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.

Page 8: Mastermind design walkthrough

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

Page 9: Mastermind design walkthrough

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

Page 10: Mastermind design walkthrough

How different components interactUser enters his secret code

Page 11: Mastermind design walkthrough

User guesses computer’s secret code

Page 12: Mastermind design walkthrough

Computer guesses user’s secret code

Page 13: Mastermind design walkthrough

Class diagram in MVC architecture

Page 14: Mastermind design walkthrough

Class diagram in Model

Page 15: Mastermind design walkthrough

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)

Page 16: Mastermind design walkthrough

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

Page 17: Mastermind design walkthrough

Class diagram in View

Page 18: Mastermind design walkthrough

Class diagram in View

Page 19: Mastermind design walkthrough

Class diagram in View

Page 20: Mastermind design walkthrough

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.

Page 22: Mastermind design walkthrough

Thank You!Any Questions?