Anti-Gravity Movement

From Robowiki
Revision as of 05:08, 15 March 2011 by Nat (talk | contribs) (→‎Similar Techniques: format link)
Jump to navigation Jump to search

Moving around, avoiding being hit 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 points of varying anti-g charge to enemies, enemy bullets (possibly VirtualBullets), walls, whatever. You then add all the force vectors together, and you let them "push" you in whatever direction they push you in. Normally other bots and walls are assigned forces. Sometimes the center of the field has a generic force as well, or even the guessed positions of bullets. The biggest challenge in getting AntiGravityMovement right is weighting all the forces effectively, especially when there are more or fewer points on the field (maybe the walls have to push harder when there are more bots on the field pushing you toward them?).

Outside of the world of Robocode, this technique is called potential field motion planning.

Standard Implementation

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.

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.

Extending Anti-Gravity Movement

Attractive Fields

In AI this generalized as using "repulsive fields". You could also combine it with attractive fields if you want, but there's rarely a real reason (same goes for tangential fields, for which there is a reason, but the actual implementation is hard to really get right in a pure anti-gravity force-vector sort of way).

Alternative to points

Voidious implemented two other types of ForcePoints: WindPoints and SwivelPoints. 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).

Other types of forces to try are PulsePoints (force pulsates with time) and RandomPoints (random force).

Custom Power

Each point can 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.

See Also

Similar Techniques

Bots

A classic example of AntiGravityMovement is TheArtOfWar. A simpler implementation is Graviton, but simpler in this case doesn't necessarily mean more clear (same goes for Escape, which is a more convoluted bot based on Graviton).