#ifndef SCRIPTS_H_INCLUDED
#define SCRIPTS_H_INCLUDED

#include <vector>

#include "analysis.h"

using namespace std;

void optimal_proba(int n_initial, int n_final, std::default_random_engine& randomizer, double p_init=0.05, double p_final=0.5, double p_step=0.01) {
    for(int n=n_initial; n<n_final; n++) {
        vector<double> avg_list;
        vector<double> probas;

        auto start = start_chrono();
        for(double p=p_init; p<p_final; p+=p_step) {
            EA algo(p, 1, 1, randomizer);
            Statistic stat = avg_calls(algo, MasterMind(n, n, randomizer));
            double avg = stat.average;
            avg_list.push_back(avg);
            probas.push_back(p);
        }
        auto stop = stop_chrono();
        int elapsed_milliseconds = interval_chrono(start, stop);

        int min_ind = 0;
        for(int i=1; i<avg_list.size(); i++)
            if(avg_list[min_ind] > avg_list[i])
                min_ind = i;
        double p_best = probas[min_ind];
        cout << "n=" << n << ": " << p_best << " in " << elapsed_milliseconds/1000. << " seconds " << "(" << 100*floor((p_final-p_init)/p_step) << " problems)" << endl;
    }
}

#endif // SCRIPTS_H_INCLUDED
