473,320 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Mastermind

The idea of the game is for one player (the code-breaker) to guess the
secret code chosen by the
other player (the code-maker). The code is a sequence of n colored
pegs chosen from m available
colors. The code-breaker makes a series of pattern guesses. After each
guess, the code-maker
gives feedback in the form of two numbers: the number of pegs that are
of the right color and in
the correct position (represented by small black pegs), and the number
of pegs that are of the
correct color but in a wrong position (represented by small white
pegs).
Complete the class CodeMaker, and construct a simple driver to test
your logic in checkBlack
and checkWhite functions.

class CodeMaker
{
public:
// add in relevant Big 3 and supporting functions
unsigned int checkBlack (char guess[]) const; // same position same
color
unsigned int checkWhite (char guess[]) const; // same color different
position

private:
unsigned int color; // total number of colors (m)
unsigned int length; // length of secret code (n)
char *secret; // secret code, supports duplicate colors
};

I don't quite understand what the code for
unsigned int checkBlack (char guess[]) const; // same position same
color
unsigned int checkWhite (char guess[]) const; // same color different
position
want me to do. Could anyone give details to me?
I have written the Big3 and some supporting functions. Thanks!
Jun 27 '08 #1
3 4003
"fo***********@gmail.com" <fo***********@gmail.comwrites:
The idea of the game is for one player (the code-breaker) to guess the
secret code chosen by the
other player (the code-maker). The code is a sequence of n colored
pegs chosen from m available
colors. The code-breaker makes a series of pattern guesses. After each
guess, the code-maker
gives feedback in the form of two numbers: the number of pegs that are
of the right color and in
the correct position (represented by small black pegs), and the number
of pegs that are of the
correct color but in a wrong position (represented by small white
pegs).
Complete the class CodeMaker, and construct a simple driver to test
your logic in checkBlack
and checkWhite functions.

class CodeMaker
{
public:
// add in relevant Big 3 and supporting functions
unsigned int checkBlack (char guess[]) const; // same position same
color
unsigned int checkWhite (char guess[]) const; // same color different
position

private:
unsigned int color; // total number of colors (m)
unsigned int length; // length of secret code (n)
char *secret; // secret code, supports duplicate colors
I'm sorry, but in the problem statement above, I don't see the word
"character" or "char", much less "pointer". How do you justify this
type for secret?
It is said that there's a secret code, and that "The code is a
sequence of n colored pegs chosen from m available".
So you should have:

Sequence<N,ColoredPegAmongst<M secretCode;

or something like that...

Or, if you don't want to deal with template (which may be overkill),
you could define types such as;

class ColoredPeg ... { ... };
class SequenceOfColoredPeg ... { ... };

with functional abstractions such as:

SequenceOfColoredPeg makeSetOfColoredPegs(unsigned int M);
SequenceOfColoredPeg makeSequenceOfRandomColoredPeg(unsigned int N,SequenceOfColoredPeg setOfColoredPegsToChooseFrom);

ColoredPeg SequenceOfColoredPeg::chooseRandomColoredPeg();
ColoredPeg SequenceOfColoredPeg::coloredPegAtPosition(unsigne d int position);
unsigned int SequenceOfColoredPeg::length();

bool sameColor(ColoredPeg a,ColoredPeg b);

unsigned int checkBlack(SequenceOfColoredPeg guess) const; // same color same position
unsigned int checkWhite(SequenceOfColoredPeg guess) const; // same color different position

etc... (or perhaps define classes for ColoredPeg and SequenceOfColoredPeg, and methods).

But I don't understand how you can came with such an horror from the
deep bowels of hell such as « char* ».
};

I don't quite understand what the code for
unsigned int checkBlack (char guess[]) const; // same position same
color
unsigned int checkWhite (char guess[]) const; // same color different
position
want me to do. Could anyone give details to me?
I have written the Big3 and some supporting functions. Thanks!
Let's take an example: Assume we have 4 colors, A, B, C, and D, (M=4)
and we have codes sequences of length 5 (N=5).

Assume the secret is: AABCD
and the guess is: ABCAD
B B

then checkBlack will return 2 because there are only two exact
matches, position per position:

AABCD
ABCAD
B B

and checkWhite will return 3, because there are three positions, that
are filled with a permutation of the remaining position that matches.

.ABC.
.BCA.
.WWW.

You can try the game here:
http://www.squiglysplayhouse.com/Gam...deBreaker.html
So to count the black, it's rather easy, you just have to scan the
code and the guess at the same time, and count and mark the matches.

Then to count the whites, you can scan for example the guess, and find
if there's a matching color in the code that is not marked yet. If
yes, then you mark it and count one.
--
__Pascal Bourguignon__
Jun 27 '08 #2
fo***********@gmail.com wrote:
The idea of the game is for one player [...]

class CodeMaker
{
public:
// add in relevant Big 3 and supporting functions
unsigned int checkBlack (char guess[]) const; // same position same
color
unsigned int checkWhite (char guess[]) const; // same color different
position

[..]
};

I don't quite understand what the code for
unsigned int checkBlack (char guess[]) const; // same position same
color
unsigned int checkWhite (char guess[]) const; // same color different
position
want me to do. Could anyone give details to me?
Your instructor should be the first one you ask.

Generally, with the provided 'guess' you need to return *how many* color
pegs are the same as in the code and are in the *correct positions* as
well (checkBlack) and in the *incorrect positions* (checkWhite). For
example, if the code is rwgb, and the *guess* is rgvy, then the first
guessed color ('r') in correct and positioned correctly, it counts in
'checkBlack'. The second guessed color ('g') is correct (because there
is 'g' in the code) but it positioned incorrectly, so it counts in
'checkWhite'.

