<?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=Sprucenshield</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=Sprucenshield"/>
	<link rel="alternate" type="text/html" href="http://robowiki.net/wiki/Special:Contributions/Sprucenshield"/>
	<updated>2026-04-18T05:36:58Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.34.1</generator>
	<entry>
		<id>http://robowiki.net/w/index.php?title=Robocode/Game_Physics&amp;diff=36198</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=36198"/>
		<updated>2016-12-06T20:01:26Z</updated>

		<summary type="html">&lt;p&gt;Sprucenshield: grammar correction&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 see 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>Sprucenshield</name></author>
		
	</entry>
	<entry>
		<id>http://robowiki.net/w/index.php?title=Robocode/FAQ&amp;diff=36196</id>
		<title>Robocode/FAQ</title>
		<link rel="alternate" type="text/html" href="http://robowiki.net/w/index.php?title=Robocode/FAQ&amp;diff=36196"/>
		<updated>2016-12-06T16:50:05Z</updated>

		<summary type="html">&lt;p&gt;Sprucenshield: grammar correction&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Frequently asked questions about Robocode.&lt;br /&gt;
&lt;br /&gt;
== [[Robocode/Download|Installing]] and [[Robocode/Getting Started|using]] ==&lt;br /&gt;
&lt;br /&gt;
; '''I can't install Robocode.'''&lt;br /&gt;
&lt;br /&gt;
: Please see instructions at [[Robocode_Download_And_Install| download and install]] site. &lt;br /&gt;
&lt;br /&gt;
; '''I have downloaded a robot from the Web, but I don't know how to use it, because it doesn't appear anywhere.'''&lt;br /&gt;
: By default, robots are read from the &amp;lt;code&amp;gt;/robocode/robots&amp;lt;/code&amp;gt; directory. You can select &amp;quot;Robot -&amp;gt; Import Downloaded Robot&amp;quot; to copy a robot JAR to this directory from another location. Also, you can configure Robocode to read robots from additional locations using the Properties dialog.&lt;br /&gt;
&lt;br /&gt;
; '''What do I have to do to see the source code of a robot?'''&lt;br /&gt;
: You can do two things. The first option is to open the Editor Window in Robocode and use the command in the File menu. The second option is to open the robot &amp;quot;.jar&amp;quot; file with a zip utility and find the source code there (assuming, of course, the robot is open source).&lt;br /&gt;
&lt;br /&gt;
; '''Can I play Robocode online?'''&lt;br /&gt;
: Robocode is not an &amp;quot;online&amp;quot; game, so you can't, for example, share a battle with your friends in real time over the Internet. But you can upload your bots to places like [http://sites.google.com/ Google Sites] or [[RobocodeRepository|Robocode Repository]] and join any of the [[:Category:Competitions|existing competitions]] such as [[RoboRumble@Home]], or organize one with your friends.&lt;br /&gt;
&lt;br /&gt;
; '''I have seen that many bots are packaged into &amp;quot;.jar&amp;quot; files. How do I package my bot?'''&lt;br /&gt;
: Select, &amp;quot;Robot --&amp;gt; Package robot for upload&amp;quot; from the menu, then enter your robot's details when prompted.&lt;br /&gt;
&lt;br /&gt;
;''' When I test my bots, Robocode is slow. Is there a way to execute the battles faster?'''&lt;br /&gt;
: When you are testing your robot, you want to execute many battles in a short time. Minimize the Robocode main screen to make it execute the battles at full speed.&lt;br /&gt;
&lt;br /&gt;
; '''I get this error when trying to start Robocode: &amp;quot;'JAVA' is not recognized as an internal or external command, operable or batch file&amp;quot;'''&lt;br /&gt;
: This is caused by an unknown path to your Java installation. Please follow [[Robocode/System_Requirements#PATH_must_be_set|this instructions]].&lt;br /&gt;
&lt;br /&gt;
== [[Robocode/Game Physics|Game physics]] ==&lt;br /&gt;
&lt;br /&gt;
; '''What is the difference between frames and ticks?'''&lt;br /&gt;
: A tick refers to one unit, which is also called a Turn in Robocode. During one turn, you may perform one action as a Robot, or multiple (independent) actions as an AdvancedRobot. A frame is a unit of drawing to the Robocode client interface. If you are processing turns slowly, you will get one frame per tick / turn. However, if you up the turns per second beyond your computer's ability to render the frames, you will miss some frames of animation. This won't affect the robots' behavior, unless you foolishly added code in your &amp;lt;code&amp;gt;onPaint(Graphics2D)&amp;lt;/code&amp;gt; method that alters your bots behavior. In that case, your bot will behave differently depending on whether or not the Paint button has been enabled, and if the framerate can keep up with the turnrate.&lt;br /&gt;
&lt;br /&gt;
; '''Can I fire bullets with power higher than 3.0 or lower than 1.0?'''&lt;br /&gt;
:No and yes. You can't fire bullets with power greater than 3.0, but you can fire bullets with power as low as 0.1. If you call a firing function (i.e. &amp;lt;code&amp;gt;setFire()&amp;lt;/code&amp;gt;) with a value greater than 3.0, Robocode will adjust it to 3.0, and if you call it with a power lower than 0.1 (except 0.0 which will not fire) it will adjust it to 0.1. Additionally, you can fire bullets with power less than 0.1 under one condition: when your robot has less than 0.1 energy left, in which case a bullet is fired with however much energy your robot had left.&lt;br /&gt;
&lt;br /&gt;
; '''How fast does a bullet travel?'''&lt;br /&gt;
:A bullet travels at a speed between 11.0 and 19.7 depending on the power. The more powerful the bullet, the slower. The formula to calculate its &amp;lt;code&amp;gt;velocity = 20 - (3 * power)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
; '''Does the robot velocity get added to the bullet velocity on firing?'''&lt;br /&gt;
: No, bullet velocity is not affected by robot velocity. It's kind of like the speed-of-light thing. =)&lt;br /&gt;
&lt;br /&gt;
; '''Which is the range of a bullet?'''&lt;br /&gt;
: A bullet has no range. It keeps going until it hits a robot or a wall.&lt;br /&gt;
&lt;br /&gt;
; '''I want to fire a bullet every turn, but I can't. Why?'''&lt;br /&gt;
: Every time you fire, the gun generates some heat. You must wait till it is cool again to fire. If you give a fire order when your gun is hot, it will do nothing. The heat generated by a shot is &amp;lt;code&amp;gt;1 + (firepower / 5)&amp;lt;/code&amp;gt;. The gun cools down at a default rate of 0.1 per turn (note that you can change this parameter when you run the battle, but nobody usually does). It means you can fire a 3.0 power bullet every 16 ticks.&lt;br /&gt;
&lt;br /&gt;
; '''How much damage does a bullet do? How do I gain or lose energy?'''&lt;br /&gt;
: You lose energy every time you hit a wall, you are hit by an enemy bullet, ram an enemy, or you fire your gun. The amount of energy you lose by being hit is &amp;lt;code&amp;gt;4 * bullet power + 2 * max(bullet power - 1 , 0)&amp;lt;/code&amp;gt;. So the maximum amount is 16.0. When you fire, you spend a quantity of energy equal to the power of the bullet fired. When one of your bullets hits an enemy, you collect back &amp;lt;code&amp;gt;3 * bullet power&amp;lt;/code&amp;gt; energy. When you hit an enemy bot, each bot takes 0.6 damage. If an [[AdvancedRobot]] (but not a [[Robot]] or [[JuniorRobot]]) hits a wall, it will take &amp;lt;code&amp;gt;max(abs(velocity) * 0.5 - 1, 0)&amp;lt;/code&amp;gt; damage.&lt;br /&gt;
&lt;br /&gt;
; '''Some times I get disabled. What happens?'''&lt;br /&gt;
: You can't kill yourself, so when your energy drops to zero because you hit a wall or you fire, your bot gets disabled. It will not be able to move nor fire. If you are lucky enough and one of your bullets in the air hits an enemy, you will get some energy back and recover from disabled status.&lt;br /&gt;
&lt;br /&gt;
; '''I get disabled, but I my energy &amp;gt; 0. Why?'''&lt;br /&gt;
: There are a few possible causes. You may have called a getXXX() function - such as getVelocity() - too many times a turn. The limit is 10000 getXXX() function calls per turn. To avoid disabling in such situations, either store returned values in variables for future use or use a [[RobotStatus]] object obtained from [[StatusEvent]]. Another case in which you can get disabled is throwing an exception, which may disable your bot, even if you catch the exception. Also, if your bot gets stuck in an infinite (or very long) loop and skips many turns, it may also get disabled.&lt;br /&gt;
&lt;br /&gt;
; '''How fast do I move?'''&lt;br /&gt;
: You can move at a maximum speed of 8.0 units/tick. You can modify (down) your maximum velocity by using &amp;lt;code&amp;gt;setMaxVelocity(...)&amp;lt;/code&amp;gt;. Note that your bot will always accelerate to reach its maximum velocity.&lt;br /&gt;
&lt;br /&gt;
; '''How fast do I accelerate?'''&lt;br /&gt;
: You accelerate at 1 unit/tick, and you decelerate at 2 units/tick. For example, if you are moving at an speed of 8.0 and reverse your direction your velocities will be [6.0, 4.0, 2.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0].&lt;br /&gt;
&lt;br /&gt;
; '''How fast do I turn?'''&lt;br /&gt;
: The faster you go, the slower you turn. The formula to calculate it in degrees is &amp;lt;code&amp;gt;10 - 0.75 * abs(velocity)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
; '''What is the size of a bot?'''&lt;br /&gt;
: The size of a bot is 36x36. Note, this is slightly smaller than the image of the bot. It is modeled as a non rotating square, so it's always the same regardless of its heading.&lt;br /&gt;
&lt;br /&gt;
; '''It seems that Robocode doesn't follow standard physics. If my velocity is 0 and I accelerate (acceleration = 1) my final velocity is 1, but it should be 0.5. What happened?'''&lt;br /&gt;
: Time in Robocode, rather than being continuous, is in discrete &amp;quot;ticks&amp;quot;. First acceleration is calculated, then velocity, and then position. So if you are stopped at a position 0 and you accelerate 1, your velocity next turn will be 1 and your position also 1.&lt;br /&gt;
&lt;br /&gt;
; '''How can I detect when an enemy has fired?'''&lt;br /&gt;
: There is no direct way to detect when an enemy fired, but you can deduce it by monitoring the enemy energy drop. A drop between 0.1 and 3 usually means that it fired a bullet (there can be other reasons, such as a low energy bullet hit or a wall hit). Wall hits are (more or less) detectable as well. A deceleration &amp;gt; 2 means the bot hit a wall (or another bot). A deceleration &amp;lt;= 2 may be simple a bot hitting the brakes, or hitting a wall at velocity = 2, but since hitting a wall at that speed won't cause any damage, you can ignore that. AdvancedRobots take &amp;lt;code&amp;gt;abs(velocity) / 2 - 1 (Never &amp;lt; 0)&amp;lt;/code&amp;gt; damage when hitting a wall, so by detecting (significant) wall-hits and adjusting the enemy drop accordingly, wall hits can be filtered out most of the time. This method fails when the enemy hits another robot.&lt;br /&gt;
&lt;br /&gt;
; '''How can I detect the position and heading of an enemy bullet?'''&lt;br /&gt;
: You can't. There is no way to know it, directly or indirectly. But of course, you can always [[GuessFactor|guess]]...&lt;br /&gt;
&lt;br /&gt;
; '''How fast can I turn my gun?'''&lt;br /&gt;
: The gun turns at 20 degrees per tick.&lt;br /&gt;
&lt;br /&gt;
; '''How fast can I turn my radar?'''&lt;br /&gt;
: It turns 45 degrees per tick.&lt;br /&gt;
&lt;br /&gt;
; '''Can I know the heading of the enemy gun/radar?'''&lt;br /&gt;
: No.&lt;br /&gt;
&lt;br /&gt;
; '''Can I specify the initial position of my bot?'''&lt;br /&gt;
: No. The bots are randomly placed in the field at the beginning of each round.&lt;br /&gt;
&lt;br /&gt;
== Programming your robot ==&lt;br /&gt;
; '''What is the difference between the setXXX() (e.g. &amp;lt;code&amp;gt;setFire()&amp;lt;/code&amp;gt;) and the XXX() (e.g. &amp;lt;code&amp;gt;fire()&amp;lt;/code&amp;gt;) methods?'''&lt;br /&gt;
: Basically, the setXXX() methods just notify Robocode to take some action at the end of the turn. The XXX()-type methods end the turn when you call them, and they block your robot's thread until the command finishes. Unless you have a good reason, you should almost always use the setXXX() version when writing [[AdvancedRobot|AdvancedRobots]].&lt;br /&gt;
&lt;br /&gt;
; '''How can I avoid my gun/radar turning when my bot turns?'''&lt;br /&gt;
: You can use &amp;lt;code&amp;gt;setAdjustGunForRobotTurn()&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; setAdjustRadarForGunTurn()&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;setAdjustRadarForRobotTurn()&amp;lt;/code&amp;gt; methods to control this. If you call &amp;lt;code&amp;gt;setAdjustGunForRobotTurn()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt; setAdjustRadarForGunTurn()&amp;lt;/code&amp;gt;, you don't need to call &amp;lt;code&amp;gt;setAdjustRadarForRobotTurn()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
; '''Why are there two functions for &amp;lt;code&amp;gt;getBearing()&amp;lt;/code&amp;gt; for example - one in radians and one in degrees? Is there any performance gain if I use radians instead of degrees?'''&lt;br /&gt;
: There is no real advantage to using one or the other. Just use the one you prefer. Often, people start using degrees (just because they feel more comfortable with them) and later they switch to radians (because calculations are easier since you can use the built-in Java trigonometric functions). Just remember to use always radians or always degrees; mixing them up is not a good idea.&lt;br /&gt;
&lt;br /&gt;
; '''I need to trace my bots actions and variables. I saw that everybody uses &amp;lt;code&amp;gt;out.println(&amp;quot;...&amp;quot;)&amp;lt;/code&amp;gt;, but where is that printed?'''&lt;br /&gt;
: It prints to the [[Robocode/Robot Console|robot console]]. When you execute the battle, just click on the button on the right of the screen that shows the name of your robot to open its [[Robocode/Robot Console|console]].&lt;br /&gt;
&lt;br /&gt;
; '''How do you get your radar to stay focused on a robot that you have defined as your target?'''&lt;br /&gt;
: You just turn the radar the other way around when you scan the bot. You lock your radar by not turning it 45 degrees, but only the arc needed to stay focused. See the [[Radar]] page for some example code.&lt;br /&gt;
&lt;br /&gt;
; '''How can I know how many enemies are in the battle field?'''&lt;br /&gt;
: You can use the &amp;lt;code&amp;gt;getOthers()&amp;lt;/code&amp;gt; method to know how many live enemies are in the battlefield.&lt;br /&gt;
&lt;br /&gt;
; '''I'm trying to recognize an enemy/teammate from its name (using &amp;lt;code&amp;gt;e.getName()&amp;lt;/code&amp;gt;) but the condition always fails. What's happening?'''&lt;br /&gt;
: Because of Java's funky way of interpreting references to Strings (not to mention a lack of operator overloading), you can't use an expression like &amp;lt;code&amp;gt;if (e.getName() == testname)&amp;lt;/code&amp;gt; to check for equality. You have to use the &amp;lt;code&amp;gt;String.equals()&amp;lt;/code&amp;gt; method, as in &amp;lt;code&amp;gt;if (e.getName().equals(testname))&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
; '''How do I keep data from round to round and battle to battle?'''&lt;br /&gt;
: The easiest way is to save data between rounds of a battle is to make the variables in the bot class static. Because Robocode uses a separate classloader for every robot, the variables will not conflict even when you have more than one copy of a robot in a battle. Note that this will save data between ''rounds'', not between ''battles''. To save between battles you will have to save to a file. The maximum allowed disk space for files is 200k. Look at the [[:Category:Robocode API|Robocode API]] for more details.&lt;br /&gt;
&lt;br /&gt;
; '''I get the following message when I run my bot, and I don't know how to solve it.'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SYSTEM: You have made 10000 calls to getXX methods without calling execute()&lt;br /&gt;
SYSTEM: Robot disabled: Too many calls to getXX methods.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
: Robocode prevents you from calling functions like &amp;lt;code&amp;gt;getX()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;getVelocity()&amp;lt;/code&amp;gt; too many times during a single tick. So if you are using them in a long loop, it will raise this error. Actually, 95% of the time, this error is a symptom of an infinite loop in your bot. If you know you have a long-but-finite loop and you get this error, either just assign the values you want to use to a variable or use a [[RobotStatus]] object obtained from [[StatusEvent]].&lt;br /&gt;
&lt;br /&gt;
; '''I'm using &amp;lt;code&amp;gt;bulletObject = setFireBullet(power)&amp;lt;/code&amp;gt; to fire, and then I want to get the bullet coordinates. But when I try to print them using &amp;lt;code&amp;gt;System.out.println(bulletObject.getX() + bulletObject.getY())&amp;lt;/code&amp;gt; I get an error. What's wrong?'''&lt;br /&gt;
: &amp;lt;code&amp;gt;setFireBullet()&amp;lt;/code&amp;gt; creates a Bullet object, but the bullet doesn't actually leave your bots gun until the next tick, so you can't do &amp;lt;code&amp;gt;getX()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;getY()&amp;lt;/code&amp;gt; on the bullet until then. If you change it to &amp;lt;code&amp;gt;fireBullet()&amp;lt;/code&amp;gt; you should be OK, because the function won't return until the bullet is in the air. If &amp;lt;code&amp;gt;fireBullet()&amp;lt;/code&amp;gt; won't work for you, you'll have to devise another method of making sure that you don't do &amp;lt;code&amp;gt;getX()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;getY()&amp;lt;/code&amp;gt; on bullets until the turn after you fire. For example, you could store Bullets in an ArrayList, and print out their coordinates before you fire in your main loop, so that a given bullet will be added to the vector on one turn, but won't be accessed until the next turn when your main loop starts over. Alternatively, your bot can attempt to predict/simulate it's own location on the next tick, to know where the bullet will be created.&lt;br /&gt;
&lt;br /&gt;
; '''I want to reverse my direction when my movement is about to finish. I use something like &amp;lt;code&amp;gt;if (getDistanceRemaining() &amp;lt; minimum)&amp;lt;/code&amp;gt;, but the bot behaves in a strange way.'''&lt;br /&gt;
: The &amp;lt;code&amp;gt;getDistanceRemaining()&amp;lt;/code&amp;gt; method (and in general all methods returning remaining movements of the body, gun, or radar) can return a positive or a negative value, depending on the direction of your movement. Use &amp;lt;code&amp;gt;if (Math.abs(getGetDistanceRemaining()) &amp;lt; minimum)&amp;lt;/code&amp;gt; instead.&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/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/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|Wikipedia entry for Robocode]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Robocode Documentation]]&lt;/div&gt;</summary>
		<author><name>Sprucenshield</name></author>
		
	</entry>
	<entry>
		<id>http://robowiki.net/w/index.php?title=Robocode/My_First_Robot&amp;diff=36149</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=36149"/>
		<updated>2016-12-01T19:36:19Z</updated>

		<summary type="html">&lt;p&gt;Sprucenshield: /* Compile your robot */&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 '''Source 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 Ctrl + R'''. 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>Sprucenshield</name></author>
		
	</entry>
	<entry>
		<id>http://robowiki.net/w/index.php?title=Robocode/My_First_Robot&amp;diff=36148</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=36148"/>
		<updated>2016-12-01T19:23:59Z</updated>

		<summary type="html">&lt;p&gt;Sprucenshield: /* My First Robot */&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 '''Source 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>Sprucenshield</name></author>
		
	</entry>
</feed>