Author Topic: Got bots that behave differently in 2.37.6 and 2.42.4?  (Read 8646 times)

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Got bots that behave differently in 2.37.6 and 2.42.4?
« Reply #15 on: May 16, 2006, 12:45:29 PM »
Shots started before my time, but as far as I understand, it's a relic of the C Robots heritage.  Shots are the "cannon" that are common in such simulations, with the returning shots the way that the bots can use it to feed.

One nice property of returning an energy shot is that it takes some time to travel, creating a kind of time differential between firing the shot, causing damage, and recieving nrg.

For the ray - cylinder collision, I imagine you want to test two simoltaneous equations.

Bot:
pos(t) = pos + t(vel)  t in [0,1]

Shot:
pos(t) = pos + t(vel) t in [0,1]

You'd then have to check if there's an intersection at a time when the t's are the same.  I can check my collision detection reference manual when I get home wednesday and give you a definative answer.

Offline Sprotiel

  • Bot Destroyer
  • ***
  • Posts: 135
    • View Profile
Got bots that behave differently in 2.37.6 and 2.42.4?
« Reply #16 on: May 16, 2006, 07:06:17 PM »
I'd say that the major argument for shots is that they are quite hard to catch, which puts the bots under selection pressure.

Correctly checking for collisions between shots and bots isn't very hard. It's exactly the same problem as the ray/circle intersection :
The bot's position during the turn is given by r_b (t) = r_b + t v_b.
The shot's position is r_s (t) = r_s (t) + t v_s
and the vector expressing its position relative to the bot is r(t) = r + t v = r_s (t) - r_b (t)
All there is to check is whether there's a t in [0,1] for which |r(t)| < R, R being the bot's radius.
So we have to study the function |r(t)|^2 = r^2 + 2t(r.v) + t^2 v^2. It reaches its minimum at t0 = -(r.v)/v^2, where |r(t0)|^2 = r^2 - (r.v)^2/v^2.

Therefore, there's a collision iff |r(0)|^2 < R^2 or |r(1)|^2 < R^2 or ( 0 < t0 < 1 and |r(t0)|^2 < R^2 ).

I don't know what's the best algorithm to translate the above into code, but it shouldn't be too hard. The most important thing is to have a quick check to reject the majority of the cases, which will probably rely on the fact that if |r| - |v| > R, we're sure there's no collision.

Offline Endy

  • Bot Overlord
  • ****
  • Posts: 852
    • View Profile
Got bots that behave differently in 2.37.6 and 2.42.4?
« Reply #17 on: May 17, 2006, 03:04:48 AM »
Shots are just sort of part of DB. They could be redone to have guaranteed effect but that would impose it's own problems. Poison and Venom would be a nightmare in that version. If it could be done easily enough a more chemical version of shots would be nice; but I'd imagine the processing power for that would be even worse than for shots.

Maybe just adding a button to stop drawing them would be best. Then players could hide them for some increased speed.

Offline EricL

  • Administrator
  • Bot God
  • *****
  • Posts: 2266
    • View Profile
Got bots that behave differently in 2.37.6 and 2.42.4?
« Reply #18 on: May 18, 2006, 12:55:01 AM »
Here is a summary of what I have done for 2.42.5 regarding shots.

First, I have written a new shot collision routine based upon Sprotiel's algorithm (thanks Sprotiel!).  Though the new code that actually does the collision detection is a little more involved and thus more computationally intensive than the old, I have added some performance improvements to the routine above and beyond what was there before.  Bascially, I don't bother to do the math for bots which are not near enough to the shot to have possibly closed the distance in the past cycle.  So, the new code as a whole is now as fast or perhaps even faster than before.

I had to add some additional code to detect cases where a fast moving shot completly penetrates a bot with a high number in the robot array and then enters a second bot with a lower number all during the same cycle so as to be sure to detect and report the collision with the first bot the shot hit and not the second.  Otherwise, you can get cases of starvation where the firing bot is shooting through a small bot and hitting one on the other side, but the returned energy shot is being absorbed by the bot in the middle.  That is, the code has to be aware that the shot ray could interesct two (or more) circles!

