.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   Releases, Installers, Docs & Coding (http://forums.bots-united.com/forumdisplay.php?f=48)
-   -   POD-bot back into shape. (http://forums.bots-united.com/showthread.php?t=833)

Pierre-Marie Baty 02-04-2004 16:35

Re: POD-bot back into shape.
 
Quote:

Originally Posted by Whistler
...it's this:
if (angle >= 180)
angle -= 360 * (int)(angle / 360 + 0.5); // 0.5 is INSIDE the (int)(...)

If you do this then your code will behave wrong for large values of angle, do you know that ? 9_9 :)

The function will exit and the angle will still be overflown.

Whistler 02-04-2004 17:04

Re: POD-bot back into shape.
 
Anyway I have tested it with this little program and it's all ok:
Code:

  #include <stdio.h>
 
  float AngleNormalize(float angle)
  {
    if (angle >= 180)
            angle -= 360 * (int)(angle / 360 + 0.5);
    if (angle < -180)
            angle += 360 * (int)(-angle / 360 + 0.5);
    return angle;
  }
 
 
  main()
  {
    float a;
    float b;
    for (a = -2532.3; a < 3602.3; a += 0.1235)
    {
            b = AngleNormalize(a);
            if (b >= 180 || b < -180)
            {
          printf("your code is wrong !\n");
          return;
            }
    }
    printf("your code is right !\n");
  }

Also the asserts are never failed in YaPB. You can try playing YaPB for a few round and I'm pretty sure you'll find no angles are mess up. :)

SoUlFaThEr 02-04-2004 17:35

Re: POD-bot back into shape.
 
i got a thing here.....with a new waypoint done within these last 2 updates.....that does not show up on waypoints from before........

i cant even show you a demo cuz you dont have the map...........(PMB) (its cs_1337_assault)

the ct gets the hostages and then appears a message:
waypoint problem: no path found

and the bot cannot get out of this room......with his hostages........when he accidentaly does.....hes walking straight through a no hostage flag......

thinking it was a no hostage flag placement mistake of mine......i went through the routes he should take and did a wp delete flag on every single waypoint from the goal to the rescue waypoint.......and the error still occurs. 2 errors in one shot.......

i went into cs_assault..to see if it happens here and it runs perfectly......no clue man......and the PODERROR.txt...(now much smaller!) shows no error of any kind.

sPlOrYgOn 02-04-2004 17:36

Re: POD-bot back into shape.
 
both ways work just fine...
[edit]
of course this is about the angles..
[/edit]
[edit2]
Code:

#include <stdio.h>

float AngleNormalize(float angle)
{
        if (angle >= 180)
                angle -= 360 * (int)(angle / 360 + 0.5);
        if (angle < -180)
                angle += 360 * (int)(-angle / 360 + 0.5);
        return angle;
}

float angleNormalize(float angle)
{
        if (angle >= 180)
                angle -= 360 * ((int)(angle / 360) + 1);
        if (angle < -180)
                angle += 360 * ((int)(-angle / 360) + 1);
        return angle;
}

int main()
{
        float a = 180.0, b, c;
        int notsame = 0;
        for (a = -9999.9; a < 9999.9; a += 0.001)
        {
                b = AngleNormalize(a);
                c = angleNormalize(a);
                if (b != c)
                        notsame++;
        }
        if(notsame <= 0)
                printf("Some are not the same...\n");
        else
                printf("they all the same WOOT!\n");
        return(0);
}

[/edit2]

Pierre-Marie Baty 02-04-2004 17:47

Re: POD-bot back into shape.
 
@Whistler:

Nope ! it's NOT okay, because even if your resulting angles are in bounds, they are NOT ANYMORE modulo 360 versions of the original one !


it's as if you were doing
Code:

if ((angle < -180) || (angle >= 180))
  angle = RANDOM_FLOAT (-180, 180);

... with a bit of exxageration, I concede :)

Nevertheless your code is wrong, and I can prove it.
Instead of running your test program, rather run this one:
Code:

void main (void)
{
  float random_angle;
  float result_angle;
  int count = 0;
 
  while (1)
  {
          random_angle = RANDOM_FLOAT (-100000000, 100000000);
 
          result_angle = AngleNormalize (random_angle);
          if ((result_angle < -180) || (result_angle >= 180))
          {
                  printf ("ERROR! in=%f out=%f count=%d\n", random_angle, result_angle, count);
                  getchar ();
          }
 
          result_angle = AngleNormalize360 (random_angle);
          if ((result_angle < 0) || (result_angle >= 360))
          {
                  printf ("ERROR! in=%f out=%f count=%d\n", random_angle, result_angle, count);
                  getchar ();
          }
 
          count++;
  }
}

