# Talk:Anti-Gravity Movement

## From the Old Wiki

NOTE: Anti-Grav movement is not really that original, in the field of robotics this is called potential field movement. Although the implementation mentioned here is an interesting take on the idea. (Added 4/20/05) Troutinator

Moving around, avoiding being hit (DodgingBullets) or rammed by enemy robots as well as WallAvoidance can be quite trickier than you'd think at first. Someone suggested using the laws of gravity for this, but reversed. Something along these lines:

• Assign anti gravity objects of varying charge to enemies, enemy bullets (possibly VirtualBullets), walls, whatever.
• Make your bot repell from those objects based on their charge.

-- PEZ

AntiGravityMovement makes for a great Melee strategy as it tends to keep your bot away from the center of the field and from large groups of other bots (who tend to annihilate each other quickly.) Standard practice is to use the inverse square of the distance from the target you wish to repel, take that force as a vector and break it into X and Y components, then add up all the forces you currently are tracking and use this to tell your bot which direction to move. DustBunny uses a very simple AntiGravityMovement routine and is a NanoBots class robot so it should be very easy to understand. For more advanced version, people put artificial antigravity points along the walls and usually 1 in the center of the field. This gives you wall avoidance and center of the field avoidance. Fermat, TheArtOfWar, and many of the best bots use this as their primary mode of movement as it tends to be hard for pattern matching aim to get a lock on this movement. There are other tutorials, but I can't remember where they live at the moment.

The original anti-gravity code can be found in Relativity, version 3_7 still exists on the RobocodeRepository.

The idea was indeed to use the formula for gravity , mass/distance-squared, and then move away from the attraction. I have also experimented with using the square-root of the distance (reason: if a bot is 600 or 700 or 800 away, I think I care about them equally, and the square-root is less codesize in a MiniBot). So far, I think the original formula is most robust.

-- tobe

I've made a class that encapsulates this algorithm, see Hanji/AGravEngine and Hanji/GravPoint for details.

--Hanji

I'm using a variation on AntiGravityMovement for my new 1v1 bot, and it seems to be working pretty well. I'm a newbie to high level Robocoding (took at stab at it 3 years back, but I've grown a lot as a coder since then), so I am open to comments/suggestions about all this. Basically, I have two other types of ForcePoints: WindPoints and SwivelPoints; more could easily be added in the future, and probably will be. The WindPoint only emits a force in a particular direction, no matter what your bearing to it is. The SwivelPoint emits a force perpendicular to your bearing to it; it randomly chooses which way, unless you're near a wall, in which case it chooses the angle closest to the bearing to center (basic wall avoidance).

The idea first arose because I was quite displeased with how GravityPoints functioned as wall avoidance. WindPoints from the corners and wall midpoints work much better for me. The SwivelPoint was created to add a tendency of being perpendicular to the opponent, but I have since begun using them for WaveSurfing, as well. Lastly, I allow each point to have a custom "distance factor" in the equation 1/distance^DF, which adds some additional flexibility. If you make the distance factor == zero, then the strength is the same at any distance; for WaveSurfing, I do that and make the strength 1/distance-to-wave-edge.

In the future, I may make PulsePoints (force pulsates with time) or RandomPoints (random force). I find this type of force sum system very easy to work with, and I haven't really found anything I couldn't do with it yet - bullet dodging, random movement, and wall avoidance I've done, and I'm working on WaveSurfing now.

-- Voidious

I took a shot at wavesurfing with antigrav a while back but I never got it to work quite right. Despite all of my efforts, my bots always seemed to want to move directly away from bullets (certain death) rather than move perpendicular to them. I always thought that the idea had merit but could not get it to show. I'll be interested to see if you get it to work correctly Voidious. --wcsv

I tried something like that too. I had gravity lines, and gravity valleys. I used the lines for wall avoidance and the valleys to get a certain distance to the enemy. But it was not as good as my simple perpendicular movement with wall avoidance... --Krabb

I know how anti-gravity is suppose to work in theory, I just can't figure out how to impliment it in a robot. -- Chase-san

@Chase-san: maybe you could use anti-gravity with some other movement, like maybe put some anti-gravity force on other bots and walls, and a gravity force on where the movement tells you to go. An example of how anti-gravity is used is here. --Starrynte

Or, grab Carruthers 1.2, and take a peek at /techdude/coreaddons/wheels/BlackboardMovement.java, that's my implementation of AntiGrav. --Nfwu

## HELP!

I've worked really hard on a bot that simulates bullets and I've finished that part, and now I need to use Anti-Gravity movement with it. But I don't know how to do it! I've never done any complex movement before... --Awesomeness 00:33, 4 May 2009 (UTC)

This is where I started, several years ago: Secrets from the Robocode masters: Anti-gravity movement --Darkcanuck 01:20, 4 May 2009 (UTC)

I don't get it, it's so complicated... Ugh. --Awesomeness 01:54, 4 May 2009 (UTC)
Well, it's not that I don't know how it works, I just don't know how to change it so that the bullets are antigrav points. I understand it, but I don't know how to implemnent it.
DustBunny is where I learned Anti-Gravity Movement. I think that Graviton is another good example, but I never read it code. » » 12:10, 4 May 2009 (UTC)
Using Google's cache feature, which saves pages, (The old robowiki just gives 404s now.) I've been able to look at Hanji's antigrav engine, and it's very clear. I think I'll even be able to make my own off this. --Awesomeness 15:04, 4 May 2009 (UTC)
I was once use Hanji's antigrav engine. I cannot make it working so I start working on DustBunny prototype instead. But I don't blame it, just my experience, and I admit that it is very neat engine. And if you think you will visit the old wiki frequently, you may want to use your host file to point to the old wiki which I, Voidious and probably some more used. (see Talk:Migration, I can't remember which section is it in.) » » 15:18, 4 May 2009 (UTC)
DustBunny uses a very bastardized version of anitgrav. Unless you are doing nano code, you are much better off creating actual x,y points and repeling from them. Use the paint code to show where the grav points are for debugging help. --Miked0801 16:58, 4 May 2009 (UTC)
But I did a semi-successful creating a complex anti-gravity movement from DustBunny =) Because it is very bastardized, I can create a version with (x,y)gravpoint in short period of time =D » » 17:03, 4 May 2009 (UTC)
Just a note, in case you haven't already done this: Treating bullets as straight-up anti-grav points may result in your robot trying to run directly away from bullets, which is a good way to get killed. You should make your anti-gravity force vector point in a direction that is perpendicular to the line between the bullet and the bot that fired it, so that your bot will flee *sideways* from the bullet. RobertWalker 15:44, 4 May 2009 (UTC)
Ugh... *Rips hair out* I can't do it... I wish there was an Anti-Gravity Tutorial... I can't understand the IBM tutorials and I feel like DustBunny's is in some ancient language... =( It's so hard for me to learn all of this stuff... And for you guys it always just slips off your fingers like it's 2+2 or something... I'm so jealous. <Insert jealous smiley here> Awesomeness 22:43, 19 January 2010 (UTC)