Author Topic: Make position a Single, not a Long  (Read 6645 times)

Offline Sprotiel

  • Bot Destroyer
  • ***
  • Posts: 135
    • View Profile
Make position a Single, not a Long
« on: May 22, 2005, 06:08:32 PM »
I don't see any reason why robots' coordinates should be integers. In the current code, there's a lot of back and forth conversions between Longs and Singles. Eliminating those should reduce the probability of errors.

Offline PurpleYouko

  • Bot God
  • *****
  • Posts: 2556
    • View Profile
Make position a Single, not a Long
« Reply #1 on: May 22, 2005, 07:43:27 PM »
Yes a very good point but you are heading in the wrong direction.

What we need to do is make everything long.

Why?

Because almost every crash in DB is due to some variable or other getting too big for a single or integer to cope with.

Robot position is a perfect case of this. At the moment the robot's readback in the memory array is a single length integer which means it has a maximum value of 32000 or so.
You will quickly notice when you run larger sims that this doesn't even begin to cut is as far as reading back realistic values. The largest present size has a Y coordinate maximum of 72000 and the X is even bigger. It used to crash immediately when we went above size 4 until Num "fixed" it by making it impossible for Xpos and Ypos to be greater than 32000.
This fixed the crash issue but it make the robot's coordinate system completely useless above size 4. The only real fix is going to be to port all variables (including memory positions) into longs. In modern windows applications this could even make the program run faster since windows is a 32 bit environment these days.
« Last Edit: May 22, 2005, 07:44:39 PM by PurpleYouko »
There are 10 kinds of people in the world
Those who understand binary.
and those who don't

:D PY :D

Offline Sprotiel

  • Bot Destroyer
  • ***
  • Posts: 135
    • View Profile
Make position a Single, not a Long
« Reply #2 on: May 22, 2005, 08:46:36 PM »
What do you mean by 'too big for a single to cope with'? Larger than 3.402823E38?? :blink:

Concerning the crashes, I suspect what happened was the following: you tried to fit x^2 into a Long with x>32768 by writing
Code: [Select]
Dim d As Long
d=Sqr(x^2+y^2)

Concerning the robots, I don't see why their CPU needs to work with anything larger than an integer.

One more thing: I don't see the connection between the robots' memory and their position. They don't know their (x,y) coordinates nor should they.
« Last Edit: May 22, 2005, 08:48:55 PM by Sprotiel »

Offline Carlo

  • Bot Destroyer
  • ***
  • Posts: 122
    • View Profile
Make position a Single, not a Long
« Reply #3 on: May 23, 2005, 04:34:03 AM »
Quote
What do you mean by 'too big for a single to cope with'? Larger than 3.402823E38?? :blink:

 :lol:

But don't you think that singles (that means single precision floating point) could slow down calculations? Maybe I'm wrong... I have simply no idea of the power of actual computers.

Quote
One more thing: I don't see the connection between the robots' memory and their position. They don't know their (x,y) coordinates nor should they

I think they know them - PY or Numsgil added this feature. Initially I thought it was very stupid: everything was designed to give organisms only relative views on the environment. Well, I'm a bit less fundamentalist about that now. Most animals are able to orientate in the environment, and this is an important feature. Obviously, they do not have a GPS in their head, but, to some extent, it is like they do. But developing such a feature is probably impossible in the DarwinBots universe, not only because organisms are very simple, but also because of the nature of the DarwinBots environment, so poor of landmarks and allowing so limited senses.
So, maybe, it is not so bad that robots know their approximate position.

Offline PurpleYouko

  • Bot God
  • *****
  • Posts: 2556
    • View Profile
Make position a Single, not a Long
« Reply #4 on: May 23, 2005, 09:19:35 AM »
Quote
What do you mean by 'too big for a single to cope with'? Larger than 3.402823E38??  

Concerning the crashes, I suspect what happened was the following: you tried to fit x^2 into a Long with x>32768 by writing

I don't know where you got that idea from.
In VB, the largest number that can be held in a single precision floating point variable or an integer is 32767. If you so much as add 1 to it then the program will return an overflow error and crash.

Just try running the following code in VB to see my point.
make a new form and place a command button on it. In the code for the button enter the following code
Code: [Select]
Private Sub Command1_Click()
Dim count As Integer
While count < 40000
  Print count
  count = count + 1
Wend
End Sub
Run the program press the button and wait for the error message.
Debug the program and hold the cursor over the variable "count"
The value displayed will be 32767. No more and no less.
This is the largest number that either a single or an integer will hold.
« Last Edit: May 23, 2005, 09:26:54 AM by PurpleYouko »
There are 10 kinds of people in the world
Those who understand binary.
and those who don't

:D PY :D

