Discussion:
Multithreading and Variables Question About Robocode
David Hsieh
2016-06-09 02:13:31 UTC
Permalink
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!
--
You received this message because you are subscribed to the Google Groups "robocode" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robocode+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
fnl
2016-06-09 20:38:48 UTC
Permalink
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
Post by David Hsieh
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!
--
You received this message because you are subscribed to the Google Groups "robocode" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robocode+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
fnl
2016-06-09 20:43:14 UTC
Permalink
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
Post by David Hsieh
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!
--
You received this message because you are subscribed to the Google Groups "robocode" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robocode+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...