Hi,
I wonder how I can tell my program (in C++) to continue calculating until the allowed 1s is over. It does a short calculation, checks the time, and if it thinks that there is enough time left for another calculation round, it goes for it.
Unfortunately I don't know how to implement this. Here's what I did (it's basically the starter-kit code plus something that doesn't seem to work), and this causes my code to be suspended!
clock_t start, stop; // from time.h
double t;
double MAXTIME 0.9;
int move;
int MakeMove(const Map& map)
{
do
{
// do some fancy calculations
stop = clock();
t = (double) (stop-start)/CLOCKS_PER_SEC;
} while (t < MAXTIME);
return move;
}
int main()
{
while (true)
{
start = clock();
Map map;
Map::MakeMove(MakeMove(map));
}
return 0;
}
A) The first problem (at least on my PC) is that 'Map map' takes already more than one second by itself
Strange, because then not even the starter packages would work
B) If I test my code on the java engine as player B, the stopwatch seems to start for player B already when player A reads its move, although player B can read its move only once A is done.
Can you please teach me how to use any time-measuring algorithm correctly with your judge?
Thanks a lot