<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://robowiki.net/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Tonnetz</id>
	<title>Robowiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="http://robowiki.net/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Tonnetz"/>
	<link rel="alternate" type="text/html" href="http://robowiki.net/wiki/Special:Contributions/Tonnetz"/>
	<updated>2026-04-20T23:27:23Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.34.1</generator>
	<entry>
		<id>http://robowiki.net/w/index.php?title=Robocode/My_First_Robot&amp;diff=33950</id>
		<title>Robocode/My First Robot</title>
		<link rel="alternate" type="text/html" href="http://robowiki.net/w/index.php?title=Robocode/My_First_Robot&amp;diff=33950"/>
		<updated>2014-11-20T06:39:02Z</updated>

		<summary type="html">&lt;p&gt;Tonnetz: /* Fire at Will! */ Fixed dash&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is the classic '''My First Robot Tutorial''' that tells how to create your first robot.&lt;br /&gt;
&lt;br /&gt;
== Creating a Robot ==&lt;br /&gt;
Here's the fun stuff: This is what [[Robocode]] is all about! &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
| Creating a robot can be easy. Making your robot a winner is not. You can spend only a few minutes on it, or you can spend months and months. I'll warn you that writing a robot can be addictive! Once you get going, you'll watch your creation as it goes through growing pains, making mistakes and missing critical shots. But as you learn, you'll be able to teach your robot how to act and what to do, where to go, who to avoid, and where to fire. Should it hide in a corner, or jump into the fray?&lt;br /&gt;
|| [[Image:MatBot.jpg|Picture of the robot named MatBot, which is one Mathew Nelson's robots]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= My First Robot =&lt;br /&gt;
Ready to create your first robot? I hope you'll find that it's easy, straightforward, fun, and addictive!&lt;br /&gt;
&lt;br /&gt;
Robocode ships with a number of sample robots that you can look at for ideas, and to see how things work. You can use the Robot Editor to look at all of them.&lt;br /&gt;
&lt;br /&gt;
In this section, we'll use the Robot Editor to create your very own, brand new robot.&lt;br /&gt;
&lt;br /&gt;
== The Robot Editor ==&lt;br /&gt;
The first step is to open up the Robot Editor. From the main Robocode screen, click on the '''Robot''' menu, then select '''Editor'''.&lt;br /&gt;
&lt;br /&gt;
When the editor window comes up, click on the '''File''' menu, then select '''New Robot'''.&lt;br /&gt;
&lt;br /&gt;
In the dialogs that follow, type in a name for your robot, and enter your initials.&lt;br /&gt;
&lt;br /&gt;
Voila! You now see the code for your own robot.&lt;br /&gt;
&lt;br /&gt;
== A New Robot ==&lt;br /&gt;
This is what you should be looking at (names have been changed to protect the innocent):&lt;br /&gt;
&lt;br /&gt;
  package man;&lt;br /&gt;
  import robocode.*;&lt;br /&gt;
  &amp;amp;nbsp;&lt;br /&gt;
  public class MyFirstRobot extends Robot {&lt;br /&gt;
      public void run() {&amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;&amp;lt;b&amp;gt;&lt;br /&gt;
          while (true) {&lt;br /&gt;
              ahead(100);&lt;br /&gt;
              turnGunRight(360);&lt;br /&gt;
              back(100);&lt;br /&gt;
              turnGunRight(360);&lt;br /&gt;
          }&amp;lt;/b&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
      }&lt;br /&gt;
  &amp;amp;nbsp;&amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;&amp;lt;b&amp;gt;&lt;br /&gt;
      public void onScannedRobot(ScannedRobotEvent e) {&lt;br /&gt;
          fire(1);&lt;br /&gt;
      }&amp;lt;/b&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
We're only concerned with the bits in '''&amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;bold&amp;lt;/span&amp;gt;''' here... you won't need to change anything else. Not that much, right?&lt;br /&gt;
&lt;br /&gt;
By the way, if you're REALLY concerned about the rest of it, right now, I describe it here:&lt;br /&gt;
&lt;br /&gt;
  package man;&lt;br /&gt;
  import robocode.*;&lt;br /&gt;
  &amp;amp;nbsp;&lt;br /&gt;
  public class MyFirstRobot extends Robot {&lt;br /&gt;
      public void run() {&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;text-align:left&amp;quot;&lt;br /&gt;
! import robocode.*;&lt;br /&gt;
| Tells Java that you're going to use Robocode objects in your robot.&lt;br /&gt;
|-&lt;br /&gt;
! public class MyFirstRobot extends Robot&lt;br /&gt;
| Tells Java: &amp;quot;The object I'm describing here is a type of [[Robot]], named MyFirstRobot&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
! public void run() { }&lt;br /&gt;
| The game calls your run() method when the battle begins.&lt;br /&gt;
|-&lt;br /&gt;
! { }&lt;br /&gt;
| &amp;quot;Curly brackets&amp;quot; ( '''{ }''' ) group things together. In this case, they're grouping together all the code for the robot.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Let's move somewhere ==&lt;br /&gt;
Let's add a couple lines so that it will do something.&lt;br /&gt;
&lt;br /&gt;
First, we'll examine the run() method: &lt;br /&gt;
&lt;br /&gt;
  while (true) {&lt;br /&gt;
      ahead(100);&lt;br /&gt;
      turnGunRight(360);&lt;br /&gt;
      back(100);&lt;br /&gt;
      turnGunRight(360);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;while(true) { }&amp;lt;/code&amp;gt; means: &amp;quot;While the condition &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt; is true, do everything between the curly brackets { }&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt; is always true, it means: &amp;quot;Do the stuff inside my curly brackets, forever&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
So this robot will:&lt;br /&gt;
# move ahead 100 pixels&lt;br /&gt;
# turn the gun right by 360 degrees&lt;br /&gt;
# move back 100 pixels&lt;br /&gt;
# turn the gun left/back by 360 degrees&lt;br /&gt;
&lt;br /&gt;
The robot will continue doing this over and over and over, until it dies, due to the &amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
Not so bad, right?&lt;br /&gt;
&lt;br /&gt;
== Fire at Will! ==&lt;br /&gt;
When our radar scans a robot, we want to fire:&lt;br /&gt;
&lt;br /&gt;
  public void onScannedRobot(ScannedRobotEvent e) {&lt;br /&gt;
      fire(1);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
The game calls your '''onScannedRobot''' method whenever—during one of the actions—you see another robot.&lt;br /&gt;
It sends along an event that can tell us lots of information about the robot—its name, how much life it has, where it is, where it's heading, how fast it's going, etc.&lt;br /&gt;
&lt;br /&gt;
However, since this is a simple robot, we're not going to look at any of that stuff. Let's just fire!&lt;br /&gt;
&lt;br /&gt;
== Compile your robot ==&lt;br /&gt;
First, save your robot by selecting the '''Save''' in the '''File''' menu. Follow the prompts to save your robot.&lt;br /&gt;
&lt;br /&gt;
Now, compile it by selecting '''Compile''' in the '''Compiler''' menu.&lt;br /&gt;
&lt;br /&gt;
If your robot compiles without any errors, you can start a new battle with your robot. Start a new battle by selecting '''New''' in the '''Battle''' menu. If you cannot see your robot, you might have to refresh the list of robots by '''pressing F5'''. Add your robot to the battle together with at least one other robot as e.g. sample.Target, and press the '''Start Battle''' button to let the games begin!&lt;br /&gt;
&lt;br /&gt;
== What's next? ==&lt;br /&gt;
You should have a look at all the sample robots to see how certain things are done.&lt;br /&gt;
&lt;br /&gt;
You'll eventually want to look at the [http://robocode.sourceforge.net/docs/robocode/ Robocode API] to see all the other things your robot can do.&lt;br /&gt;
&lt;br /&gt;
Above all, good luck, have fun, and enjoy!&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
=== Robot API ===&lt;br /&gt;
* [http://robocode.sourceforge.net/docs/robocode/ Robot API]&lt;br /&gt;
&lt;br /&gt;
=== Tutorials ===&lt;br /&gt;
* [[Robocode/System Requirements|System Requirements for Robocode]]&lt;br /&gt;
* [[Robocode/Download|How to download and install Robocode]]&lt;br /&gt;
* [[Robocode/Robot Anatomy|The anatomy of a robot]]&lt;br /&gt;
* [[Robocode/Getting Started|Getting started with Robocode]]&lt;br /&gt;
* [[Robocode/Game Physics|Robocode Game Physics]]&lt;br /&gt;
* [[Robocode/Scoring|Scoring in Robocode]]&lt;br /&gt;
* [[Robocode/Robot Console|Using the robot console]]&lt;br /&gt;
* [[Robocode/Downloading_Robots|Downloading other robots]]&lt;br /&gt;
* [[Robocode/Learning from Robots|Learning from other robots]]&lt;br /&gt;
* [[Robocode/Package Robot|Package your robot]]&lt;br /&gt;
* [[Robocode/FAQ|Frequently Asked Questions (FAQ)]]&lt;br /&gt;
* [[Robocode/Articles|Articles about Robocode]]&lt;br /&gt;
* [[Robocode/Console Usage|Starting Robocode from the command line]]&lt;br /&gt;
* [[Robocode/Graphical_Debugging|Graphical debugging]]&lt;br /&gt;
* [[Robocode/Eclipse|Using Eclipse as IDE]]&lt;br /&gt;
* [[Robocode/Eclipse/Create_a_Project|Creating a project for your robots]]&lt;br /&gt;
* [[Robocode/Eclipse/Create_a_Robot|Creating a robot in Eclipse]]&lt;br /&gt;
* [[Robocode/Running from Eclipse|Running your robot from Eclipse]]&lt;br /&gt;
* [[Robocode/Eclipse/Debugging Robot|Debugging your robot with Eclipse]]&lt;br /&gt;
&lt;br /&gt;
=== News and Releases ===&lt;br /&gt;
* [http://sourceforge.net/export/rss2_project.php?group_id=37202 RSS Feeds for the Robocode project]&lt;br /&gt;
* [http://sourceforge.net/project/showfiles.php?group_id=37202&amp;amp;package_id=29609 Robocode file releases]&lt;br /&gt;
&lt;br /&gt;
=== Home pages ===&lt;br /&gt;
* [http://robocode.sourceforge.net/ Classic homepage]&lt;br /&gt;
* [http://sourceforge.net/projects/robocode Robocode project at SourceForge]&lt;br /&gt;
* [http://robocoderepository.com/ Robocode Repository]&lt;br /&gt;
* [[wikipedia:Robocode|Wikipediaentry for Robocode]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Robocode Documentation]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Tonnetz</name></author>
		
	</entry>
	<entry>
		<id>http://robowiki.net/w/index.php?title=Robocode/My_First_Robot&amp;diff=33949</id>
		<title>Robocode/My First Robot</title>
		<link rel="alternate" type="text/html" href="http://robowiki.net/w/index.php?title=Robocode/My_First_Robot&amp;diff=33949"/>
		<updated>2014-11-20T06:38:27Z</updated>

		<summary type="html">&lt;p&gt;Tonnetz: /* Fire at Will! */ Tweaked wording to hopefully give the impression that events are delivered within, not parallel to, the run method's execution&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is the classic '''My First Robot Tutorial''' that tells how to create your first robot.&lt;br /&gt;
&lt;br /&gt;
== Creating a Robot ==&lt;br /&gt;
Here's the fun stuff: This is what [[Robocode]] is all about! &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
| Creating a robot can be easy. Making your robot a winner is not. You can spend only a few minutes on it, or you can spend months and months. I'll warn you that writing a robot can be addictive! Once you get going, you'll watch your creation as it goes through growing pains, making mistakes and missing critical shots. But as you learn, you'll be able to teach your robot how to act and what to do, where to go, who to avoid, and where to fire. Should it hide in a corner, or jump into the fray?&lt;br /&gt;
|| [[Image:MatBot.jpg|Picture of the robot named MatBot, which is one Mathew Nelson's robots]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= My First Robot =&lt;br /&gt;
Ready to create your first robot? I hope you'll find that it's easy, straightforward, fun, and addictive!&lt;br /&gt;
&lt;br /&gt;
Robocode ships with a number of sample robots that you can look at for ideas, and to see how things work. You can use the Robot Editor to look at all of them.&lt;br /&gt;
&lt;br /&gt;
In this section, we'll use the Robot Editor to create your very own, brand new robot.&lt;br /&gt;
&lt;br /&gt;
== The Robot Editor ==&lt;br /&gt;
The first step is to open up the Robot Editor. From the main Robocode screen, click on the '''Robot''' menu, then select '''Editor'''.&lt;br /&gt;
&lt;br /&gt;
When the editor window comes up, click on the '''File''' menu, then select '''New Robot'''.&lt;br /&gt;
&lt;br /&gt;
In the dialogs that follow, type in a name for your robot, and enter your initials.&lt;br /&gt;
&lt;br /&gt;
Voila! You now see the code for your own robot.&lt;br /&gt;
&lt;br /&gt;
== A New Robot ==&lt;br /&gt;
This is what you should be looking at (names have been changed to protect the innocent):&lt;br /&gt;
&lt;br /&gt;
  package man;&lt;br /&gt;
  import robocode.*;&lt;br /&gt;
  &amp;amp;nbsp;&lt;br /&gt;
  public class MyFirstRobot extends Robot {&lt;br /&gt;
      public void run() {&amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;&amp;lt;b&amp;gt;&lt;br /&gt;
          while (true) {&lt;br /&gt;
              ahead(100);&lt;br /&gt;
              turnGunRight(360);&lt;br /&gt;
              back(100);&lt;br /&gt;
              turnGunRight(360);&lt;br /&gt;
          }&amp;lt;/b&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
      }&lt;br /&gt;
  &amp;amp;nbsp;&amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;&amp;lt;b&amp;gt;&lt;br /&gt;
      public void onScannedRobot(ScannedRobotEvent e) {&lt;br /&gt;
          fire(1);&lt;br /&gt;
      }&amp;lt;/b&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
We're only concerned with the bits in '''&amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;bold&amp;lt;/span&amp;gt;''' here... you won't need to change anything else. Not that much, right?&lt;br /&gt;
&lt;br /&gt;
By the way, if you're REALLY concerned about the rest of it, right now, I describe it here:&lt;br /&gt;
&lt;br /&gt;
  package man;&lt;br /&gt;
  import robocode.*;&lt;br /&gt;
  &amp;amp;nbsp;&lt;br /&gt;
  public class MyFirstRobot extends Robot {&lt;br /&gt;
      public void run() {&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; style=&amp;quot;text-align:left&amp;quot;&lt;br /&gt;
! import robocode.*;&lt;br /&gt;
| Tells Java that you're going to use Robocode objects in your robot.&lt;br /&gt;
|-&lt;br /&gt;
! public class MyFirstRobot extends Robot&lt;br /&gt;
| Tells Java: &amp;quot;The object I'm describing here is a type of [[Robot]], named MyFirstRobot&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
! public void run() { }&lt;br /&gt;
| The game calls your run() method when the battle begins.&lt;br /&gt;
|-&lt;br /&gt;
! { }&lt;br /&gt;
| &amp;quot;Curly brackets&amp;quot; ( '''{ }''' ) group things together. In this case, they're grouping together all the code for the robot.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Let's move somewhere ==&lt;br /&gt;
Let's add a couple lines so that it will do something.&lt;br /&gt;
&lt;br /&gt;
First, we'll examine the run() method: &lt;br /&gt;
&lt;br /&gt;
  while (true) {&lt;br /&gt;
      ahead(100);&lt;br /&gt;
      turnGunRight(360);&lt;br /&gt;
      back(100);&lt;br /&gt;
      turnGunRight(360);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;while(true) { }&amp;lt;/code&amp;gt; means: &amp;quot;While the condition &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt; is true, do everything between the curly brackets { }&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt; is always true, it means: &amp;quot;Do the stuff inside my curly brackets, forever&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
So this robot will:&lt;br /&gt;
# move ahead 100 pixels&lt;br /&gt;
# turn the gun right by 360 degrees&lt;br /&gt;
# move back 100 pixels&lt;br /&gt;
# turn the gun left/back by 360 degrees&lt;br /&gt;
&lt;br /&gt;
The robot will continue doing this over and over and over, until it dies, due to the &amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
Not so bad, right?&lt;br /&gt;
&lt;br /&gt;
== Fire at Will! ==&lt;br /&gt;
When our radar scans a robot, we want to fire:&lt;br /&gt;
&lt;br /&gt;
  public void onScannedRobot(ScannedRobotEvent e) {&lt;br /&gt;
      fire(1);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
The game calls your '''onScannedRobot''' method whenever—during one of the actions—you see another robot.&lt;br /&gt;
It sends along an event that can tell us lots of information about the robot -- its name, how much life it has, where it is, where it's heading, how fast it's going, etc.&lt;br /&gt;
&lt;br /&gt;
However, since this is a simple robot, we're not going to look at any of that stuff. Let's just fire!&lt;br /&gt;
&lt;br /&gt;
== Compile your robot ==&lt;br /&gt;
First, save your robot by selecting the '''Save''' in the '''File''' menu. Follow the prompts to save your robot.&lt;br /&gt;
&lt;br /&gt;
Now, compile it by selecting '''Compile''' in the '''Compiler''' menu.&lt;br /&gt;
&lt;br /&gt;
If your robot compiles without any errors, you can start a new battle with your robot. Start a new battle by selecting '''New''' in the '''Battle''' menu. If you cannot see your robot, you might have to refresh the list of robots by '''pressing F5'''. Add your robot to the battle together with at least one other robot as e.g. sample.Target, and press the '''Start Battle''' button to let the games begin!&lt;br /&gt;
&lt;br /&gt;
== What's next? ==&lt;br /&gt;
You should have a look at all the sample robots to see how certain things are done.&lt;br /&gt;
&lt;br /&gt;
You'll eventually want to look at the [http://robocode.sourceforge.net/docs/robocode/ Robocode API] to see all the other things your robot can do.&lt;br /&gt;
&lt;br /&gt;
Above all, good luck, have fun, and enjoy!&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
=== Robot API ===&lt;br /&gt;
* [http://robocode.sourceforge.net/docs/robocode/ Robot API]&lt;br /&gt;
&lt;br /&gt;
=== Tutorials ===&lt;br /&gt;
* [[Robocode/System Requirements|System Requirements for Robocode]]&lt;br /&gt;
* [[Robocode/Download|How to download and install Robocode]]&lt;br /&gt;
* [[Robocode/Robot Anatomy|The anatomy of a robot]]&lt;br /&gt;
* [[Robocode/Getting Started|Getting started with Robocode]]&lt;br /&gt;
* [[Robocode/Game Physics|Robocode Game Physics]]&lt;br /&gt;
* [[Robocode/Scoring|Scoring in Robocode]]&lt;br /&gt;
* [[Robocode/Robot Console|Using the robot console]]&lt;br /&gt;
* [[Robocode/Downloading_Robots|Downloading other robots]]&lt;br /&gt;
* [[Robocode/Learning from Robots|Learning from other robots]]&lt;br /&gt;
* [[Robocode/Package Robot|Package your robot]]&lt;br /&gt;
* [[Robocode/FAQ|Frequently Asked Questions (FAQ)]]&lt;br /&gt;
* [[Robocode/Articles|Articles about Robocode]]&lt;br /&gt;
* [[Robocode/Console Usage|Starting Robocode from the command line]]&lt;br /&gt;
* [[Robocode/Graphical_Debugging|Graphical debugging]]&lt;br /&gt;
* [[Robocode/Eclipse|Using Eclipse as IDE]]&lt;br /&gt;
* [[Robocode/Eclipse/Create_a_Project|Creating a project for your robots]]&lt;br /&gt;
* [[Robocode/Eclipse/Create_a_Robot|Creating a robot in Eclipse]]&lt;br /&gt;
* [[Robocode/Running from Eclipse|Running your robot from Eclipse]]&lt;br /&gt;
* [[Robocode/Eclipse/Debugging Robot|Debugging your robot with Eclipse]]&lt;br /&gt;
&lt;br /&gt;
=== News and Releases ===&lt;br /&gt;
* [http://sourceforge.net/export/rss2_project.php?group_id=37202 RSS Feeds for the Robocode project]&lt;br /&gt;
* [http://sourceforge.net/project/showfiles.php?group_id=37202&amp;amp;package_id=29609 Robocode file releases]&lt;br /&gt;
&lt;br /&gt;
=== Home pages ===&lt;br /&gt;
* [http://robocode.sourceforge.net/ Classic homepage]&lt;br /&gt;
* [http://sourceforge.net/projects/robocode Robocode project at SourceForge]&lt;br /&gt;
* [http://robocoderepository.com/ Robocode Repository]&lt;br /&gt;
* [[wikipedia:Robocode|Wikipediaentry for Robocode]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Robocode Documentation]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Tonnetz</name></author>
		
	</entry>
	<entry>
		<id>http://robowiki.net/w/index.php?title=Robocode/Game_Physics&amp;diff=33948</id>
		<title>Robocode/Game Physics</title>
		<link rel="alternate" type="text/html" href="http://robowiki.net/w/index.php?title=Robocode/Game_Physics&amp;diff=33948"/>
		<updated>2014-11-20T06:25:43Z</updated>

		<summary type="html">&lt;p&gt;Tonnetz: /* Robocode Processing Loop */ Wording rework&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the game physics of [[Robocode]].&lt;br /&gt;
&lt;br /&gt;
== Coordinates and Direction Conventions ==&lt;br /&gt;
{|border=&amp;quot;0&amp;quot; style=&amp;quot;text-align:left&amp;quot;&lt;br /&gt;
! Coordinates System:&lt;br /&gt;
| [[Robocode]] is using the [http://en.wikipedia.org/wiki/Cartesian_coordinate_system Cartesian Coordinate System], which means that that the (0, 0) coordinate is located in the bottom left of the battle field.&lt;br /&gt;
|-&lt;br /&gt;
! Clockwise Direction:&lt;br /&gt;
| [[Robocode]] is using a clockwise direction convention where 0 / 360 deg is towards &amp;quot;North&amp;quot;, 90 deg towards &amp;quot;East&amp;quot;, 180 deg towards &amp;quot;South&amp;quot;, and 270 deg towards &amp;quot;West&amp;quot;.&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
Figure 1:&lt;br /&gt;
http://www.ibm.com/developerworks/java/library/j-robocode2/fig2.gif&lt;br /&gt;
&lt;br /&gt;
== Time and distance measurements in Robocode ==&lt;br /&gt;
{|border=&amp;quot;0&amp;quot; style=&amp;quot;text-align:left&amp;quot;&lt;br /&gt;
! Time (t):&lt;br /&gt;
| Robocode time is measured in &amp;quot;ticks&amp;quot;. Each robot gets one turn per tick. 1 tick = 1 turn.&lt;br /&gt;
|-&lt;br /&gt;
! Distance Measurement:&lt;br /&gt;
| Robocode's units are basically measured in pixels, with two exceptions. First, all distances are measured with ''double'' precision, so you can actually move a fraction of a pixel. Second, Robocode automatically scales down battles to fit on the screen. In this case, the unit of distance is actually smaller than a pixel.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Robot Movement Physics ==&lt;br /&gt;
{|border=&amp;quot;0&amp;quot; style=&amp;quot;text-align:left&amp;quot;&lt;br /&gt;
! Acceleration (a):&lt;br /&gt;
| Robots accelerate at the rate of 1 pixel/turn/turn. Robots decelerate at the rate of 2 pixels/turn/turn. Robocode determines acceleration for you, based on the distance you are trying to move.&lt;br /&gt;
|-&lt;br /&gt;
! Velocity Equation(v):&lt;br /&gt;
| v = at. Velocity can never exceed 8 pixels/turn. Note that technically, velocity is a vector, but in Robocode we simply assume the direction of the vector to be the robot's heading.&lt;br /&gt;
|-&lt;br /&gt;
! Distance Equation (d):&lt;br /&gt;
| d = vt. That is, distance = velocity * time&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Robot, Gun, and Radar rotation ==&lt;br /&gt;
{|border=&amp;quot;0&amp;quot; style=&amp;quot;text-align:left&amp;quot;&lt;br /&gt;
! Max rate of rotation of robot:&lt;br /&gt;
| (10 - 0.75 * abs(velocity)) deg / turn. The faster you're moving, the slower you turn.&lt;br /&gt;
|-&lt;br /&gt;
! Max rate of rotation of gun:&lt;br /&gt;
| 20 deg / turn. This is added to the current rate of rotation of the robot.&lt;br /&gt;
|-&lt;br /&gt;
! Max rate of rotation of radar:&lt;br /&gt;
| 45 deg / turn. This is added to the current rate of rotation of the gun.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Bullets ==&lt;br /&gt;
{|border=&amp;quot;0&amp;quot; style=&amp;quot;text-align:left&amp;quot;&lt;br /&gt;
! Damage:&lt;br /&gt;
| 4 * firepower. If firepower &amp;gt; 1, it does an additional damage = 2 * (power - 1).&lt;br /&gt;
|-&lt;br /&gt;
! Velocity:&lt;br /&gt;
| 20 - 3 * firepower.&lt;br /&gt;
|-&lt;br /&gt;
! GunHeat generated:&lt;br /&gt;
| 1 + firepower / 5. You cannot fire if gunHeat &amp;gt; 0. All guns are hot at the start of each round.&lt;br /&gt;
|-&lt;br /&gt;
! Power returned on hit:&lt;br /&gt;
| 3 * firepower. &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Collisions ==&lt;br /&gt;
{|border=&amp;quot;0&amp;quot; style=&amp;quot;text-align:left&amp;quot;&lt;br /&gt;
! With Another Robot:&lt;br /&gt;
| Each robot takes 0.6 damage. If a robot is moving away from the collision, it will not be stopped.&lt;br /&gt;
|-&lt;br /&gt;
! With a Wall:&lt;br /&gt;
| [[AdvancedRobot]]s take abs(velocity) * 0.5 - 1; (Never &amp;lt; 0).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Robocode Processing Loop ==&lt;br /&gt;
The order that Robocode runs is as follows: &lt;br /&gt;
&lt;br /&gt;
# Battle view is (re)painted.&lt;br /&gt;
# All robots execute their code until they take action (and then paused).&lt;br /&gt;
# Time is updated (time = time + 1).&lt;br /&gt;
# All bullets move and check for collisions. This includes firing bullets.&lt;br /&gt;
# All robots move (gun, radar, heading, acceleration, velocity, distance, in that order).&lt;br /&gt;
# All robots perform scans (and collect team messages).&lt;br /&gt;
# All robots are resumed to take new action.&lt;br /&gt;
# Each robot processes its event queue.&lt;br /&gt;
&lt;br /&gt;
Most of this can be gleamed by following the method calls from BaseBattle.runRound() and Battle.runTurn() in the robocode.battle module.&lt;br /&gt;
&lt;br /&gt;
Event dispatch happens from within commands that take a turn.  So the call stack when an event is delivered usually looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;Robocode internals → Robot's run method → Robocode internals → Event handler&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However, event handlers can themselves make calls that take turns.  If one of these happens to generate an event, we might suspect a call stack like&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;Robocode internals → Robot's run method → Robocode internals → First event handler → Robocode internals → Second event handler&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But this kind of nesting could lead to a stack overflow.  Or—more commonly—cases where the first handler finishes up its actions long after the response-provoking situation has passed.  Thus, Robocode takes special steps for events generated within event handlers; these measures are implemented in EventManager.processEvents().  In particular, the call stack will get as far as&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;Robocode internals → Robot's run method → Robocode internals (including processEvents) → First event handler → Robocode internals (including processEvents)&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
but then the inner processEvents will detect the impending nesting and throw an EventInterruptedException, which unwinds the stack to the catch block in the outer processEvents:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;Robocode internals → Robot's run method → Robocode internals (including processEvents)&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
effectively canceling whatever the running event handler was up to.  Next, the event-delivering loop in the outer processEvents resumes delivering events, letting the second event handler execute unnested:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;Robocode internals → Robot's run method → Robocode internals → Second event handler&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is possible, though not usually useful, to catch and respond to EventInterruptedExceptions in the first handler instead.&lt;br /&gt;
&lt;br /&gt;
=== Firing Pitfall ===&lt;br /&gt;
Because bullets are fired before the gun is moved, calling setFire() will cause the bullet to leave at the current gun heading. This may seem counter-intuitive if you are used to thinking in terms of pointing a gun, then shooting. It is also inconvenient because you can't call &amp;lt;code&amp;gt;setTurnGun(...)&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;setFire(...)&amp;lt;/code&amp;gt; right after each other (not if you need perfect accuracy, anyway). Most of the time, the error will be so small you won't notice it, but if you're testing a pattern matcher against &amp;lt;code&amp;gt;sample.Walls&amp;lt;/code&amp;gt;, you will occasionally spot the bug.&lt;br /&gt;
&lt;br /&gt;
To get the bullet to leave after turning the gun, you will need to use code like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
long fireTime = 0;&lt;br /&gt;
void doGun() {&lt;br /&gt;
    if (fireTime == getTime() &amp;amp;&amp;amp; getGunTurnRemaining() == 0) {&lt;br /&gt;
        setFire(2);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    // ... aiming code ...&lt;br /&gt;
&lt;br /&gt;
    setTurnGunRight(...);&lt;br /&gt;
    // Don't need to check whether gun turn will complete in single turn because&lt;br /&gt;
    // we check that gun is finished turning before calling setFire(...).&lt;br /&gt;
    // This is simpler since the precise angle your gun can move in one tick&lt;br /&gt;
    // depends on where your robot is turning.&lt;br /&gt;
    fireTime = getTime() + 1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
=== Robot API ===&lt;br /&gt;
* [http://robocode.sourceforge.net/docs/robocode/ Robot API]&lt;br /&gt;
&lt;br /&gt;
=== Tutorials ===&lt;br /&gt;
* [[Robocode/System Requirements|System Requirements for Robocode]]&lt;br /&gt;
* [[Robocode/Download|How to download and install Robocode]]&lt;br /&gt;
* [[Robocode/Robot Anatomy|The anatomy of a robot]]&lt;br /&gt;
* [[Robocode/Getting Started|Getting started with Robocode]]&lt;br /&gt;
* [[Robocode/My First Robot|My First Robot Tutorial]]&lt;br /&gt;
* [[Robocode/Scoring|Scoring in Robocode]]&lt;br /&gt;
* [[Robocode/Robot Console|Using the robot console]]&lt;br /&gt;
* [[Robocode/Downloading_Robots|Downloading other robots]]&lt;br /&gt;
* [[Robocode/Learning from Robots|Learning from other robots]]&lt;br /&gt;
* [[Robocode/Package Robot|Package your robot]]&lt;br /&gt;
* [[Robocode/FAQ|Frequently Asked Questions (FAQ)]]&lt;br /&gt;
* [[Robocode/Articles|Articles about Robocode]]&lt;br /&gt;
* [[Robocode/Console Usage|Starting Robocode from the command line]]&lt;br /&gt;
* [[Robocode/Graphical_Debugging|Graphical debugging]]&lt;br /&gt;
* [[Robocode/Eclipse|Using Eclipse as IDE]]&lt;br /&gt;
* [[Robocode/Eclipse/Create_a_Project|Creating a project for your robots]]&lt;br /&gt;
* [[Robocode/Eclipse/Create_a_Robot|Creating a robot in Eclipse]]&lt;br /&gt;
* [[Robocode/Running from Eclipse|Running your robot from Eclipse]]&lt;br /&gt;
* [[Robocode/Eclipse/Debugging Robot|Debugging your robot with Eclipse]]&lt;br /&gt;
&lt;br /&gt;
=== News and Releases ===&lt;br /&gt;
* [http://sourceforge.net/export/rss2_project.php?group_id=37202 RSS Feeds for the Robocode project]&lt;br /&gt;
* [http://sourceforge.net/project/showfiles.php?group_id=37202&amp;amp;package_id=29609 Robocode file releases]&lt;br /&gt;
&lt;br /&gt;
=== Home pages ===&lt;br /&gt;
* [http://robocode.sourceforge.net/ Classic homepage]&lt;br /&gt;
* [http://sourceforge.net/projects/robocode Robocode project at SourceForge]&lt;br /&gt;
* [http://robocoderepository.com/ Robocode Repository]&lt;br /&gt;
* [[wikipedia:Robocode|Wikipediaentry for Robocode]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Robocode Documentation]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Tonnetz</name></author>
		
	</entry>
	<entry>
		<id>http://robowiki.net/w/index.php?title=Robocode/Game_Physics&amp;diff=33947</id>
		<title>Robocode/Game Physics</title>
		<link rel="alternate" type="text/html" href="http://robowiki.net/w/index.php?title=Robocode/Game_Physics&amp;diff=33947"/>
		<updated>2014-11-20T06:14:48Z</updated>

		<summary type="html">&lt;p&gt;Tonnetz: /* Robocode Processing Loop */ Formatting cleanup&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the game physics of [[Robocode]].&lt;br /&gt;
&lt;br /&gt;
== Coordinates and Direction Conventions ==&lt;br /&gt;
{|border=&amp;quot;0&amp;quot; style=&amp;quot;text-align:left&amp;quot;&lt;br /&gt;
! Coordinates System:&lt;br /&gt;
| [[Robocode]] is using the [http://en.wikipedia.org/wiki/Cartesian_coordinate_system Cartesian Coordinate System], which means that that the (0, 0) coordinate is located in the bottom left of the battle field.&lt;br /&gt;
|-&lt;br /&gt;
! Clockwise Direction:&lt;br /&gt;
| [[Robocode]] is using a clockwise direction convention where 0 / 360 deg is towards &amp;quot;North&amp;quot;, 90 deg towards &amp;quot;East&amp;quot;, 180 deg towards &amp;quot;South&amp;quot;, and 270 deg towards &amp;quot;West&amp;quot;.&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
Figure 1:&lt;br /&gt;
http://www.ibm.com/developerworks/java/library/j-robocode2/fig2.gif&lt;br /&gt;
&lt;br /&gt;
== Time and distance measurements in Robocode ==&lt;br /&gt;
{|border=&amp;quot;0&amp;quot; style=&amp;quot;text-align:left&amp;quot;&lt;br /&gt;
! Time (t):&lt;br /&gt;
| Robocode time is measured in &amp;quot;ticks&amp;quot;. Each robot gets one turn per tick. 1 tick = 1 turn.&lt;br /&gt;
|-&lt;br /&gt;
! Distance Measurement:&lt;br /&gt;
| Robocode's units are basically measured in pixels, with two exceptions. First, all distances are measured with ''double'' precision, so you can actually move a fraction of a pixel. Second, Robocode automatically scales down battles to fit on the screen. In this case, the unit of distance is actually smaller than a pixel.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Robot Movement Physics ==&lt;br /&gt;
{|border=&amp;quot;0&amp;quot; style=&amp;quot;text-align:left&amp;quot;&lt;br /&gt;
! Acceleration (a):&lt;br /&gt;
| Robots accelerate at the rate of 1 pixel/turn/turn. Robots decelerate at the rate of 2 pixels/turn/turn. Robocode determines acceleration for you, based on the distance you are trying to move.&lt;br /&gt;
|-&lt;br /&gt;
! Velocity Equation(v):&lt;br /&gt;
| v = at. Velocity can never exceed 8 pixels/turn. Note that technically, velocity is a vector, but in Robocode we simply assume the direction of the vector to be the robot's heading.&lt;br /&gt;
|-&lt;br /&gt;
! Distance Equation (d):&lt;br /&gt;
| d = vt. That is, distance = velocity * time&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Robot, Gun, and Radar rotation ==&lt;br /&gt;
{|border=&amp;quot;0&amp;quot; style=&amp;quot;text-align:left&amp;quot;&lt;br /&gt;
! Max rate of rotation of robot:&lt;br /&gt;
| (10 - 0.75 * abs(velocity)) deg / turn. The faster you're moving, the slower you turn.&lt;br /&gt;
|-&lt;br /&gt;
! Max rate of rotation of gun:&lt;br /&gt;
| 20 deg / turn. This is added to the current rate of rotation of the robot.&lt;br /&gt;
|-&lt;br /&gt;
! Max rate of rotation of radar:&lt;br /&gt;
| 45 deg / turn. This is added to the current rate of rotation of the gun.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Bullets ==&lt;br /&gt;
{|border=&amp;quot;0&amp;quot; style=&amp;quot;text-align:left&amp;quot;&lt;br /&gt;
! Damage:&lt;br /&gt;
| 4 * firepower. If firepower &amp;gt; 1, it does an additional damage = 2 * (power - 1).&lt;br /&gt;
|-&lt;br /&gt;
! Velocity:&lt;br /&gt;
| 20 - 3 * firepower.&lt;br /&gt;
|-&lt;br /&gt;
! GunHeat generated:&lt;br /&gt;
| 1 + firepower / 5. You cannot fire if gunHeat &amp;gt; 0. All guns are hot at the start of each round.&lt;br /&gt;
|-&lt;br /&gt;
! Power returned on hit:&lt;br /&gt;
| 3 * firepower. &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Collisions ==&lt;br /&gt;
{|border=&amp;quot;0&amp;quot; style=&amp;quot;text-align:left&amp;quot;&lt;br /&gt;
! With Another Robot:&lt;br /&gt;
| Each robot takes 0.6 damage. If a robot is moving away from the collision, it will not be stopped.&lt;br /&gt;
|-&lt;br /&gt;
! With a Wall:&lt;br /&gt;
| [[AdvancedRobot]]s take abs(velocity) * 0.5 - 1; (Never &amp;lt; 0).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Robocode Processing Loop ==&lt;br /&gt;
The order that Robocode runs is as follows: &lt;br /&gt;
&lt;br /&gt;
# Battle view is (re)painted.&lt;br /&gt;
# All robots execute their code until they take action (and then paused).&lt;br /&gt;
# Time is updated (time = time + 1).&lt;br /&gt;
# All bullets move and check for collisions. This includes firing bullets.&lt;br /&gt;
# All robots move (gun, radar, heading, acceleration, velocity, distance, in that order).&lt;br /&gt;
# All robots perform scans (and collect team messages).&lt;br /&gt;
# All robots are resumed to take new action.&lt;br /&gt;
# Each robot processes its event queue.&lt;br /&gt;
&lt;br /&gt;
Most of this can be gleamed by following the method calls from BaseBattle.runRound() and Battle.runTurn() in the robocode.battle module.&lt;br /&gt;
&lt;br /&gt;
Event dispatch happens from within commands that take a turn.  So the call stack&lt;br /&gt;
when an event is delivered usually looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;Robocode internals → Robot's run method → Robocode internals → Event handler&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However, event handlers can themselves make calls that take turns.  If one of&lt;br /&gt;
these happens to generate an event, we might suspect a call stack like&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;Robocode internals → Robot's run method → Robocode internals → First event handler → Robocode internals → Second event handler&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But, as this could lead to a stack overflow or even just undesirable robot&lt;br /&gt;
behavior, Robocode takes special steps for events generated within event&lt;br /&gt;
handlers; these measures are implemented in EventManager.processEvents().  In&lt;br /&gt;
particular, the call stack will get as far as&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;Robocode internals → Robot's run method → Robocode internals → First event handler → Robocode internals&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
until processEvents detects the impending nesting and throws an&lt;br /&gt;
EventInterruptedException, which unwinds the stack to&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;Robocode internals → Robot's run method → Robocode internals&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
effectively canceling whatever the running event handler was up to.  The outer&lt;br /&gt;
event loop catches the exception and resumes delivering events, letting the&lt;br /&gt;
second event handler execute unnested:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;Robocode internals → Robot's run method → Robocode internals → Second event handler&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Firing Pitfall ===&lt;br /&gt;
Because bullets are fired before the gun is moved, calling setFire() will cause the bullet to leave at the current gun heading. This may seem counter-intuitive if you are used to thinking in terms of pointing a gun, then shooting. It is also inconvenient because you can't call &amp;lt;code&amp;gt;setTurnGun(...)&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;setFire(...)&amp;lt;/code&amp;gt; right after each other (not if you need perfect accuracy, anyway). Most of the time, the error will be so small you won't notice it, but if you're testing a pattern matcher against &amp;lt;code&amp;gt;sample.Walls&amp;lt;/code&amp;gt;, you will occasionally spot the bug.&lt;br /&gt;
&lt;br /&gt;
To get the bullet to leave after turning the gun, you will need to use code like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
long fireTime = 0;&lt;br /&gt;
void doGun() {&lt;br /&gt;
    if (fireTime == getTime() &amp;amp;&amp;amp; getGunTurnRemaining() == 0) {&lt;br /&gt;
        setFire(2);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    // ... aiming code ...&lt;br /&gt;
&lt;br /&gt;
    setTurnGunRight(...);&lt;br /&gt;
    // Don't need to check whether gun turn will complete in single turn because&lt;br /&gt;
    // we check that gun is finished turning before calling setFire(...).&lt;br /&gt;
    // This is simpler since the precise angle your gun can move in one tick&lt;br /&gt;
    // depends on where your robot is turning.&lt;br /&gt;
    fireTime = getTime() + 1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
=== Robot API ===&lt;br /&gt;
* [http://robocode.sourceforge.net/docs/robocode/ Robot API]&lt;br /&gt;
&lt;br /&gt;
=== Tutorials ===&lt;br /&gt;
* [[Robocode/System Requirements|System Requirements for Robocode]]&lt;br /&gt;
* [[Robocode/Download|How to download and install Robocode]]&lt;br /&gt;
* [[Robocode/Robot Anatomy|The anatomy of a robot]]&lt;br /&gt;
* [[Robocode/Getting Started|Getting started with Robocode]]&lt;br /&gt;
* [[Robocode/My First Robot|My First Robot Tutorial]]&lt;br /&gt;
* [[Robocode/Scoring|Scoring in Robocode]]&lt;br /&gt;
* [[Robocode/Robot Console|Using the robot console]]&lt;br /&gt;
* [[Robocode/Downloading_Robots|Downloading other robots]]&lt;br /&gt;
* [[Robocode/Learning from Robots|Learning from other robots]]&lt;br /&gt;
* [[Robocode/Package Robot|Package your robot]]&lt;br /&gt;
* [[Robocode/FAQ|Frequently Asked Questions (FAQ)]]&lt;br /&gt;
* [[Robocode/Articles|Articles about Robocode]]&lt;br /&gt;
* [[Robocode/Console Usage|Starting Robocode from the command line]]&lt;br /&gt;
* [[Robocode/Graphical_Debugging|Graphical debugging]]&lt;br /&gt;
* [[Robocode/Eclipse|Using Eclipse as IDE]]&lt;br /&gt;
* [[Robocode/Eclipse/Create_a_Project|Creating a project for your robots]]&lt;br /&gt;
* [[Robocode/Eclipse/Create_a_Robot|Creating a robot in Eclipse]]&lt;br /&gt;
* [[Robocode/Running from Eclipse|Running your robot from Eclipse]]&lt;br /&gt;
* [[Robocode/Eclipse/Debugging Robot|Debugging your robot with Eclipse]]&lt;br /&gt;
&lt;br /&gt;
=== News and Releases ===&lt;br /&gt;
* [http://sourceforge.net/export/rss2_project.php?group_id=37202 RSS Feeds for the Robocode project]&lt;br /&gt;
* [http://sourceforge.net/project/showfiles.php?group_id=37202&amp;amp;package_id=29609 Robocode file releases]&lt;br /&gt;
&lt;br /&gt;
=== Home pages ===&lt;br /&gt;
* [http://robocode.sourceforge.net/ Classic homepage]&lt;br /&gt;
* [http://sourceforge.net/projects/robocode Robocode project at SourceForge]&lt;br /&gt;
* [http://robocoderepository.com/ Robocode Repository]&lt;br /&gt;
* [[wikipedia:Robocode|Wikipediaentry for Robocode]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Robocode Documentation]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Tonnetz</name></author>
		
	</entry>
	<entry>
		<id>http://robowiki.net/w/index.php?title=Robocode/Game_Physics&amp;diff=33946</id>
		<title>Robocode/Game Physics</title>
		<link rel="alternate" type="text/html" href="http://robowiki.net/w/index.php?title=Robocode/Game_Physics&amp;diff=33946"/>
		<updated>2014-11-20T00:04:40Z</updated>

		<summary type="html">&lt;p&gt;Tonnetz: /* Robocode Processing Loop */ Explained event handler cancellation&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the game physics of [[Robocode]].&lt;br /&gt;
&lt;br /&gt;
== Coordinates and Direction Conventions ==&lt;br /&gt;
{|border=&amp;quot;0&amp;quot; style=&amp;quot;text-align:left&amp;quot;&lt;br /&gt;
! Coordinates System:&lt;br /&gt;
| [[Robocode]] is using the [http://en.wikipedia.org/wiki/Cartesian_coordinate_system Cartesian Coordinate System], which means that that the (0, 0) coordinate is located in the bottom left of the battle field.&lt;br /&gt;
|-&lt;br /&gt;
! Clockwise Direction:&lt;br /&gt;
| [[Robocode]] is using a clockwise direction convention where 0 / 360 deg is towards &amp;quot;North&amp;quot;, 90 deg towards &amp;quot;East&amp;quot;, 180 deg towards &amp;quot;South&amp;quot;, and 270 deg towards &amp;quot;West&amp;quot;.&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
Figure 1:&lt;br /&gt;
http://www.ibm.com/developerworks/java/library/j-robocode2/fig2.gif&lt;br /&gt;
&lt;br /&gt;
== Time and distance measurements in Robocode ==&lt;br /&gt;
{|border=&amp;quot;0&amp;quot; style=&amp;quot;text-align:left&amp;quot;&lt;br /&gt;
! Time (t):&lt;br /&gt;
| Robocode time is measured in &amp;quot;ticks&amp;quot;. Each robot gets one turn per tick. 1 tick = 1 turn.&lt;br /&gt;
|-&lt;br /&gt;
! Distance Measurement:&lt;br /&gt;
| Robocode's units are basically measured in pixels, with two exceptions. First, all distances are measured with ''double'' precision, so you can actually move a fraction of a pixel. Second, Robocode automatically scales down battles to fit on the screen. In this case, the unit of distance is actually smaller than a pixel.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Robot Movement Physics ==&lt;br /&gt;
{|border=&amp;quot;0&amp;quot; style=&amp;quot;text-align:left&amp;quot;&lt;br /&gt;
! Acceleration (a):&lt;br /&gt;
| Robots accelerate at the rate of 1 pixel/turn/turn. Robots decelerate at the rate of 2 pixels/turn/turn. Robocode determines acceleration for you, based on the distance you are trying to move.&lt;br /&gt;
|-&lt;br /&gt;
! Velocity Equation(v):&lt;br /&gt;
| v = at. Velocity can never exceed 8 pixels/turn. Note that technically, velocity is a vector, but in Robocode we simply assume the direction of the vector to be the robot's heading.&lt;br /&gt;
|-&lt;br /&gt;
! Distance Equation (d):&lt;br /&gt;
| d = vt. That is, distance = velocity * time&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Robot, Gun, and Radar rotation ==&lt;br /&gt;
{|border=&amp;quot;0&amp;quot; style=&amp;quot;text-align:left&amp;quot;&lt;br /&gt;
! Max rate of rotation of robot:&lt;br /&gt;
| (10 - 0.75 * abs(velocity)) deg / turn. The faster you're moving, the slower you turn.&lt;br /&gt;
|-&lt;br /&gt;
! Max rate of rotation of gun:&lt;br /&gt;
| 20 deg / turn. This is added to the current rate of rotation of the robot.&lt;br /&gt;
|-&lt;br /&gt;
! Max rate of rotation of radar:&lt;br /&gt;
| 45 deg / turn. This is added to the current rate of rotation of the gun.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Bullets ==&lt;br /&gt;
{|border=&amp;quot;0&amp;quot; style=&amp;quot;text-align:left&amp;quot;&lt;br /&gt;
! Damage:&lt;br /&gt;
| 4 * firepower. If firepower &amp;gt; 1, it does an additional damage = 2 * (power - 1).&lt;br /&gt;
|-&lt;br /&gt;
! Velocity:&lt;br /&gt;
| 20 - 3 * firepower.&lt;br /&gt;
|-&lt;br /&gt;
! GunHeat generated:&lt;br /&gt;
| 1 + firepower / 5. You cannot fire if gunHeat &amp;gt; 0. All guns are hot at the start of each round.&lt;br /&gt;
|-&lt;br /&gt;
! Power returned on hit:&lt;br /&gt;
| 3 * firepower. &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Collisions ==&lt;br /&gt;
{|border=&amp;quot;0&amp;quot; style=&amp;quot;text-align:left&amp;quot;&lt;br /&gt;
! With Another Robot:&lt;br /&gt;
| Each robot takes 0.6 damage. If a robot is moving away from the collision, it will not be stopped.&lt;br /&gt;
|-&lt;br /&gt;
! With a Wall:&lt;br /&gt;
| [[AdvancedRobot]]s take abs(velocity) * 0.5 - 1; (Never &amp;lt; 0).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Robocode Processing Loop ==&lt;br /&gt;
The order that Robocode runs is as follows: &lt;br /&gt;
&lt;br /&gt;
# Battle view is (re)painted.&lt;br /&gt;
# All robots execute their code until they take action (and then paused).&lt;br /&gt;
# Time is updated (time = time + 1).&lt;br /&gt;
# All bullets move and check for collisions. This includes firing bullets.&lt;br /&gt;
# All robots move (gun, radar, heading, acceleration, velocity, distance, in that order).&lt;br /&gt;
# All robots perform scans (and collect team messages).&lt;br /&gt;
# All robots are resumed to take new action.&lt;br /&gt;
# Each robot processes its event queue.&lt;br /&gt;
&lt;br /&gt;
Most of this can be gleamed by following the method calls from BaseBattle.runRound() and Battle.runTurn() in the robocode.battle module.&lt;br /&gt;
&lt;br /&gt;
Event dispatch happens from within commands that take a turn.  So the call stack&lt;br /&gt;
when an event is delivered usually looks like this:&lt;br /&gt;
&lt;br /&gt;
    Robocode internals → Robot's run method → Robocode internals → Event handler&lt;br /&gt;
&lt;br /&gt;
However, event handlers can themselves make calls that take turns.  If one of&lt;br /&gt;
these happens to generate an event, we might suspect a call stack like&lt;br /&gt;
&lt;br /&gt;
    Robocode internals → Robot's run method → Robocode internals → First event handler → Robocode internals → Second event handler&lt;br /&gt;
&lt;br /&gt;
But, as this could lead to a stack overflow or even just undesirable robot&lt;br /&gt;
behavior, Robocode takes special steps for events generated within event&lt;br /&gt;
handlers; these measures are implemented in EventManager.processEvents().  In&lt;br /&gt;
particular, the call stack will get as far as&lt;br /&gt;
&lt;br /&gt;
    Robocode internals → Robot's run method → Robocode internals → First event handler → Robocode internals&lt;br /&gt;
&lt;br /&gt;
until processEvents detects the impending nesting and throws an&lt;br /&gt;
EventInterruptedException, which unwinds the stack to&lt;br /&gt;
&lt;br /&gt;
    Robocode internals → Robot's run method → Robocode internals&lt;br /&gt;
&lt;br /&gt;
effectively canceling whatever the running event handler was up to.  The outer&lt;br /&gt;
event loop catches the exception and resumes delivering events, letting the&lt;br /&gt;
second event handler execute unnested:&lt;br /&gt;
&lt;br /&gt;
    Robocode internals → Robot's run method → Robocode internals → Second event handler&lt;br /&gt;
&lt;br /&gt;
=== Firing Pitfall ===&lt;br /&gt;
Because bullets are fired before the gun is moved, calling setFire() will cause the bullet to leave at the current gun heading. This may seem counter-intuitive if you are used to thinking in terms of pointing a gun, then shooting. It is also inconvenient because you can't call &amp;lt;code&amp;gt;setTurnGun(...)&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;setFire(...)&amp;lt;/code&amp;gt; right after each other (not if you need perfect accuracy, anyway). Most of the time, the error will be so small you won't notice it, but if you're testing a pattern matcher against &amp;lt;code&amp;gt;sample.Walls&amp;lt;/code&amp;gt;, you will occasionally spot the bug.&lt;br /&gt;
&lt;br /&gt;
To get the bullet to leave after turning the gun, you will need to use code like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
long fireTime = 0;&lt;br /&gt;
void doGun() {&lt;br /&gt;
    if (fireTime == getTime() &amp;amp;&amp;amp; getGunTurnRemaining() == 0) {&lt;br /&gt;
        setFire(2);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    // ... aiming code ...&lt;br /&gt;
&lt;br /&gt;
    setTurnGunRight(...);&lt;br /&gt;
    // Don't need to check whether gun turn will complete in single turn because&lt;br /&gt;
    // we check that gun is finished turning before calling setFire(...).&lt;br /&gt;
    // This is simpler since the precise angle your gun can move in one tick&lt;br /&gt;
    // depends on where your robot is turning.&lt;br /&gt;
    fireTime = getTime() + 1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
=== Robot API ===&lt;br /&gt;
* [http://robocode.sourceforge.net/docs/robocode/ Robot API]&lt;br /&gt;
&lt;br /&gt;
=== Tutorials ===&lt;br /&gt;
* [[Robocode/System Requirements|System Requirements for Robocode]]&lt;br /&gt;
* [[Robocode/Download|How to download and install Robocode]]&lt;br /&gt;
* [[Robocode/Robot Anatomy|The anatomy of a robot]]&lt;br /&gt;
* [[Robocode/Getting Started|Getting started with Robocode]]&lt;br /&gt;
* [[Robocode/My First Robot|My First Robot Tutorial]]&lt;br /&gt;
* [[Robocode/Scoring|Scoring in Robocode]]&lt;br /&gt;
* [[Robocode/Robot Console|Using the robot console]]&lt;br /&gt;
* [[Robocode/Downloading_Robots|Downloading other robots]]&lt;br /&gt;
* [[Robocode/Learning from Robots|Learning from other robots]]&lt;br /&gt;
* [[Robocode/Package Robot|Package your robot]]&lt;br /&gt;
* [[Robocode/FAQ|Frequently Asked Questions (FAQ)]]&lt;br /&gt;
* [[Robocode/Articles|Articles about Robocode]]&lt;br /&gt;
* [[Robocode/Console Usage|Starting Robocode from the command line]]&lt;br /&gt;
* [[Robocode/Graphical_Debugging|Graphical debugging]]&lt;br /&gt;
* [[Robocode/Eclipse|Using Eclipse as IDE]]&lt;br /&gt;
* [[Robocode/Eclipse/Create_a_Project|Creating a project for your robots]]&lt;br /&gt;
* [[Robocode/Eclipse/Create_a_Robot|Creating a robot in Eclipse]]&lt;br /&gt;
* [[Robocode/Running from Eclipse|Running your robot from Eclipse]]&lt;br /&gt;
* [[Robocode/Eclipse/Debugging Robot|Debugging your robot with Eclipse]]&lt;br /&gt;
&lt;br /&gt;
=== News and Releases ===&lt;br /&gt;
* [http://sourceforge.net/export/rss2_project.php?group_id=37202 RSS Feeds for the Robocode project]&lt;br /&gt;
* [http://sourceforge.net/project/showfiles.php?group_id=37202&amp;amp;package_id=29609 Robocode file releases]&lt;br /&gt;
&lt;br /&gt;
=== Home pages ===&lt;br /&gt;
* [http://robocode.sourceforge.net/ Classic homepage]&lt;br /&gt;
* [http://sourceforge.net/projects/robocode Robocode project at SourceForge]&lt;br /&gt;
* [http://robocoderepository.com/ Robocode Repository]&lt;br /&gt;
* [[wikipedia:Robocode|Wikipediaentry for Robocode]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Robocode Documentation]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Tonnetz</name></author>
		
	</entry>
</feed>