Offline PurpleYouko

  • Bot God
  • *****
  • Posts: 2556
    • View Profile
Make position a Single, not a Long
« Reply #5 on: May 23, 2005, 09:25:22 AM »
Quote
I think they know them - PY or Numsgil added this feature. Initially I thought it was very stupid: everything was designed to give organisms only relative views on the environment. Well, I'm a bit less fundamentalist about that now. Most animals are able to orientate in the environment, and this is an important feature. Obviously, they do not have a GPS in their head, but, to some extent, it is like they do. But developing such a feature is probably impossible in the DarwinBots universe, not only because organisms are very simple, but also because of the nature of the DarwinBots environment, so poor of landmarks and allowing so limited senses.
So, maybe, it is not so bad that robots know their approximate position.

I added the xpos, ypos and depth features for V2.15 pond mode about a year and a half ago.
The feature enabled us to explore whole new behavioural patterns including territoriality and ant-bots that return home to feed the queen.
In pond mode, the depth control (actually the same memory location as ypos) allows for bouyancy to control exact depth in the water column. Again this allows for organisms to sink during the day time and rise to the surface at night. Unfortunately very few people ever seem to use pond mode even though it provides one of the very few areas where it is possible to have diverse environments.
There are 10 kinds of people in the world
Those who understand binary.
and those who don't

:D PY :D

Offline Anonomous Guest Person

  • Bot Builder
  • **
  • Posts: 85
    • View Profile
Make position a Single, not a Long
« Reply #6 on: May 23, 2005, 10:08:38 AM »
xpos and ypos are both programmable as a single gene. Not very cost efficient, but not all bots need such a gene.

It might also, as time goes on, become inaccurate, but who knows?

cond
start
  25 .veldx addstore
  26 .velsx addstore
stop

The only difference is that it's relative to it's starting position.
Which, for antbots, is good, because the queen can pass it along to it's children, and then they simply go back to 0,0.

Hence, xpos and ypos are practically useless. Even if you wanted to make bots communicate the location of food, they'd say where the food is relatively rather then based on their oppinion where the center of the world is.

And as time goes on, it'd become (realistically) inaccurate. requiring antbots to search for their queen, and reestablish where they are based on her being the center of the world. (Which would be loads more amazing if xpos and ypos were removed.)

