Thread history

From Talk:Main Page
Viewing a history listing
Jump to navigation Jump to search
Time User Activity Comment
07:12, 29 September 2011 Skotty (talk | contribs) Comment text edited (fix link)
07:11, 29 September 2011 Skotty (talk | contribs) New reply created (Reply to while true loop)
00:36, 29 September 2011 Ultimatebuster (talk | contribs) New reply created (Reply to while true loop)
22:00, 28 September 2011 Voidious (talk | contribs) New reply created (Reply to while true loop)
20:49, 28 September 2011 Ultimatebuster (talk | contribs) New thread created  

while true loop

How is the while (true) loop actually broken down? Does robocode executes the code there 1 iteration per turn? Or..?

Ultimatebuster20:49, 28 September 2011

Generally, yes - when you call execute(), the Robocode engine processes one tick, including firing all the events on your bot, and then your run() method continues executing. So most of us have an infinite loop that calls execute() at the end, and each iteration is one tick.

But there's no magic to it - you could have a run method that goes:

public void run() {
  turnRight(20);
  ahead(100);
  fire(3);
}

And that would be perfectly valid. Or you could call execute() every third iteration of your loop. In Dookious, my run method used to have a loop that was while (notWonYet) ..., then a victory dance.

Voidious22:00, 28 September 2011
 

The timing thing for me is very confusing...

For example, if i want to fire at a certain angle, i have to rotate to it.. by the time i do.. i have another angle... which requires more rotation.. etc..

Same thing for turning the robot and going ahead.. I never know how to correctly time them. (Effectively stuck)

Ultimatebuster00:36, 29 September 2011
 

For gun aiming, see Robocode/Game_Physics#Firing_Pitfall. This can cause your aim to be a tick behind. I think most robots don't worry about it. But if you do worry about it, what I do is predict robot positions 1 tick into the future and use that for aiming. It's not exact, but works well enough for me.

Skotty07:11, 29 September 2011