Question
Need help writing code in C for an AI to win a game like Bulls and Cows in the least amount of turns possible.-------------------------------------------------------------------------------------------------------------------------- Game:
Need help writing code in C for an AI to win a game like "Bulls and Cows" in the least amount of turns possible.--------------------------------------------------------------------------------------------------------------------------
Game: Similar to Bulls and Cows, the user inputs a random 4 digit number (with numbers from 1 to 8 being allowed and repeating digits allowed).
If the user enters a number in the correct position, 1 bull is given but if a correct number is entered but is not in the correct position, 1 cow is given. The AI should be able to play repeatedly until 4 bulls are reached.
An example of this game could include (with the AI entering the numbers in the most optimal order):
Here is a sample run, where we picked 9736: Enter a 4 digit number(repated digits allowed): 0987 bulls = 0 and cows = 2 Enter a 4 digit number(repated digits allowed): 9078 bulls = 1 and cows = 1 Enter a 4 digit number(repated digits allowed): 9780 bulls = 2 and cows = 0 Enter a 4 digit number(repated digits allowed): 9580 bulls = 1 and cows = 0 Enter a 4 digit number(repated digits allowed): 9740 bulls = 2 and cows = 0 Enter a 4 digit number(repated digits allowed): 9721 bulls = 2 and cows = 0 Enter a 4 digit number(repated digits allowed): 9768 bulls = 2 and cows = 1 Enter a 4 digit number(repated digits allowed): 9785 bulls = 2 and cows = 0 Enter a 4 digit number(repated digits allowed): 9756 bulls = 3 and cows = 0 Enter a 4 digit number(repated digits allowed): 9706 bulls = 3 and cows = 0 Enter a 4 digit number(repated digits allowed): 9716 bulls = 3 and cows = 0 Enter a 4 digit number(repated digits allowed): 9726 bulls = 3 and cows = 0 Enter a 4 digit number(repated digits allowed): 9736 bulls = 4 and cows = 0
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started