Added guess response

This commit is contained in:
Matúš Púll 2024-11-02 16:22:05 +01:00
parent a5fab72e1a
commit 2b0a13f6db
2 changed files with 54 additions and 3 deletions

View file

@ -1,13 +1,17 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <vector>
#include "solver.hpp"
#include "gen.hpp"
using std::cout; using std::cout;
using std::cin; using std::cin;
using std::string; using std::string;
using std::vector;
int main(void) { int main(void) {
// Taking problem parameters // Take game parameters
cout << "Length of sequence : "; cout << "Length of sequence : ";
int N; cin >> N; int N; cin >> N;
@ -17,10 +21,20 @@ int main(void) {
cout << "Who plays [human/bot] : "; cout << "Who plays [human/bot] : ";
string player; cin >> player; string player; cin >> player;
string opponent = "random"; string gen = "random";
if(player == "bot") { if(player == "bot") {
cout << "Who generates the sequence [random/human]: "; cout << "Who generates the sequence [random/human]: ";
cin >> opponent; cin >> gen;
}
// Generate the sequence
auto sequence = vector<int>(N, 0);
if(gen == "random")
sequence = generate(N, M);
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];
} }
return 0; return 0;

37
validate.hpp Normal file
View file

@ -0,0 +1,37 @@
#pragma once
#include <vector>
using std::vector;
vector<int> validate(vector<int> sequence, vector<int> guess) {
int S = sequence.size();
// Return values
int r_correct = 0;
int r_somewhere = 0;
// Find and remove correct values
for(int i = 0; i < S; i++) {
if(sequence[i] == guess[i]) {
r_correct++;
sequence.erase(sequence.begin()+i);
guess.erase(guess.begin()+i);
i--;
S--;
}
}
// Find values that are there somewhere
for(int col : guess) {
for(int i = 0; i < S; i++) {
if(sequence[i] == col) {
r_somewhere++;
sequence.erase(sequence.begin()+i);
S--;
break;
}
}
}
return {r_somewhere, r_correct};
}