Binary value if a human is playing
This commit is contained in:
parent
7d756bc066
commit
137c23cda7
1 changed files with 14 additions and 13 deletions
27
main.cpp
27
main.cpp
|
@ -21,6 +21,7 @@ int main(int argc, char* argv[]) {
|
||||||
string player = get_input("-p", args, string("Who plays [")+HUMAN+"/"+BOT+"]", "bot");
|
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");
|
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);
|
string gen = player == HUMAN ? RANDOM : get_input("-g", args, "Who generates the seque", RANDOM);
|
||||||
|
bool human_player = player == HUMAN;
|
||||||
|
|
||||||
// Generate the sequence
|
// Generate the sequence
|
||||||
auto sequence = vector<int>(N);
|
auto sequence = vector<int>(N);
|
||||||
|
@ -41,7 +42,7 @@ int main(int argc, char* argv[]) {
|
||||||
if(col < 0 || col >= M) return 1;
|
if(col < 0 || col >= M) return 1;
|
||||||
|
|
||||||
// Human info
|
// Human info
|
||||||
if(player == HUMAN) {
|
if(human_player) {
|
||||||
cout << std::endl;
|
cout << std::endl;
|
||||||
cout << "Guesses are " << N << " space-separated numbers from 0 to " << M-1 << 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;
|
<< "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);
|
vector<int> guess(N);
|
||||||
Response response;
|
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
|
// Human playing
|
||||||
else if(player == HUMAN) {
|
if(human_player) {
|
||||||
cout << "Guess " << history.size() << " : ";
|
cout << "Guess " << history.size() << " : ";
|
||||||
for(int n = 0; n < N; n++)
|
for(int n = 0; n < N; n++)
|
||||||
cin >> guess[n];
|
cin >> guess[n];
|
||||||
|
@ -80,6 +71,16 @@ int main(int argc, char* argv[]) {
|
||||||
bot.learn(guess, response);
|
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)
|
if(learn)
|
||||||
bot.print();
|
bot.print();
|
||||||
history.push_back(guess);
|
history.push_back(guess);
|
||||||
|
@ -90,7 +91,7 @@ int main(int argc, char* argv[]) {
|
||||||
cout << std::endl;
|
cout << std::endl;
|
||||||
|
|
||||||
// Print game history
|
// Print game history
|
||||||
if(player == HUMAN)
|
if(human_player)
|
||||||
cout << "History\n";
|
cout << "History\n";
|
||||||
for(auto guess : history)
|
for(auto guess : history)
|
||||||
cout << format_guess_history(sequence, guess) << std::endl;
|
cout << format_guess_history(sequence, guess) << std::endl;
|
||||||
|
|
Loading…
Reference in a new issue