Game skeleton is working
This commit is contained in:
parent
526ef69c4a
commit
e403157b65
1 changed files with 50 additions and 8 deletions
58
main.cpp
58
main.cpp
|
@ -3,14 +3,19 @@
|
|||
#include <vector>
|
||||
#include "solver.hpp"
|
||||
#include "gen.hpp"
|
||||
#include "validate.hpp"
|
||||
|
||||
using std::cout;
|
||||
using std::cin;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
int main(void) {
|
||||
// To avoid typos
|
||||
#define BOT "bot"
|
||||
#define HUMAN "human"
|
||||
#define RANDOM "random"
|
||||
|
||||
int main(void) {
|
||||
// Take game parameters
|
||||
cout << "Length of sequence : ";
|
||||
int N; cin >> N;
|
||||
|
@ -18,24 +23,61 @@ int main(void) {
|
|||
cout << "Number of colors : ";
|
||||
int M; cin >> M;
|
||||
|
||||
cout << "Who plays [human/bot] : ";
|
||||
cout << "Who plays [" << HUMAN << "/" << BOT << "] : ";
|
||||
string player; cin >> player;
|
||||
|
||||
string gen = "random";
|
||||
if(player == "bot") {
|
||||
cout << "Who generates the sequence [random/human]: ";
|
||||
string gen = RANDOM;
|
||||
if(player == BOT) {
|
||||
cout << "Who generates the sequence [" << HUMAN << "/" << RANDOM << "]: ";
|
||||
cin >> gen;
|
||||
}
|
||||
|
||||
// Generate the sequence
|
||||
auto sequence = vector<int>(N, 0);
|
||||
if(gen == "random")
|
||||
auto sequence = vector<int>(N);
|
||||
if(gen == RANDOM)
|
||||
sequence = generate(N, M);
|
||||
else if(gen == "human") {
|
||||
else if(gen == HUMAN) {
|
||||
cout << "Enter " << N << " space-separated colors from 0 to " << M-1 << std::endl;
|
||||
for(int n = 0; n < N; n++)
|
||||
cin >> sequence[n];
|
||||
}
|
||||
|
||||
// Init solver
|
||||
Solver bot(N, M);
|
||||
|
||||
// Guessing
|
||||
vector<vector<int>> history = {};
|
||||
for(int guesses = 0; guesses < 10; guesses++) {
|
||||
vector<int> guess(N), response;
|
||||
|
||||
// Bot playing
|
||||
if(player == BOT) {
|
||||
guess = bot.guess();
|
||||
cout << format_guess(guess);
|
||||
|
||||
response = validate(sequence, guess);
|
||||
cout << format_response(response);
|
||||
bot.learn(guess, response);
|
||||
}
|
||||
|
||||
// Human playing
|
||||
else if(player == HUMAN) {
|
||||
cout << "Guess " << N << " space-separated colors from 0 to " << M-1 << std::endl;
|
||||
for(int n = 0; n < N; n++)
|
||||
cin >> guess[n];
|
||||
|
||||
response = validate(sequence, guess);
|
||||
cout << format_response(response);
|
||||
}
|
||||
|
||||
history.push_back(guess);
|
||||
if(response[1] == N) break;
|
||||
}
|
||||
|
||||
// Print game statistics
|
||||
cout << "How well did the game go\n";
|
||||
for(auto guess : history)
|
||||
cout << format_guess_history(sequence, guess) << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue