Robo Home | Changes | Preferences | AllPages

Robocode API function returning how much the robot has left of your last setAhead() / setBack() calls. A possible use is to check Math.abs(getDistanceRemaining()) for a close to zero return value before issuing new movement commands. -- PEZ
It some times (fail or) returns 0 when the bot hits the wall or an other bot. --SSO?

But hitting a wall or another bot makes the robot stop doesn't it? So then zero must be the correct return value, in'it? -- PEZ

Yep, its correct. The point is if you use it in the controls such as while, for etc. It may couse you problems. So, is's a point to take into account. I prefer to use something like myBot.getLocation().equals(nextPoint); in the controls--SSO?

Same here. In fact, I've hardly really found a practical use for this function; I think my SpaceInvaders? use it a bit to set up, but that's it. I'm not sure if I've ever used it in a competitive bot. What's the use of this function? -- Vuen

It's an easy way to check if you need to move. That way, instead of putting handlers in onHitWall? and onHitRobot?, and also moving at the end of your current movement, you can just move whenever getDistanceRemaining?() == 0. That will cover all of the bases. -- nano

An advantage of using this function instead of checking if you have reached your destination is that you know this function will eventually reach zero. Say you have an enemy bot in the way when trying to reach your destination. Then using the "have I arrived?" type of check might risk you keeping to ram this bot instead of making a new movement descision. -- PEZ

I use Cartesian coordinates rather than polar. - By using above code it saves me a lot of conversions and re calculations. Moreover, If it rams its an advantage and if the enemy moves away still I'll arrive my target destination. It's also matter of taste...--SSO?

Hmph. I always thought a bot should be programmed with a bit more, say, 'awareness' than that. It should know at every tick where it is, and make a movement decision every tick. If you setAhead(200) and it ends up taking you straight into a corner, the robot should be able to realize what's happening before the movement is up and make a decision beforehand. -- Vuen

Robo Home | Changes | Preferences | AllPages
Edit text of this page | View other revisions
Last edited June 15, 2003 19:29 EST by Vuen (diff)