Ask Computer Engineering Expert

Programming Assignment Bulls and Cows

This project is about a modified version of Bulls and Cows. Instead of playing the game by using 4-letter words, the number of letters in a word in this modified version for the player to guess ranges from 1 to 21 letters. The modified version of the game plays as follows:

• A player (Host) comes up with a valid secret word from the word list.

• Another player (Guesser) tries to come up with a probe word.

• The Host responds by giving the Guesser the number of bulls and cows for the probe word. "Bulls" gives information about how many letters in the probe word match the letters in the secret word in the right position while "Cows" gives information about how many letters in the probe word match the letters in the secret word in the wrong position. The number of letters counted in "Bulls" cannot be double counted in "Cows" though.

• If the Guesser correctly guessed the secret word, then the game is over. Otherwise,the Guesser needs to come up with another probe word and obtains feedback from the Host until the Guesser correctly guesses the secret word.

For example, if the secret word is apocalypse and the probe word is abstract, then the Host should respond 1 "Bulls" and 3 "Cows". If the secret word is apocalypse and the probe word is a, then the Host should respond 1 "Bulls" and 0 "Cows". If the secret word is abstract and the probe word is abstain, then the Host should respond 4 "Bulls" and 1 "Cows".

Your task for this project will be to implement a Bulls and Cows solver that, given a secret word in the test program, will produce as few number of probe words as possible that lead the Guesser to correctly guess the secret word. Because we may give you a large word list, you will want to come up with an efficient way of generating as few number of probe words as possible that correctly guess the secret word. It is possible that your algorithm might correctly guess the secret word in 1 step, but the probability is 1/60000 given a word list with 60,000 words.

Here is the interface for a Game class (Game.h) that lets you initialize a word list we provide in the constructor, set up a a secret word, determine the length of the secret word, and determine the "Bulls" (nInRightPlace) and "Cows" (nInWrongPlace) from the probe word provided by the Player:

class Game
{
public:
Game(const vector &words); bool setSecretWord(const string &sw); int secretWordLength() const;
void probe(const string &probeWord, int &nInRightPlace, int &nInWrongPlace);
~Game(); private:
// Prevent people from copying Game objects. Game(const Game&);
Game& operator=(const Game&);
// Define your own data structure here
// ...
string secretWord;
};

• The constructor stores the given word list in a data structure of your choice as private data member. setSecretWord() takes in a secret word and checks against the word list to determine if the given secret word is in the word list. If it is, return true, otherwise return false.

• secretWordLength() returns the length of the secret word.

• probe() takes in a probe word provided by the Player, determines "Bulls" and "Cows", stores the correct value of "Bulls" in nInRightPlace, and stores the correct value of "Cows" in nInWrongPlace

• The destructor does whatever is necessary to clean up.

Here is the interface for a Player class (Player.h).

class Player
{
public:
Player(const vector &words); string generateProbeWord();
void learn(string probe, int nInRightPlace, int nInWrongPlace);
~Player(); private:
// Prevent people from copying Player objects. Player(const Player&);
Player& operator=(const Player&);
// Define your own data structure here
};

• The constructor stores the given word list in a data structure of your choice as private data member. You may also need to build a data structure inside the constructor that allows you to efficiently search for the next probe word to return when generateProbeWord() is called.

• generateProbeWord() returns a probe word chosen by the Player.

• learn() tells the Player how many bulls and cows are in the probe word; that information presumably comes from a previous call to Game::probe(). The Player object does what is necessary to update its data structures in light of that information.

• The destructor does whatever is necessary to clean up your data structures.

None of these member functions may read from cin or write to cout. (They can write debugging information to cerr, which we will ignore.)

Here is a very simple working solution for a Player class that does not meet the requirement for this project as it performs a linear search through the word list.

class Player
{
public:
Player(const vector &words) { wordlist = words;
n = 0;
}
string generateProbeWord() { return wordlist[n++];
}
void learn(string probe, int nInRightPlace, int nInWrongPlace) { }
~Player() { } private:
// Prevent people from copying Player objects.
Player(const Player&);
Player& operator=(const Player&);
// Define your own data structure here vector wordlist;
int n;
};

