Author Topic: Rounding  (Read 4786 times)

Offline abyaly

  • Bot Destroyer
  • ***
  • Posts: 363
    • View Profile
Rounding
« on: July 16, 2007, 06:02:16 PM »
is the rounding performed when you store a value, or are all numbers on the stack integers?
Lancre operated on the feudal system, which was to say, everyone feuded all
the time and handed on the fight to their descendants.
        -- (Terry Pratchett, Carpe Jugulum)

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Rounding
« Reply #1 on: July 16, 2007, 09:08:52 PM »
All numbers on the stack are integers, but have more bits than the robot memory.  So you shouldn't have to worry about overflow.

5 3 div would result in 1 I believe (though definitely double check that).

Offline abyaly

  • Bot Destroyer
  • ***
  • Posts: 363
    • View Profile
Rounding
« Reply #2 on: July 17, 2007, 03:57:42 PM »
doing trig this way will be interesting
Lancre operated on the feudal system, which was to say, everyone feuded all
the time and handed on the fight to their descendants.
        -- (Terry Pratchett, Carpe Jugulum)

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Rounding
« Reply #3 on: July 17, 2007, 10:57:54 PM »
When I first joined I was able to make an approximating function that took bot angles and found the sine of them (expressed in -1000 to 1000 I think).

Another alternative is to just use vectors and use the dot and cross products for sine and cosine where you need them.

Offline abyaly

  • Bot Destroyer
  • ***
  • Posts: 363
    • View Profile
Rounding
« Reply #4 on: July 18, 2007, 04:08:00 PM »
I'm trying to convert velocity vectors from the bot's frame of reference into the standard basis. (or convert position -into- the bot's frame of reference; it amounts to the same thing)
Lancre operated on the feudal system, which was to say, everyone feuded all
the time and handed on the fight to their descendants.
        -- (Terry Pratchett, Carpe Jugulum)

Offline abyaly

  • Bot Destroyer
  • ***
  • Posts: 363
    • View Profile
Rounding
« Reply #5 on: July 18, 2007, 05:03:46 PM »
Ok, something is going horribly wrong.
For example:

Code: [Select]
*.refxpos *.xpos sub *.refveldx mult
*.refypos *.ypos sub *.refveldn mult add 2 mult .beta store
Which translates into
2 * [ (refxpos - xpos)*refveldx + (refypos - ypos)*refveldn]
Except, that isnt what it does -.-
? .refxpos
 689-> 1963
? .xpos
 219-> 1736
? .refveldx
 697-> 25
? .refypos
 690-> 2629
? .ypos
 217-> 1835
? .refveldn
 698->-14
? 51
 51->-10958

2 * [ (1963 - 1763)*25 + (2629 - 1835)*(-14) ] = 2 * [ 200*25 - 794*14]
= 2 * [5000 - 11116] = 2 * -6116 = -12232 != -10958

I have no idea how this is happening. I think I'm losing hair.
Lancre operated on the feudal system, which was to say, everyone feuded all
the time and handed on the fight to their descendants.
        -- (Terry Pratchett, Carpe Jugulum)

Offline Trafalgar

  • Bot Destroyer
  • ***
  • Posts: 122
    • View Profile
Rounding
« Reply #6 on: July 18, 2007, 06:07:44 PM »
Quote from: abyaly
Ok, something is going horribly wrong.
For example:

You made one mistake (you subtracted 1763 instead of 1736), but I don't think that's what's causing this. (You'd get (1963-1736)*25 is 5675. 5675-11116 is -5441, 2* which is -10882.)

What's really going on, if you're checking the variables in the console, is that those sysvars are changed after the DNA is executed, so, the value in .beta was calculated using data that is one cycle older than the data you are seeing in the console.

This is why Guardian's .pyt source has a bunch of commented-out vars and commented out routines to write them, named things like sxRec, velsxRec, etc. It used to have ones for just about every ref* var there was (to test why friendly checks were screwing up).

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Rounding
« Reply #7 on: July 18, 2007, 10:40:15 PM »
Maybe I should write a small standalone stack virtual machine.  Something like irb for ruby.  Just so people can play with math and see how it works.

Offline googlyeyesultra

  • Bot Destroyer
  • ***
  • Posts: 109
    • View Profile
Rounding
« Reply #8 on: July 19, 2007, 12:01:55 AM »
Just edit the console so that we can run math commands, like 30 50 add would output 80. Would also be nice for debugging a bot, since we could do it in the game.
« Last Edit: July 19, 2007, 12:03:15 AM by googlyeyesultra »

Offline abyaly

  • Bot Destroyer
  • ***
  • Posts: 363
    • View Profile
Rounding
« Reply #9 on: July 19, 2007, 12:11:44 AM »
The biggest challenge for me in DB is making the things that work on paper also work in notepad.
Lancre operated on the feudal system, which was to say, everyone feuded all
the time and handed on the fight to their descendants.
        -- (Terry Pratchett, Carpe Jugulum)

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Rounding
« Reply #10 on: July 19, 2007, 12:43:58 AM »
Quote from: abyaly
The biggest challenge for me in DB is making the things that work on paper also work in notepad.

Why do you think it's been so long since I authored a bot