Binary value if a human is playing

This commit is contained in:
Matúš Púll 2024-12-04 12:38:33 +01:00
parent 7d756bc066
commit 137c23cda7

View file

@ -21,6 +21,7 @@ int main(int argc, char* argv[]) {
string player = get_input("-p", args, string("Who plays [")+HUMAN+"/"+BOT+"]", "bot");
bool learn = "y" == get_input("-l", args, "Do you want to know what bot learns [y/n]", "y");
string gen = player == HUMAN ? RANDOM : get_input("-g", args, "Who generates the seque", RANDOM);
bool human_player = player == HUMAN;
// Generate the sequence
auto sequence = vector<int>(N);
@ -41,7 +42,7 @@ int main(int argc, char* argv[]) {
if(col < 0 || col >= M) return 1;
// Human info
if(player == HUMAN) {
if(human_player) {
cout << std::endl;
cout << "Guesses are " << N << " space-separated numbers from 0 to " << M-1 << std::endl
<< "Responses are in format [correct out of place] / [correct in place]" << std::endl;
@ -57,18 +58,8 @@ int main(int argc, char* argv[]) {
vector<int> guess(N);
Response response;
// Bot playin
if(player == BOT) {
guess = bot.guess();
response = validate(sequence, guess);
bot.learn(guess, response);
if(learn)
cout << "Guess " << history.size() << " : " << format_guess(guess) << format_response(response);
}
// Human playing
else if(player == HUMAN) {
if(human_player) {
cout << "Guess " << history.size() << " : ";
for(int n = 0; n < N; n++)
cin >> guess[n];
@ -80,6 +71,16 @@ int main(int argc, char* argv[]) {
bot.learn(guess, response);
}
// Bot playin
else {
guess = bot.guess();
response = validate(sequence, guess);
bot.learn(guess, response);
if(learn)
cout << "Guess " << history.size() << " : " << format_guess(guess) << format_response(response);
}
if(learn)
bot.print();
history.push_back(guess);
@ -90,7 +91,7 @@ int main(int argc, char* argv[]) {
cout << std::endl;
// Print game history
if(player == HUMAN)
if(human_player)
cout << "History\n";
for(auto guess : history)
cout << format_guess_history(sequence, guess) << std::endl;