1

Topic: Neverball Time --- ANYONE!!!!!!!!!

I need to know how to measure time correctly in Neverball for an AI.

I have tried most things but here's what I am doing currently;
--- I call the AI from main;

t0 = SDL_GetTicks();
   
    while (loop())
    {
        if ((t1 = SDL_GetTicks()) > t0)
        {
            ball_AI_Controller(  ); // THIS IS MY AI.
            st_timer(0.001f * (t1 - t0));
            t0 = t1;
            ...........................................

--- I get time for the AI from "game_common.c";

void lockstep_run(struct lockstep *ls, float dt)
{
    ls->at += dt * ls->ts;
    int k=0;
    while (ls->at >= ls->dt)
    {
        ls->step(ls->dt);
        ls->at -= ls->dt;
        if(k==0){savetimeremaining++; // HERE IS A COUNTER THAT ADDS ONE EACH TIME THE PHYSICS UPDATES.           
        }
        k++;
    }
   
}
.........

And I take that time for my AI and it is supposed to call the files with learned tilts in them at the same time every time, and thus reproduce a path.  It does not do this and once runs are any longer than 20s or so the program diverges and cannot learn as paths are not repeated.

Has anyone tinkered with Time in Neverball ?
Do you know how I should be taking Time?
The method above seems to be heavily dependent on framerate and although the physics is supposed to update at 90Hz it crawls on some computers and this completely ruins my AI.

Should I be calling my AI from main?
Am I correctly getting the 90Hz rate?
Why doesn't it work?
And why does it work differently on different computers?

Any help would be great!!

I can post more code or answer any questions you ask...

Post's attachments

Attachment icon linkforVideo.txt 32 b, 7 downloads since 2017-07-06 

2

Re: Neverball Time --- ANYONE!!!!!!!!!

I remain doubtful that your issue has to do with timing. It's not that difficult to get right.

What you should do first and foremost is prove whether the simulation is deterministic in itself. It sounds like a lot can go wrong in your implicitly-described setup, so you should reduce the problem surface by removing the extra steps. Simply write out the tilt values from the game in one run, then read them back using your method in another. If the results between the first run and the second run are different (on the same machine, this is an important detail), then you might have a timing issue. If the results are identical, the issue lies with your AI "file calling" code.

3

Re: Neverball Time --- ANYONE!!!!!!!!!

parasti wrote:

I remain doubtful that your issue has to do with timing. It's not that difficult to get right.

What you should do first and foremost is prove whether the simulation is deterministic in itself. It sounds like a lot can go wrong in your implicitly-described setup, so you should reduce the problem surface by removing the extra steps. Simply write out the tilt values from the game in one run, then read them back using your method in another. If the results between the first run and the second run are different (on the same machine, this is an important detail), then you might have a timing issue. If the results are identical, the issue lies with your AI "file calling" code.



To be honest I wish it were a problem in my code.
It gives small changes that cause big path differences.

I am very very close to giving up on this one.

here is the code that reads the tilt from logfiles;

if(TOTALTIME !=0 ){    // this will and should fail for states yet to be done
        FILE *fp0;
        char str0[400];
        fp0 = fopen(usefull_cated_string , "r");
        if(fp0 != NULL)
        {
            fgets (str0, sizeof str0, fp0);
            sscanf(str0, "%d %d %f %f %f %f %d %d %f %s",
            &take_T, &take_opts, &take_XTilt,  &take_ZTilt, &take_X, &take_Z, &take_Coins,  &take_MxCoins, &take_Reward, take_runID);
            fclose(fp0);
           
        }else{
           
        }
    }

And this runs for each state up to the state being explored, which tries new tilts.

I don't know where these errors come from and I am losing hope.


I also include my entire AI code in the hope that someone anybody can see an error in the timing. I doubt that anyone will even try, but here it is any way and I can answer any questions that you have.

Post's attachments

Attachment icon AI_code.txt 27.04 kb, 7 downloads since 2017-07-10 

4

Re: Neverball Time --- ANYONE!!!!!!!!!

I don't really know anything about AI, so this code is incomprehensible to me. Nearly all of your variables are global and their declarations and initializations are missing from the text file, so it is difficult to tell what is what.

Can I assume that take_T is an integer that holds the tilt time? Neverball keeps time as a float, so I assume this is not Neverball time? Or is this a frame count? The Neverball time unit is seconds, not frames. Also, any integer to float conversions are bound to introduce inaccuracies, so I would recommend using Neverball time without conversion.

It also seems that take_T is actually never used, so how would you even confirm that the tilt values are being applied at the correct time (or frame)?

5 (edited by Computron59 2017-07-11 17:01:56)

Re: Neverball Time --- ANYONE!!!!!!!!!

parasti wrote:

I don't really know anything about AI, so this code is incomprehensible to me. Nearly all of your variables are global and their declarations and initializations are missing from the text file, so it is difficult to tell what is what.

Can I assume that take_T is an integer that holds the tilt time? Neverball keeps time as a float, so I assume this is not Neverball time? Or is this a frame count? The Neverball time unit is seconds, not frames. Also, any integer to float conversions are bound to introduce inaccuracies, so I would recommend using Neverball time without conversion.

It also seems that take_T is actually never used, so how would you even confirm that the tilt values are being applied at the correct time (or frame)?

Hello!!

I have cleaned the code so that all it does is read tilts from a text file. I hope that it is easier to understand.

Maddeningly it fails.

Why can't I read tilt from a file?

About the T, that was an int I increased each step, now it is replaced by  exploredState_Iterator .

I also include the tilt file used as input.

Please please help.


The file is only 180 lines of fairly clean code, how is it possible that I keep messing this up?

here is the method in game_common.c that  i used to call the AI;

void lockstep_run(struct lockstep *ls, float dt)
{
    ls->at += dt * ls->ts;

    clock_gettime(CLOCK_MONOTONIC_RAW, &namantime);
    c_time = namantime.tv_sec + namantime.tv_nsec/1000000000.00d;
    AI_Controller_Loop_Manager();

    while (ls->at >= ls->dt)
    {
        ls->step(ls->dt);
        ls->at -= ls->dt;
    }
}

namantime  is just the name for my time.


I am losing hope here  ...

Post's attachments

Attachment icon AI_code_neater.txt 4.57 kb, 5 downloads since 2017-07-11 

Attachment icon tilts.txt 3.04 kb, 5 downloads since 2017-07-11 

6

Re: Neverball Time --- ANYONE!!!!!!!!!

Well, without even looking at the rest of your code, I can see two potential issues: you're calling the AI entry point at the wrong time and you're retrieving time from the system instead of from the Neverball simulation.

As I said earlier, the authoritative simulation happens in game_server.c. It's a function called game_server_iter.

game_server_iter is invoked by the lockstep_run function via the ls->step() callback. This happens in a while loop, but you are calling your AI function before the loop. This means that the AI does not advance 1:1 with the simulation. You should probably do one of these things: 1) either move your AI function to be inside the loop or 2) call your AI from game_server_iter.