The final solution works very well.  The code now has (I hope) a fairly bullet proof (pun intended) bot/shot collision routine which takes into account both shot and target bot velocity (and thus position) during the cycle - a marked improvement over what was there before.  It can handle shots of varying speed (within reason) so if we wanted to for example, expose a sysvar to allow for bots to shoot at different speeds, or base shot speed on .shootval or similar, the code is now set up for that.  (To be clear, such capabilities will NOT be in 2.42.5).

As fas as the speed of returning energy shots, I have been playing around with this and while Sprotiel's V_back = 2 V_target - V_shot formula works well for ideal environments without brownian motion or gravity when the firing bot maintains constant velcoity during the cycles it takes for the shot it fired to impact and the associated energy shot to retrun, the increased shot speed actually decreases the probability that the firing bot will receive the returned energy shot in cases where these conditions are violated.  In short, the slower the returned shot travels and the longer it lasts (I.e. the longer it's "range" in cycles) the greater the probability that the firing bot (or some other bot) will stumble into it.  When returned energy shots travel fast, they often miss and go zooming by the bot that fired the causal shot because the bot isn't exactly where the math/physics say he should be due to brownian motion or his own acceleration.  Slower shots hang around the area for a longer number of cycles, resulting in more consumptions.

So, I have left the returned energy shot speed as it was:

Returning shot's velocity = colliding bot's velocity - shooting shot's velocity / 2

But have doubled the "range" - the number of cycles they last.  The result is that in situations where the targetted bot's veloctiy is zero, such as a fixed veggy, the returned energy shot has the same range in terms of distance on the field as the shot that initiated it, giving a satisfying visiaul experience, but it goes half as fast (lasting twice as many cycles).   In cases where the targetted bot has velocity, well, generally it's being chased and the energy shots maintain a good deal of the targetted bot's velocity, but fall behind at a speed of 1/2 the ***relative*** speed of the incoming shot.   Again, I think this is visually satisfying and exhibits good results in a variety of environments and circumstances.  Feedback and comments are of course very welcome.

Additionally, since I had to figure out exactly when (in terms of a fraction of a cycle) the shot hit the bot anyway as part of the collision detection routine, I now begin returning energy shots at the initial point of impact and not some arbitrary distance inside (or through and beyond) the bot.  This should give returning energy shots *exactly* the same range in terms of distance on the field as the shot which caused them.  

One last thing is that I found and fixed an order of operation bug with shots that are on their last cycle of age.   In short, collision detection was not happening on the last cycle of a shot's life, even though the shot was being displayed.  This resulted in cases where a shot from a distance could be seen hitting the target bot but no energy shot was being returned.  I've remedied this.  Note that the energy of the returned shot still falls off dramatically when the triggerring shot is near the end of it's range.  So even though an energy shot will now be returned due to a hit from a shot on its last cycle of existance, the nrg in that returned shot will be much less than if the feeding bot had fired point blank.
« Last Edit: May 18, 2006, 01:27:43 AM by EricL »
Many beers....

Offline EricL

  • Administrator
  • Bot God
  • *****
  • Posts: 2266
    • View Profile
Got bots that behave differently in 2.37.6 and 2.42.4?
« Reply #19 on: May 19, 2006, 02:05:32 PM »
I'd like to reiterate my call for people to bring version differences or other issues with 2.42.4 to my attention.

On a separate note, I have been testing the changes to shot collision detection mentioned above and working on overall performance in general.  I feel very confident that 2.42.5 completly nails the issues with shots observed in previous versions.
Many beers....

Offline EricL

  • Administrator
  • Bot God
  • *****
  • Posts: 2266
    • View Profile
Got bots that behave differently in 2.37.6 and 2.42.4?
« Reply #20 on: May 19, 2006, 02:26:10 PM »
Quote from: Endy
Maybe just adding a button to stop drawing them would be best. Then players could hide them for some increased speed.
It turns out that doing the actual drawing of stuff in DB is not all that CPU intensive relative to the rest of the code.  Oh sure, if you have a small sim, then the drawing part is a reasonable fraction of the total computation and turning off the graphics results in a noticable increase in cycles/sec.  But for large sims, it's in the noise.  The time it takes to draw stuff is linear to the number of things being drawn with a small constant overhead for each thing (e.g. each tie, bot, shot).  But the vast majority of stuff in the sim needs to be calculated whether graphics are on or not and some of those things are worse than O(N) ((I.e. nonlinear - doubling the number of bots needs more than double the number of CPU cycles because the number of possible interactions - who sees who, ties, shots, etc. increases faster than 2X).  Shot collision for example is proportional to both the number of shots and the number of bots in the sim, though there are a lot of perf shortcuts now that make it a lot better then O(N^2).  So, the computation time it takes for the sim as a whole increases non-linerally with the size of the sim and the physics calculations, etc. become a larger and larger percentage of the total CPU time as the sim size increases.