Find the game on the web and play it.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 27 '08 #3
On Jun 13, 8:15 pm, p...@informatimago.com (Pascal J. Bourguignon)
wrote:
"foolsmart2...@gmail.com" <foolsmart2...@gmail.comwrites:
The idea of the game is for one player (the code-breaker) to guess the
secret code chosen by the
other player (the code-maker). The code is a sequence of n colored
pegs chosen from m available
colors. The code-breaker makes a series of pattern guesses. After each
guess, the code-maker
gives feedback in the form of two numbers: the number of pegs that are
of the right color and in
the correct position (represented by small black pegs), and the number
of pegs that are of the
correct color but in a wrong position (represented by small white
pegs).
Complete the class CodeMaker, and construct a simple driver to test
your logic in checkBlack
and checkWhite functions.
class CodeMaker
{
public:
// add in relevant Big 3 and supporting functions
unsigned int checkBlack (char guess[]) const; // same position same
color
unsigned int checkWhite (char guess[]) const; // same color different
position
private:
unsigned int color; // total number of colors (m)
unsigned int length; // length of secret code (n)
char *secret; // secret code, supports duplicate colors

I'm sorry, but in the problem statement above, I don't see the word
"character" or "char", much less "pointer". How do you justify this
type for secret?

It is said that there's a secret code, and that "The code is a
sequence of n colored pegs chosen from m available".

So you should have:

Sequence<N,ColoredPegAmongst<M secretCode;

or something like that...

Or, if you don't want to deal with template (which may be overkill),
you could define types such as;

class ColoredPeg ... { ... };
class SequenceOfColoredPeg ... { ... };

with functional abstractions such as:

SequenceOfColoredPeg makeSetOfColoredPegs(unsigned int M);
SequenceOfColoredPeg makeSequenceOfRandomColoredPeg(unsigned int N,SequenceOfColoredPeg setOfColoredPegsToChooseFrom);

ColoredPeg SequenceOfColoredPeg::chooseRandomColoredPeg();
ColoredPeg SequenceOfColoredPeg::coloredPegAtPosition(unsigne d int position);
unsigned int SequenceOfColoredPeg::length();

bool sameColor(ColoredPeg a,ColoredPeg b);

unsigned int checkBlack(SequenceOfColoredPeg guess) const; // same color same position
unsigned int checkWhite(SequenceOfColoredPeg guess) const; // same color different position

etc... (or perhaps define classes for ColoredPeg and SequenceOfColoredPeg, and methods).

But I don't understand how you can came with such an horror from the
deep bowels of hell such as « char* ».
};
I don't quite understand what the code for
unsigned int checkBlack (char guess[]) const; // same position same
color
unsigned int checkWhite (char guess[]) const; // same color different
position
want me to do. Could anyone give details to me?
I have written the Big3 and some supporting functions. Thanks!

Let's take an example: Assume we have 4 colors, A, B, C, and D, (M=4)
and we have codes sequences of length 5 (N=5).

Assume the secret is: AABCD
and the guess is: ABCAD
B B

then checkBlack will return 2 because there are only two exact
matches, position per position:

AABCD
ABCAD
B B

and checkWhite will return 3, because there are three positions, that
are filled with a permutation of the remaining position that matches.

.ABC.
.BCA.
.WWW.

You can try the game here:http://www.squiglysplayhouse.com/Gam...deBreaker.html

So to count the black, it's rather easy, you just have to scan the
code and the guess at the same time, and count and mark the matches.

Then to count the whites, you can scan for example the guess, and find
if there's a matching color in the code that is not marked yet. If
yes, then you mark it and count one.

--
__Pascal Bourguignon__
Actually,char *secret is a dynamic array storing the secret code.
Length of dynamic array is determined by the member variable length.
Thanks for your help.
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Andy Jacobs | last post by:
Hi All I've tried as many combinations as I can think of but I'm not getting any where. This is what I have: <? $menu = 'menus/' . $HTTP_GET_VARS . '.inc'; echo $menu; ?>
18
by: jblazi | last post by:
I should like to search certain characters in a string and when they are found, I want to replace other characters in other strings that are at the same position (for a very simply mastermind game)...
20
by: jblazi | last post by:
How do I find out my own IP number (using Pythoi of course). And how do I send/receive data to/from andother TCP/IP socket (of known ip number)? I mean: which module do I have to use for that? ...
19
by: Claudio Grondi | last post by:
I would like to save time copying the same file (>6 GByte) to various different target storage media connected to the system via USB. Is there a (Python or other) tool able to help me to do...
3
C++
by: estelle87 | last post by:
I am doing a mastermind game using C++. Anyone has any idea on how to do it? You can send me an email at est_elle87@yahoo.com Thanks!
1
by: idsh | last post by:
I cant make this code work. I am new at Python, and in this program I have made a simple mastermind program. After creating the widgets, I try to insert text in the textbox in a function but all I...
2
by: mira88 | last post by:
Hi, I have to program the Mastermind game( dont' know if anyone knows it). Anyway I've got my GUI looking quite pretty :), but I want to know something on working with Colors. I' ve got 6 colors to...
2
Butterflybis
by: Butterflybis | last post by:
Hi all, I’m newbie in java code development, I have written a mastermind play, and I would like to include a time limitation (for example 3 minutes) which appears like a coloured and vertical...
2
by: ImmortalFire | last post by:
/* * Mastermind * * Author: Gerald Cruz * * Date: June 21, 2008 * */ #include<iostream>
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.