You will see that your code fails for large values of angle.

And NOT only this, but if you add a
Code:

        printf ("in=%f out=%f\n", random_angle, result_angle);
        getchar ();

for each angle that is tested, and compare the input and the output, you'll notice that the output is NOT a modulo 360 representative of the input. You have an error that goes increasing with larger values.

Believe me, I've tested it all thoroughly, thanks to you pointing me that bug, and I've found the right code. It goes like this:
Code:

float WrapAngle (float angle)
{
  // this function adds or substracts 360 enough times needed to the angle_to_wrap angle in
  // order to set it into the range -180/+180 and returns the resulting angle. Letting the
  // engine have a hand on angles that are outside these bounds may cause the game to freeze
  // by screwing up the engine math code.
 
  // check for wraparound of angle
  if (angle >= 180)
          angle -= 360 * abs (((int) angle + 180) / 360);
  if (angle < -180)
          angle += 360 * abs (((int) angle - 180) / 360);
 
  // needs a 2nd pass to check for floating part truncation (rounded 180)
  if (angle == 180.0)
          angle = -180;
 
  return (angle);
}
 
float WrapAngle360 (float angle)
{
  // this function adds or substracts 360 enough times needed to the angle_to_wrap angle in
  // order to set it into the range +0/+360 and returns the resulting angle Letting the
  // engine have a hand on angles that are outside these bounds may cause the game to freeze
  // by screwing up the engine math code.
 
  // check for wraparound of angle
  if (angle >= 360)
          angle -= 360 * abs ((int) angle / 360);
  if (angle < 0)
          angle += 360 * abs (((int) angle - 360) / 360);
 
  // needs a 2nd pass to check for floating part truncation (rounded 180)
  if (angle == 360.0)
          angle = 0;
 
  return (angle);
}

And if you think about it it's perfectly logical. The function asks itself, how many times can I add OR substract 360 to the current angle to have it in the bounds ? Then, taking the absolute of this value, it either adds (if value was initially inferior) OR substract (if value was initially superior) - hence the abs(), as many times 360 as needed and the resulting angle is GUARANTEED to be in bounds, and a modulo of 360.

The only check left to do is the floating point truncation (precision error) that would make the final angle land accurately on a rounded 180 (which would be just above the limit).

Pierre-Marie Baty 02-04-2004 17:54

Re: POD-bot back into shape.
 
@SoUlFaThEr, your problem IS a waypoint problem. It means that the bot can find a way to get TO the hostages, but it can't find a way BACK, because all the routes it could take are blocked with a FL_NOHOSTAGE flag. Try waypointing your map again, you'll see it works. I understand now why you said the bot was ignoring the FL_NOHOSTAGE flag before on this map, that was because the bot couldn't find ANY other way back. Double-check your waypoints again, and beware of one-way connections :)

SoUlFaThEr 02-04-2004 17:59

Re: POD-bot back into shape.
 
EDIT


MY BAD DUDE......i ran through it without seing one waypoint with a no connect........im sorry!!!!!!!!

ok i suck :) thats what happens when you dont sleep :)

Pierre-Marie Baty 02-04-2004 18:10

Re: POD-bot back into shape.
 
tsk tsk tsk, check them again. I *know* how the code works, and I tell you, your waypoints will STILL be saved even if all of them wear a FL_NOHOSTAGE flag. The checking routine doesn't check for this.

Isn't there simply a FL_NOHOSTAGE right at the exit of the room ?

Test them again. Trust me. Waypoint problem. :)

...

if I'm wrong I pay you a pack of beer and I ship it by air mail.



*edit* then no beer for Tim :D
hehehehehehehe

SoUlFaThEr 02-04-2004 18:16

Re: POD-bot back into shape.
 
damn and i was getting thirsty......i owe you some beer.....what you want?
Guiness?

Pierre-Marie Baty 02-04-2004 18:25

Re: POD-bot back into shape.
 
lol dude, any blonde will do :D

/me pops off a garette and waits for the beer... :P


All times are GMT +2. The time now is 13:02.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.