#include <chrono>
#include "light.hpp"
#include <unistd.h>
#include <thread>
using namespace std; 


light::light():
  finalResult           (0),
  winner                (0),
  maxtime               (5000),
  globalEnding          (false)
{
    opt = new paras();
    opt->init_paras();
}

light::~light() {
    for (int i = 0; i < solvers.size(); i++) delete(solvers[i]);
    solvers.clear(true);
}

void light::arg_parse(int argc, char **argv) {
    for (int i = 1; i < argc; i++) {
        char *arg = argv[i];
        if (arg[0] != '-' || arg[1] != '-') {
            filename = arg; continue;
        }
        int l = strlen(arg), pos = 0;
        for (int i = 2; i < l; i++)
            if (arg[i] == '=') pos = i;
        if (!pos) continue;
        char name[50];
        strncpy(name, arg + 2, pos - 2);
        name[pos - 2] = '\0';
        char* val = arg + pos + 1;
        if (opt->map_int.count(name)) opt->set_para(name, atoi(val));
        opt->set_para(name, atof(val));
    }
    opt->sync_paras();
    opt->print_change();
    printf("c filename: %s\n", filename);
}