Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. int main(){
  2. /// write the code for the main here in order to test your functions
  3. set_random_seed();
  4. float length, num, total_game = 1000, total_attempt = 0, max=0;
  5. std::vector<int> worse;
  6. std::vector<double> time_of_each_length, average_attempt;
  7. double average;
  8. std::cout << "enter length of sequence and number of possible values:" << std::endl;
  9. std::cin >> length >> num;
  10. // for(int length = 1; length < 10; length++){
  11. total_attempt = 0;
  12. auto start1 = std::chrono::high_resolution_clock::now();
  13. if(length >= 6){
  14. total_game = 1;
  15. }
  16. for(int k=0; k < total_game; k++){
  17. std::cout << "game number: " << k << '\n';
  18. mm_solver solver;
  19. solver.init(length, num);
  20. mm_code_maker maker;
  21. maker.init(length, num);
  22. maker.generate_sequence();
  23. std::cout << "generate_sequence" << '\n';
  24. std::cout << "the sequence generated by the code maker was:" << std::endl;
  25. for(int i = 0; i < maker.sequence.size(); i++){
  26. std::cout << maker.sequence[i] << " ";
  27. }
  28. std::cout << std::endl;
  29. int black_hits=0, white_hits=0;
  30. int attempts_limit = 20;
  31. int attempts = 0;
  32. while((black_hits < length) && (attempts < attempts_limit)){
  33. std::vector<int> attempt;
  34. solver.create_attempt(attempt);
  35. maker.give_feedback(attempt, black_hits, white_hits);
  36. std::cout << "attempt number " << attempts << " : " <<std::endl;
  37. for(int i = 0; i < attempt.size(); i++){
  38. std::cout << attempt[i] << " ";
  39. }
  40. std::cout << std::endl;
  41. std::cout << "black pegs: " << black_hits << " " << " white pegs: " << white_hits << std::endl;
  42. solver.learn(attempt, black_hits, white_hits);
  43. attempts++;
  44. }
  45.  
  46. if(black_hits == length){
  47. std::cout << "the solver has found the sequence in " << attempts << " attempts" << std::endl;
  48. total_attempt = total_attempt+attempts;
  49. }
  50. else{
  51. std::cout << "after " << attempts << " attempts still no solution" << std::endl;
  52. }
  53. if(attempts > max){
  54. max = attempts;
  55. worse = maker.sequence;
  56. }
  57. }
  58. auto end1 = std::chrono::high_resolution_clock::now();
  59. std::chrono::duration<double> elapsed1 = end1 - start1;
  60. double time_taken = elapsed1.count();
  61. double average_time = time_taken/total_game;
  62. std::cout << "Elapsed time: "<< elapsed1.count() << " s\n";
  63. std::cout << "Average time " << average_time << '\n';
  64. time_of_each_length.push_back(average_time);
  65. average = total_attempt/total_game;
  66. std::cout << "average is " << average << '\n';
  67. average_attempt.push_back(average);
  68. std::cout << "worst attempts: " << max << '\n';
  69. std::cout << "out of " << total_game << '\n';
  70. print_vector(worse);
  71. // }
  72. std::cout << "time" << '\n';
  73. print_vector_double(time_of_each_length);
  74. std::cout << "attempt" << '\n';
  75. print_vector_double(average_attempt);
  76. return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement