Programming Assignment 2 Solution

$29.99 $18.99

Description: For this assignment, you will write a Python version of the Mastermind game. Mastermind is a two-player logic game and what passed for fun before the internet existed. Details: A game of Mastermind begins with one player choosing a hidden pattern of 4 pegs, each of which is one of 6 colors. Colors may…

You’ll get a: . zip file solution

 

 

Description

Rate this product

Description: For this assignment, you will write a Python version of the Mastermind game. Mastermind is a two-player logic game and what passed for fun before the internet existed.

Details: A game of Mastermind begins with one player choosing a hidden pattern of 4 pegs, each of which is one of 6 colors. Colors may be repeated in the pattern. The other player then tries to deduce the pattern through a series of \guesses.” Each guess consists of a pattern of 4 pegs. If a guess is correct, the guessing player wins and the game is over. Otherwise, the player is told how many colors and positions he/she has right. This is done with white and black pegs. A white peg indicates that a color is correct while a black pegs indicates that a color and position are correct. However, the position is not identi ed. The guesser’s goal is, of course, to deduce the pattern in as few guesses as possible.

In our version of the game, the computer will always be the player that chooses the pattern and a human player will be the guesser. Thus, the pattern will be determined at random. The six colors are: black, white, red, green, purple, and orange. Note that each begins with a unique rst letter so that they can be concisely represented on the board as a single upper-case letter. The pegs indicating the quality of the guess, will be represented using a single lower-case ’b’ or ’w’.

You will write a number of Python functions to solve this problem. They include: create new game, get guess, evaluate guess, and print board. Each is speci ed below. You may have additional functions a well but those listed must be part of your implementation. Note that print board prints the current guess and result as well as all previous guesses and result in the game.

You will choose your representation of the data. Think carefully about this before you begin coding.

Function Speci cations:

create new game

{ Parameters: none

{ Returns: a valid game pattern in your chosen representation

get guess

{ Parameters: none

{ Returns: a valid game pattern, indicating the user’s guess, in your chosen representation

evaluate guess

{ Parameters: a valid game pattern

{ Returns: sequence of pegs indicating correctness of the guess, in your chosen representation

print board

{ Parameters: a valid game board

{ Returns: none

Adhere to common coding conventions and comment your code.. Include a comment at the top that looks like this:

#

  • CS 224 Spring 2019

  • Programming Assignment 2

  • Your wonderful, pithy, erudite description of the assignment.

  • Author: Your name here

  • Date: March 13, 2019

#

Submission: The name of your program must be mastermind.py. Submit your solution as a compressed directory by 11:59 PM on the due date.

3