Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main(){
- /// write the code for the main here in order to test your functions
- set_random_seed();
- float length, num, total_game = 1000, total_attempt = 0, max=0;
- std::vector<int> worse;
- std::vector<double> time_of_each_length, average_attempt;
- double average;
- std::cout << "enter length of sequence and number of possible values:" << std::endl;
- std::cin >> length >> num;
- // for(int length = 1; length < 10; length++){
- total_attempt = 0;
- auto start1 = std::chrono::high_resolution_clock::now();
- if(length >= 6){
- total_game = 1;
- }
- for(int k=0; k < total_game; k++){
- std::cout << "game number: " << k << '\n';
- mm_solver solver;
- solver.init(length, num);
- mm_code_maker maker;
- maker.init(length, num);
- maker.generate_sequence();
- std::cout << "generate_sequence" << '\n';
- std::cout << "the sequence generated by the code maker was:" << std::endl;
- for(int i = 0; i < maker.sequence.size(); i++){
- std::cout << maker.sequence[i] << " ";
- }
- std::cout << std::endl;
- int black_hits=0, white_hits=0;
- int attempts_limit = 20;
- int attempts = 0;
- while((black_hits < length) && (attempts < attempts_limit)){
- std::vector<int> attempt;
- solver.create_attempt(attempt);
- maker.give_feedback(attempt, black_hits, white_hits);
- std::cout << "attempt number " << attempts << " : " <<std::endl;
- for(int i = 0; i < attempt.size(); i++){
- std::cout << attempt[i] << " ";
- }
- std::cout << std::endl;
- std::cout << "black pegs: " << black_hits << " " << " white pegs: " << white_hits << std::endl;
- solver.learn(attempt, black_hits, white_hits);
- attempts++;
- }
- if(black_hits == length){
- std::cout << "the solver has found the sequence in " << attempts << " attempts" << std::endl;
- total_attempt = total_attempt+attempts;
- }
- else{
- std::cout << "after " << attempts << " attempts still no solution" << std::endl;
- }
- if(attempts > max){
- max = attempts;
- worse = maker.sequence;
- }
- }
- auto end1 = std::chrono::high_resolution_clock::now();
- std::chrono::duration<double> elapsed1 = end1 - start1;
- double time_taken = elapsed1.count();
- double average_time = time_taken/total_game;
- std::cout << "Elapsed time: "<< elapsed1.count() << " s\n";
- std::cout << "Average time " << average_time << '\n';
- time_of_each_length.push_back(average_time);
- average = total_attempt/total_game;
- std::cout << "average is " << average << '\n';
- average_attempt.push_back(average);
- std::cout << "worst attempts: " << max << '\n';
- std::cout << "out of " << total_game << '\n';
- print_vector(worse);
- // }
- std::cout << "time" << '\n';
- print_vector_double(time_of_each_length);
- std::cout << "attempt" << '\n';
- print_vector_double(average_attempt);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement