Bulls and Cows is an old English game whose object is guessing a secret number using a minimum number of attempts. The digits of this secret number have to be all different, thus 1234 is a legal secret number but 1123 is not legal and should not be used in this game.
The game involves two players: one chooses the secret number and the other one tries to guess the secret number. After each guess, the opponent player informs the player about:
Your task is writing a C program to simulate the described game. The computer will play the role of the player who chooses the secret number and the user will play the game by attempting to guess.
What will be the digit count of the secret number?
The digit count of the secret number will be indicated by the user. Therefore, if you are using a string to store the secret number -this is a suggestion-, it should be allocated dynamically according to the user-defined digit count.
How will the program generate the secret number with all different digits?
This is a good sub-problem and various kinds of algorithms can be designed for that purpose. Actually, the algorithm is up to you but it can be pointed out that you should use the random number generator by recalling rand() and srand() functions, as you can also predict.
How will the program direct the user after each guess is evaluated?
As in the description of the game, the program will score each guess by counting cows and bulls.
Under which conditions the user will lose the game?
Either the maximum number of attempts is exceeded, or the user gives up by typing "quit"
How should the program behave, when a malformed guess is encountered?
Any guess that are malformed should be rejected and a new guess is requested from user by the program. Here is the word "malformed" implies only the following two conditions:
In what condition the program will be terminated?
After the user wins or lose, the program should ask her that whether she want to continue with a new game or exit. If she types "yes", your program will let her to play a new game by repeating the same steps: getting the digit count from user, generating a new secret number, evaluating each guess comes from the user...etc. If the user types no, the program will be terminated.
***We want your program to record the information about each game (let's say "hand") played by user, to a history.txt file. For this purpose, define a structure to represent the hands. A hand record should contain the following members: