-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmartGuesser.cpp
More file actions
53 lines (49 loc) · 1.27 KB
/
Copy pathSmartGuesser.cpp
File metadata and controls
53 lines (49 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//
// Pgia
//
// Created by Jeme Jbareen on 4/28/19.
// Copyright © 2019 Jeme Jbareen. All rights reserved.
//
#include "SmartGuesser.hpp"
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
using std::string,std::to_string,std::vector;
string SmartGuesser::guess() {
int r = rand() % vec.size();
_lastGuess = vec[r];
return _lastGuess;
}
void SmartGuesser::learn(bullpgia::Latest_Guess s) {
vector<string> _BullsVec;
string str1=to_string(s._Bulls)+","+to_string(s._Pgia);
for(int i=0; i!= vec.size();i++) {
bullpgia::Latest_Guess ans = bullpgia::calculateBullAndPgia(_lastGuess, vec[i]);
string str=to_string(ans._Bulls)+","+to_string(ans._Pgia);
if(str1 == str)
_BullsVec.push_back(vec[i]);
}
vec.clear();
vec=_BullsVec;
_lastGuess=vec[0];
}
string SmartGuesser::Convert_Guess(int num){
string str = to_string(num);
int size = length - str.length();
for (int i=0; i<size; ++i){
str = "0" + str;
}
return str;
}
void SmartGuesser::startNewGame(uint len){
_lastGuess = "";
vec.clear();
length = len;
for (int i=0; i<pow(10.0,len); ++i){
vec.push_back(Convert_Guess(i));
}
Convert_Guess(length);
}