Skip to main content

2015 Fall Computer Science I Program #3: Mastermind

Introduction

In the popular game Mastermind, one player creates a secret code of four pegs, each of which can be chosen from one of six colors. (The number of pegs and colors may be different than this in different versions, but your implementation will use these values, but be extendible to other values. Also, a color can be reused, thus there really are six choices for each of the four pegs.) The other player then has to guess the color of each peg, with the order mattering.The player who made the secret code then has to give feed back to the player guessing. This feedback is in the form of white and black pegs. A black peg means that the guesser has chosen the correct color in the correct slot.
These are first “calculated” and awarded. Once these are counted, these pegs are ignored. Then the white pegs are awarded. These are for pegs that are the correct color but are in the incorrect slot. There is no “double dipping” of pegs in the response, so the sum total of white and black pegs the guesser can receive is four, and no one peg in the guesser’s answer may earn them more than one black or one white peg.
Your task will be to analyze a partially completed game and calculate the number of possible color combinations that are completely consistent with all of the given information. Due to the fact that the manufacturer may release different versions of the game with a different number of possible colors and a different number of possible slots, your program should work where these two values are given as variables.

The Input (read from standard input)

The first line of input will contain a single positive integer, c (c ≤ 100), representing the number of input cases. The first line of each input case will contain three space-separated positive integers, n, the number of slots to fill in, k (k ≥ 2), the number of possible colors for each slot, and m (m ≤ 20), the number of moves that have currently been played. It's guaranteed that kn ≤ 106. The following m lines will contain information about each player guess for that round. Each of these lines will start with n space separated non-negative integers, each in between 0 and k-1, inclusive, representing the player's guess, in order, for filling the slots of the secret combination. The last two integers (also space separated) on each line will be b and w, representing the number of colors in correct locations guessed correctly in the combination and the number of colors in the incorrect locations guessed correctly, respectively.

The Output (to standard out)

For each input case, output a single integer, on a line by itself, representing the number of possible combinations consistent with the partially played game for the case. You are guaranteed that each input case will have at least one possible combination meaning that the information given for the input case is correct and the person reporting the number of matches has done so.

Sample Input

3 4 6 4 0 1 2 3 0 22 2 4 1 0 24 3 3 2 1 11 3 5 4 1 36 10 30 1 2 3 4 5 0 07 7 8 8 9 9 0 49 9 7 7 8 8 4 010 2 10 1 0 1 0 1 0 1 0 1 5 4

Sample Output

1
36200

Use of Global Variables

Often times, teachers discourage the use of global variables because students use them because they do not understand parameter passing. Most uses of global variables are poor, however, there are situations where they make code easier to read and debug, such as this program. The qualities of this program that make it a reasonable place to use globals are that it's fairly short, there's some common information that doesn't change while processing a single input case that is needed by several functions, and the logic and readability of the most important function (the recursive one) are enhanced if globals are used. Thus, for this assignment, feel free to use global variables within the context described above. No penalty will be given for doing so.

Implementation Detail - Use of Recursion

Though this problem can be solved iteratively, the recursive solution is more elegant. Full credit will only be given to correct recursive solutions that use good programming style.

Images of Working program




Deliverables

You must submit a single file, mastermind.c, over WebCourses. Please use stdin, stdout.
Order now what are you waiting for? Get your solution in just one minute :D

Buy now

CONTACT DETAILS

For any other questions or other tasks please feel free to contact me
via email: mhassnainjamil@gmail.com
via WhatsApp: +92-324-7042178
via skype: hassnainjamil1

Comments

Popular posts from this blog

The Zoo Management System - entity relationship diagram & MS Access Database

Zoo Management System - Project Details: You are the employee of a big, worldwide working Zoo Management Company. Your company is responsible for the Zoo management. Your boss thinks it would be a great idea to store all data for each Zoo in a brand new self-developed ZOO Management System. Up to now, the ZOO management company has maps of each ZOO available. Your boss knows that you took a course in introduction on an ERP system, so he asks you if you could help designing such a system. Each ZOO must have the same organizational structure, which should look like this: Each Zoo has a Zoo-Address. Each Zoo has many visitors (Visitor Ticket Process (VTP). Many Zoo-Attractions belong to a Zoo. Module 1: Entity Relationship Diagram Design a ER (entity-relationship) diagram for your ZOO Management System. Use the information provided below with the entities and its attributes. Put the entities in the correct relationship to each other (organizational structure). Module 2: DB Implem...

Human Physiology by Stuart Ira Fox [PDF] (12th edition) free download

Student Registration System Web Project using HTML, CSS & PHP

Student Registry System In this task, you’re to further develop the student registry you started on lab-task. The solution is based the on the use of HTML5, stylesheets, and PHP, and will use a database for storage of information, MySQL on (school website) is used for this. Information of students is saved in the table student, ID is primary key and is set In addition to this, you need a table named class where id a is the primary key and is set up with AUTOINCREMENT, other columns and data types in accordance with the figure. The property class in the student table needs to be a foreign key that refers to the ID column in the class table. In MySQL you need to use tables of the type INNODB with support for foreign keys, reference integrity shall remain. The task: Write a class with the name StudentRegister (means Student registry), the class should use PDO and only prepared statements/questions. The class shall implement the interface StudentInterface, and use the two classes, Student,...