So, simply put, xpos and ypos aren't actually needed to make a location system, assuming you're creative enough. (And if you want it for evolution, then I remind you that evolution rarely creates anything good, and this isn't exactly helped by all the functional memory locations. It'd be like making a random word generator, and running it until we get something good; except instead of 26 letters, we'd have 260.)

Offline PurpleYouko

  • Bot God
  • *****
  • Posts: 2556
    • View Profile
Make position a Single, not a Long
« Reply #7 on: May 23, 2005, 11:11:47 AM »
I don't see how the gene that you showed could do this.

veldx and velsx only tell the bot how fast it is currently travelling in its own sx and dx vectors. Those vectors are directly related to its current aim angle so they would be utterly useless as cumulative distance counters, as would vel, or velup.

If a robot is travelling to the right at a speed of 20 with no up or down movement then vel and velup would be 20 while both veldx and velsx would return zero

If the same robot were travelling straight up with no left or right movement then vel, velup, velsx and veldx would return exactly the same values as before.

In fact any robot travelling at a speed of 20 in any direction would return the same numbers to all its "vel" sysvars.

In other words a robot can only know its rate of movement relative to its current direction of travel. It has absolutely no way to tell anything at all relative to a specific location unless it has xpos and ypos sysvars. It can't count how far it has travelled along the x axis or y axis because it can't tell how far it has travelled due to having no direct reference to either of them.

To make your example work the robot would need to use its direction and rate of travel to calculate x and y vectors using trigonometry along with veldx, and velup. Robots do not have trig capabilities since that is even more unrealistic than having direct xpos and ypos knowledge.
Even if the robots could count how far they have travelled along x and y coordinates, they would probably soon hit the 32767 size limit of the memory locations and so completely lose themselves.

Real organisms such as ants use sight to align themselves with specific landmarks. Experiments in the dessert have proven this. DB has no landmarks so the xpos, ypos system just makes it work as if it did have.
There are 10 kinds of people in the world
Those who understand binary.
and those who don't

:D PY :D

Offline Sprotiel

  • Bot Destroyer
  • ***
  • Posts: 135
    • View Profile
Make position a Single, not a Long
« Reply #8 on: May 23, 2005, 11:46:25 AM »
Quote
In VB, the largest number that can be held in a single precision floating point variable is 32767.
:blink:  :blink:

Please try
Code: [Select]
Private Sub Command1_Click()
Dim count As Single
While count < 400000000#
 Print count
 count = count + 10000
Wend
End Sub

Offline PurpleYouko

  • Bot God
  • *****
  • Posts: 2556
    • View Profile
Make position a Single, not a Long
« Reply #9 on: May 23, 2005, 12:11:46 PM »
OK so it would appear that I was a little remis in assuming that singles worked the same way as integers. From this example they obviously don't. They go negative pretty well too.

Just goes to show that I don't know as much as I think I do sometimes.  :redface:

But the problem still remains in many places that the program has a real tendency to crash when singles are used. The crashes mysteriously go away when the variables are redefined as longs. I am pretty sure this isn't because of numbers in vast excess of 32000 as in many cases the actual number being stored into the variable can be read directly from the program in debug mode. It is often only around 40,000.

The main problem though is that large numbers of variables in the program are actually integers and these definitely can't hold more than 32767. Changing them into singles would result in things like fractions being stored into the robot's memory locations. Maybe some kind of long integer could be used.

I don't think VB supports "long integer" as a variable type

Well whadya know?

A quick look through the help files tells me that "Long" is actually an integer variable anyway. It is the same thing as "Long Integer"
That is a little counter intuitive I would say.

Still looks to me as if all the robot memory locations need to be upgraded to longs though. This will eliminate SOOO many routines that exist solely to limit values that are saved to memory, to 32000
There are 10 kinds of people in the world
Those who understand binary.
and those who don't

:D PY :D

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Bot God
  • *****
  • Posts: 4483
    • View Profile
Make position a Single, not a Long
« Reply #10 on: May 23, 2005, 07:35:16 PM »
Quote
They don't know their (x,y) coordinates nor should they.

Like hell they do.

Ok lets make it simple:  Why do modern cars need GPS ?

The only way we can apply the word "global" here is if we look at the edges of the screen that kinda worp space for our little robots.

Example 2:

After we get the egrid really going we can have somthing like the locas butterfly that always returns to the same forest during its mating seson even if it was born somewere else.
« Last Edit: May 23, 2005, 07:39:45 PM by Botsareus »

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Bot God
  • *****
  • Posts: 4483
    • View Profile
Make position a Single, not a Long
« Reply #11 on: May 23, 2005, 07:54:32 PM »
I want to some day build a bot some day that uses stratagy in groups and a good understanding of the whole world (map) it is in to win. I will probebly need trig in order to do that.

Trig will be usefull anyway bc it will allow more complex figting stratagys in a bot.

And If you wana talk about realism: real cells do not "think" the way darwinbots do, they form into groups if neurons and then they "think". In the real worlds moleculer level you wont find a cell like "the one" But if Shvartz can tell me a linky or somthing of how thouse real deadly viruse cells "think" I will be glad to read. I am still sure its far more simpler stratagy wise then what darwinbots do already.

Offline shvarz

  • Bot God
  • *****
  • Posts: 1341
    • View Profile
Make position a Single, not a Long
« Reply #12 on: May 23, 2005, 10:51:58 PM »
What is "think" Bots?  Do computers think?  Do dogs think?  Do worms think?  Do cells think?

But if we are talking about behaviour, even the simplest living cell has a behaviour that is much more complex than the behaviour of the most complex bot created so far.
"Never underestimate the power of stupid things in big numbers" - Serious Sam

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Make position a Single, not a Long
« Reply #13 on: May 24, 2005, 02:30:47 AM »
The xpos/ypos argument is so old.  You can probably find it in the old forum.

I was thinking when I get the env grid up, we can have bots' locations be stored for what egrid cell they are in, instead of the uber-fine current twip locations.  Each square is about as big as a bot, so I can't imagine needing to be more exact than that.

Speaking of when I get X working, I'm starting to program again!  I have to find a summer jopb and earn X thousand dollars this summer for school, but other than that I have nothing to do.  DB 2.37/2.4/3.0 here we come!

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Bot God
  • *****
  • Posts: 4483
    • View Profile
Make position a Single, not a Long
« Reply #14 on: May 31, 2005, 07:17:13 PM »
Shvartz dont start me on this "think" crap , I get it enough from my shrink. I beleave we can make computers "think" one day , but thats just me.


Quote
And If you wana talk about realism: real cells do not "think" the way darwinbots do, they form into groups if neurons and then they "think". In the real worlds moleculer level you wont find a cell like "the one" But if Shvartz can tell me a linky or somthing of how thouse real deadly viruse cells "think" I will be glad to read. I am still sure its far more simpler stratagy wise then what darwinbots do already.

Ok I see what you mean now. Ok If you cant call it thinking , if you can find a better word for it , use the better word.


Thats why I put it in "" marks...
« Last Edit: May 31, 2005, 07:19:20 PM by Botsareus »