Difference between revisions of "Robocode 2"

From CompSciWiki
Jump to: navigation, search
(updated creation of robot)
Line 16: Line 16:
 
Open the robot editor and create a new robot.  If you need assistance in creating a robot, see the first Robocode lab at: [[Robocode_1#Create_your_first_Robot|Robocode part 1]]
 
Open the robot editor and create a new robot.  If you need assistance in creating a robot, see the first Robocode lab at: [[Robocode_1#Create_your_first_Robot|Robocode part 1]]
  
== Move after being hit by a bullet ==
+
== Implement a method with help ==
 
+
== Move back after hitting a wall ==
+
  
 
== Add your own event based method from the robot API ==
 
== Add your own event based method from the robot API ==

Revision as of 11:39, 4 April 2012

COMP 1010 Home > Back to Extra Labs

Introduction

In this lab we will explore the Robot class more deeply and examine all of the different methods that the robot can call. You will become more familiar with the API for the Robot class. You will also explore the downloading of robots that others have created and testing your best creation against the world.

This lab will help get you comfortable using an Application Programming Interface (API). An API will have information about the way a prebuilt class can function. We will examine tghe robot class more closely than the first Robocode lab. With a short introduction, you will be able to read the API and start to understand how it works. Finally you will read the API and implement a few of the methods that it contains.

Installation

Download and run the latest version of robocode-x.x.x.x-setup.jar file from: http://sourceforge.net/projects/robocode/files/

Building starting robot

Open the robot editor and create a new robot. If you need assistance in creating a robot, see the first Robocode lab at: Robocode part 1

Implement a method with help

Add your own event based method from the robot API

Revisit the robot API at: http://robocode.sourceforge.net/docs/robocode/robocode/Robot.html

The rows listed under method summary are a list of the methods and information about them. It is important to note that most of the methods are self explanatory when you examine their names. The methods that we will be looking at for part of the lab are the ones that contain an event as part of their parameter list. Some of these events can be triggered by a user pressing a key on the keyboard or by the robot experiencing some specific act.

For example the method BulletHitBulletEvent is called whenever a robot has its bullet hit a bullet from another robot. If this method is not included in your code than nothing will happen, but if you wanted to add functionality to do something in that case, you could implement the method easily. If you wanted to back up 50 pixels when your robots' bullet hit another bullet the code would look like this:

 onBulletHitBullet(BulletHitBulletEvent event) 
{
	back(50);
} 

Your task as part of this lab is to implement 2 new event driven methods. Both of these methods will then call other action methods like back(), ahead() or fire(). Try to make your robot perform something unexpected. This could be something as easy as changing the colour of the gun barrel to performing moves to dodge incoming bullets.

Once you have implemented these two new methods, show your T.A. and test them in a battle to ensure they are doing what you intended them to.

Challenge!