Secondly, the only authoritative time in the simulation is the ls->dt value (or dt in game_server_iter). DT stands for delta time, which is the time since the previous simulation step. For monotonically increasing time do something like

static void game_server_iter(float dt) {
    // ...
    c_time += dt;

It's not exactly accurate, but it's more relevant to the simulation than whatever clock_gettime is returning.

7

Re: Neverball Time --- ANYONE!!!!!!!!!

parasti wrote:

Well, without even looking at the rest of your code, I can see two potential issues: you're calling the AI entry point at the wrong time and you're retrieving time from the system instead of from the Neverball simulation.

As I said earlier, the authoritative simulation happens in game_server.c. It's a function called game_server_iter.

game_server_iter is invoked by the lockstep_run function via the ls->step() callback. This happens in a while loop, but you are calling your AI function before the loop. This means that the AI does not advance 1:1 with the simulation. You should probably do one of these things: 1) either move your AI function to be inside the loop or 2) call your AI from game_server_iter.

Secondly, the only authoritative time in the simulation is the ls->dt value (or dt in game_server_iter). DT stands for delta time, which is the time since the previous simulation step. For monotonically increasing time do something like

static void game_server_iter(float dt) {
    // ...
    c_time += dt;

It's not exactly accurate, but it's more relevant to the simulation than whatever clock_gettime is returning.


Is so obvious now.

Thank you.

8

Re: Neverball Time --- ANYONE!!!!!!!!!

Hello!!

Thanks to your tip the program is now working!!!!

Is there a way to overwrite the X and Z and move the ball to a given coordinate?

Where are coin positions and goal positions stored?

What is the gravity acceleration magnitude when the ball is
falling?

Thanks again for telling me how to take time in Neverball.

Expect more videos.