When we test your code, we will use a large word list file of about 60,000 words that we will provide you here. (The file came from an open-source wordlist project that is hosted at wordlist.sourceforge.net. If you're interested in building a freeware or open-source application that requires a large list of English words, this is a great place to get a wordlist for it.) Here's a small example of some tests:

#include
#include
...
using namespace std;

const char* filename = " ";
// A Windows user might have the path be "C:/CS32/P4/wordlist.txt"
// A Mac user might have it be "/Users/fred/CS32/P4/wordlist.txt"

void play(Game& g, Player &p)
{
int secretLength = g.secretWordLength(); int nTurns = 0;
for(;;)
{
int nInRightPlace, nInWrongPlace; string probe = p.generateProbeWord();
g.probe(probe, nInRightPlace, nInWrongPlace);
// repeat probes until word is guessed nTurns++;
if (nInRightPlace == secretLength) break;
p.learn(probe, nInRightPlace, nInWrongPlace);
}

cerr << "The Player probed " << nTurns << " times!" << endl;
}

int main()
{
ifstream wordlistfile(filename); if (!wordlistfile)
{
cerr << "Cannot open " << filename << "!" << endl; return 1;
}
vector words;

string w;
while (wordlistfile >> w)
words.push_back(w);

Player player(words); Game g(words);

if (!g.setSecretWord("apocalypse")) // Supply the secret word
{
cerr << "Secret word is not in word list!" << endl;

return 1;
}

play(g, player);
}

Here are some requirements your program must meet:

• You must not add any public members to Game or Player. You are allowed to add private data members and private member functions if you wish.

• Your program should be efficient enough to generate as few number of probe words as possible that lead the Player (Guesser) to correctly guess the secret word. A linear search solution provided above will guarantee to fail the performance requirement for this project. In order to satisfy this performance requirement, your Player constructor is allowed to run up to 25 seconds on the SEASnet Linux server, and your generateProbeWord and learn functions are allowed to run up to 5 seconds each on the SEASnet Linux server.

• You may design interesting data structures of your own, but the only containers from the C++ standard library you may use are vector, list, stack, and queue (and string). If you want anything fancier, implement it yourself. (It'll be a good exercise for you.) If you decide to use a hash table, it must not have more than 100000 buckets. (Using a hash table is a good way to get reasonable speed with a large word list.) Although we're limiting your use of containers from the library, you are free to use library algorithms (e.g., sort).

• During execution, your program must not perform any undefined actions, such as dereferencing a null or uninitialized pointer.

Attachment:- Wordlist.rar

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M91924200

Have any Question?


Related Questions in Computer Engineering

Does bmw have a guided missile corporate culture and

Does BMW have a guided missile corporate culture, and incubator corporate culture, a family corporate culture, or an Eiffel tower corporate culture?

Rebecca borrows 10000 at 18 compounded annually she pays

Rebecca borrows $10,000 at 18% compounded annually. She pays off the loan over a 5-year period with annual payments, starting at year 1. Each successive payment is $700 greater than the previous payment. (a) How much was ...

Jeff decides to start saving some money from this upcoming

Jeff decides to start saving some money from this upcoming month onwards. He decides to save only $500 at first, but each month he will increase the amount invested by $100. He will do it for 60 months (including the fir ...

Suppose you make 30 annual investments in a fund that pays

Suppose you make 30 annual investments in a fund that pays 6% compounded annually. If your first deposit is $7,500 and each successive deposit is 6% greater than the preceding deposit, how much will be in the fund immedi ...

Question -under what circumstances is it ethical if ever to

Question :- Under what circumstances is it ethical, if ever, to use consumer information in marketing research? Explain why you consider it ethical or unethical.

What are the differences between four types of economics

What are the differences between four types of economics evaluations and their differences with other two (budget impact analysis (BIA) and cost of illness (COI) studies)?

What type of economic system does norway have explain some

What type of economic system does Norway have? Explain some of the benefits of this system to the country and some of the drawbacks,

Among the who imf and wto which of these governmental

Among the WHO, IMF, and WTO, which of these governmental institutions do you feel has most profoundly shaped healthcare outcomes in low-income countries and why? Please support your reasons with examples and research/doc ...

A real estate developer will build two different types of

A real estate developer will build two different types of apartments in a residential area: one- bedroom apartments and two-bedroom apartments. In addition, the developer will build either a swimming pool or a tennis cou ...

Question what some of the reasons that evolutionary models

Question : What some of the reasons that evolutionary models are considered by many to be the best approach to software development. The response must be typed, single spaced, must be in times new roman font (size 12) an ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As