So, not drawing shots saves very little.  You still have to keep track of them, do all the math to figure out collisions, release energy, etc.

Bottom line, drawing stuff is easy.  Figuring out what to draw, now that's hard...  
Many beers....

Offline Elite

  • Bot Overlord
  • ****
  • Posts: 532
    • View Profile
Got bots that behave differently in 2.37.6 and 2.42.4?
« Reply #21 on: May 19, 2006, 05:10:40 PM »
Helios, Light's legendary MB, doesn't work in 2.4

It just doesn't form 4-cell MBs like it's supposed to  

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Got bots that behave differently in 2.37.6 and 2.42.4?
« Reply #22 on: May 19, 2006, 05:15:54 PM »
Dollars to donuts it has to do with the more dynamic sizing in 2.4.  That's where I'd concentrate my debugging efforts.

Offline Endy

  • Bot Overlord
  • ****
  • Posts: 852
    • View Profile
Got bots that behave differently in 2.37.6 and 2.42.4?
« Reply #23 on: May 19, 2006, 05:29:53 PM »
Not sure if it's been fixed yet, but I figured out what was causing the mysterious poison shots to be returned on occasion by bots/walls without any poison. It's caused by shots again near the end of their lives, apparently with nrg being just below zero, these would cease existing next cycle but I guess they're not caught in time. Anyways the oddball poison shots returned don't have any real nrg or poison, so don't compose a major threat.

Added right before the poison shot generation area:

If nrg <= 0 Then GoTo exitsub

Did the trick and stoped them from forming  

Also found another minor bug in shots, allowing walls to receive stray shots, giving them nrg and waste. Probably at least part of the reason they keep occasionally dieing on me.

Added some code to check that a bot isn't a wall in the -2 shot case handling section to correct for it.

Something else is also going though, I had a mutant TheOne figure out a way to kill them in a single shot. Sneaky bots, I'm going to try and trouble shoot where the problem is.
« Last Edit: May 19, 2006, 05:32:51 PM by Endy »

Offline EricL

  • Administrator
  • Bot God
  • *****
  • Posts: 2266
    • View Profile
Got bots that behave differently in 2.37.6 and 2.42.4?
« Reply #24 on: May 19, 2006, 08:46:43 PM »
Quote from: Elite
Helios, Light's legendary MB, doesn't work in 2.4

It just doesn't form 4-cell MBs like it's supposed to  

Well, first off, .stifftie is not implemented in 2.42.4.  But that is only part of it.

The main issue is that unless I am mistaken, Helios should not work in any version and the fact that does in 2.37.6 is a bug.  It attempts to use .fixlen, .fixang and .stifftie well before it is a multibot, like at .robage 2 and 3.   My understanding (as PY says very adamantly here) is that these sysvars should not work unless a bot is a multibot and that bots arn't multbots until a tie has hardned and the only way a tie can harden is for it to exist for 20 cycles so that is what the 2.42.4 code enforces.  

So, the reason it is not forming 4 bot multibots ( I think) is that it expects to stiffen the tie to its first offspring and fix it's length to move the offspring away to make room to reproduce again at a specific age , but of course this does not work (by design) so the other offspring can't be born on the cycle it wants them to because it's first baby is still in the way adn this messes it up.
Many beers....

Offline EricL

  • Administrator
  • Bot God
  • *****
  • Posts: 2266
    • View Profile
Got bots that behave differently in 2.37.6 and 2.42.4?
« Reply #25 on: May 19, 2006, 08:50:42 PM »
Quote from: Endy
Not sure if it's been fixed yet...,

Added right before the poison shot generation area:

If nrg <= 0 Then GoTo exitsub

I had actually caught this and fixed is in a similar fashion.

Quote from: Endy
Also found another minor bug in shots, allowing walls to receive stray shots, giving them nrg and waste.
Nice find.  I'll take care of this in 2.42.5.
« Last Edit: May 19, 2006, 08:51:54 PM by EricL »
Many beers....