Mastermind In this assignment, you will program the well-known game Mastermind. In Mastermind, player 1 creates a pattern consisting of a pre-approved number of colored pins. Then player 2 has to guess this pattern in as few turns as possible. Each turn, player 2 can guess what the pattern might be. Player 1 will then tell player 2 how many correct colors were guessed, and how many of those correctly guessed colors were guessed in the right place. Player 2 can then use this information to improve their guess for the next turn. When player 2 guesses the correct pattern, the game ends. Write a program that acts as player 1 of the Mastermind game. This program will generate a (random) pattern, and will play according to the game’s rules, with a human acting as player 2. The program should stop when the user guesses the pattern. Additionally, the program has to conform with the following specifications: 1. Because of practical reasons, the pattern will consist of capital letters instead of colors. 2. The number of different letters that can be used in a pattern must be specified by the human player. This number cannot be larger than 15 (A until O). 3. The length of the pattern must be specified by the human player. To generate a random pattern, the following function can be used: # This function generates a random string with length pattern_length. # The string can contain characters 'A'until 'A'+ number_of_letters - 1. import random def generate_pattern(number_of_letters, pattern_length): result = '' for i in range(pattern_length): letter_index = random.randint(1, number_of_letters) letter = chr(ord('A') + letter_index – 1) result += letter return result For example, generate_pattern(3, 4) will generate a random string of length 4, that consists of the letters A, B, and C. Example: Number of different letters: 14 Pattern length: 4 > AAAA correct letters: 2, letters in correct place: 2 > DCBA correct letters: 2, letters in correct place: 1 > AABN correct

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Mastermind
In this assignment, you will program the well-known game Mastermind. In Mastermind, player 1
creates a pattern consisting of a pre-approved number of colored pins. Then player 2 has to guess
this pattern in as few turns as possible. Each turn, player 2 can guess what the pattern might
be. Player 1 will then tell player 2 how many correct colors were guessed, and how many of those
correctly guessed colors were guessed in the right place. Player 2 can then use this information to
improve their guess for the next turn. When player 2 guesses the correct pattern, the game ends.
Write a program that acts as player 1 of the Mastermind game. This program will generate a
(random) pattern, and will play according to the game’s rules, with a human acting as player 2.
The program should stop when the user guesses the pattern.
Additionally, the program has to conform with the following specifications:
1. Because of practical reasons, the pattern will consist of capital letters instead of colors.
2. The number of different letters that can be used in a pattern must be specified by the human
player. This number cannot be larger than 15 (A until O).
3. The length of the pattern must be specified by the human player.
To generate a random pattern, the following function can be used:
# This function generates a random string with length pattern_length.
# The string can contain characters 'A'until 'A'+ number_of_letters - 1.
import random
def generate_pattern(number_of_letters, pattern_length):
result = ''
for i in range(pattern_length):
letter_index = random.randint(1, number_of_letters)
letter = chr(ord('A') + letter_index – 1)
result += letter
return result
For example, generate_pattern(3, 4) will generate a random string of length 4, that consists of
the letters A, B, and C.
Example:
Number of different letters: 14
Pattern length: 4
> AAAA
correct letters: 2, letters in correct place: 2
> DCBA
correct letters: 2, letters in correct place: 1
> AABN
correct

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education