Multithreading and Variables Question About Robocode

62 views
Skip to first unread message

David Hsieh

unread,
Jun 9, 2016, 1:11:43 PM6/9/16
to robocode
Hi! If you implement multithreading in Robocode, what happens if the two parts of your code that are involved contradict each other in some way? What would happen if one part told the robot to move one way, and the other part of the code told it to move a different way? Would the processes occur simultaneously as usually happens in multithreading, and if so how?

For my second question, how do you carry information over between rounds? Thanks!

fnl

unread,
Jun 9, 2016, 4:38:48 PM6/9/16
to robocode
Robocode keeps a queue for each robot with the "intents" from commands like setAhead(), setTurnLeft(), setFire() etc. but it if multible setAhead() commands are fired within the same turn, the last setAhead() counts.

So if multiple threads are involved in sending commands like setAhead() etc. these will be put into the robot queue in the order they occur based on the time.

Please notice that Robocode divides movement into velocity, direction for body, direction for gun, direction for radar.
So if two threads both give instructions for a new velocity (e.g. one calling setAhead(50) and another setBack(7)), the thread gets to write its instruction in the queue, as the last one, will gets its velocity instruction executed.

Hence, you will need to figure out a way to avoid raise conditions.

I recommend that you have one thread responsible for all movement of the tank - period.
Other threads should have other tasks like e.g. figure out where to aim the gun, pick out a new target, avoid collisions etc.

Cheers,
- Flemming

fnl

unread,
Jun 9, 2016, 4:43:14 PM6/9/16
to robocode
Oh... forgot your second question.

One way to carry information between rounds (and between games after Robocode has been closed down) is to write to the robot data file using the RobocodeFileOutputStream og RobocodeFileInputStream.
But keep in mind that you only have 200.000 bytes of storage (its considered a part of the challenge that storage is limited for every robot).

Cheers,
- Flemming

Den torsdag den 9. juni 2016 kl. 19.11.43 UTC+2 skrev David Hsieh:
Reply all
Reply to author
Forward
0 new messages