How to use getTurn() correctly for an AdvancedRobot?

23 views
Skip to first unread message

John Smith

unread,
Nov 27, 2021, 9:43:24 AM11/27/21
to Robocode
I am very knew to robocode and I am trying to have some way of keeping track of time for some of my code. For example: I want my radar to do a 360 scan to check for greater threats than the current target and I would like it to do it once every 100 ticks/turns.

Any tips would be great. Unfortunately it appears that a lot of website links are no longer hosted that have examples robocode.

Thank you for your time.   

fnl

unread,
Nov 27, 2021, 9:58:53 AM11/27/21
to Robocode
Hi John and welcome to Robocode. :)

The best source to get tips about Robocode is the RoboWiki here:
https://robowiki.net/wiki/Main_Page

The getTurn() method returns the current turn number, which is the same as the "time" or "tick" in Robocode.

If you want to do something every 100 ticks then you can use the modulo operator.
So you could e.g. do something like:

If (getTime() % 100 == 0) { // every 100th tick
    // do something else with radar
}

I guess your radar strategy depends on how many enemy bots are (left) on the battlefield (using the getOthers() method).
E.g. if there is only one robot left, you might as well "lock" the radar on this last robot (1-to-1 battle).
If there are two robots left, then a better strategy might be to sweep the shortest distance for the radar between the two robots.

Make sure to have a look at some of the well-known radar strategies here at the RoboWiki:
https://robowiki.net/wiki/Radar

Best regards,
- Flemming

Reply all
Reply to author
Forward
0 new messages