Presentation is loading. Please wait.

Presentation is loading. Please wait.

How does Robocode work? In short it is a framework

Similar presentations


Presentation on theme: "How does Robocode work? In short it is a framework"— Presentation transcript:

1 How does Robocode work? In short it is a framework
You write a Java class extending the robocode Your Robot is register for battle and may be inturn be invoked by the framework once registered via a callback You see the effect in the onscreen battlefield In general what is a Framework ? A Framework specifies a reusable architecture for all or part of a system May include reusable classes, patterns or templates In simple terms it can be viewed as a partially developed program – ready for customization

2 What others say? A framework is a reusable design of an application or subsystem that is represented by a set of abstract classes and the way objects of these classes collaborate [Johnson 1997]. A framework is a set of cooperating classes that make up a reusable design for a specific class of software [GoF 1994]. A framework is the skeleton of an application that can be customized by an application developer [Fayad et al 1999].

3 Some Characteristics of a Framework
Frameworks exhibit inversion of control at run-time i.e., the framework determines which objects and methods to invoke in response to events Some say that a framework follows the job interview principle we will call you, don’t call us This however is not always the case

4 Framework versus Library
Library Implementation Application Software Library Components Framework Implementation Application Software Library Components

5 Framework implementation
Framework components are loosely coupled via “callbacks” Callbacks allow independently developed software components to be connected together Callbacks provide a connection-point where generic framework objects can communicate with application objects (in your case a robot) The framework provides the common template Methods The application code provides the variant hook methods

6 Event-based architecture
The Robocode framework is based on an Event based architecture or an event driven system Event driven programming can be considered a different paradigm from procedural or OOP programming However the system is still usually made of objects

7 What is an event driven system?
An event is an occurrence of interest Events take place at a particular time An event driven system is a software system where events are a driving force Events from the user (mouse click) Internal events (variable assignment, timers) Events from other computing systems (any message arriving across the network) Or for robocode HitByBulletEvent HitWallEvent

8 Examples of Event Driven Systems
Mobile phone TV The Windows GUI What are some events associated with each of these?

9 Basic Event Driven Programming Model
Often a separate handler for each event Events generated here notifies Event Source Event Handler modifies System Objects

10 Properties What are the properties of an event driven system?
Loose Coupling between source and handler Behavior of system depends on its state System often spends much of its time in stasis Not often the case in Robocode Events occur that propagate through the system and then it returns to statis

11 Let look at theses in the API
Some Robocode Events ScannedRobotEvent Handle the ScannedRobotEvent by overriding the onScannedRobot() method; this method is called when the radar detects a robot. HitByBulletEvent Handle the HitByBulletEvent by overriding the onHitByBullet() method; this method is called when the robot is hit by a bullet. HitRobotEvent Handle the HitRobotEvent by overriding the onHitRobot() method; this method is called when your robot hits another robot. HitWallEvent Handle the HitWallEvent by overriding the onHitWall() method; this method is called when your robot hits a wall. Let look at theses in the API

12 Robocode: coding Each event class has its own set of member functions that can be called to assess details about the event ex. Calling e.getBearing() in onScannedRobot() Full info on these is available via the API Any additional classes used by your robot should be placed in the same file after your robot class

13 Robocode: basics Coords. are (x,y), with bottom left as (0,0)
Heading: degrees, straight up = 0, pos. clockwise (0 <= heading <= 360) Bearing: relative angle from your heading, pos. clockwise (-180 <= bearing <= 180) Hitting a wall or another robot ends turn Energy: costs 1 to fire, receive energy when one of your bullets hits enemy Radar is mounted on gun

14 Robocode: numbers Max velocity: 8 Accel: 1/frame, Decel: 2/frame
Max turning rate = *getVelocity() Turret turn rate = 20 degrees/frame Radar turn rate = 45 degrees/frame Damage = 4 * pwr, if pwr>1 damage+=2*(pwr-1)

15 Robocode: numbers Power = .1 to 3 Bullet speed = 20 – 3 * pwr
Heat = 1 + pwr/5 Heat dissipates at .1/frame

16 Robocode: coding public void run() {
//setColors(Color.red,Color.blue,Color.green); while(true) { // Replace the next 4 lines with any behavior ahead(100); turnGunRight(360); back(100); }

17 Robocode: coding ahead(double dist) back(double dist) fire(double pwr)
scan() turnGunLeft/Right(double degrees) turnLeft/Right(double degrees) turnRadarLeft/Right(double degrees) stop()/resume()

18 Robocode: coding Each event class has its own set of member functions that can be called to assess details about the event ex. Calling e.getBearing() in onScannedRobot()

19 Use of Events Determine what type of event object you need to handle
Determine what method is used to register interest in the event Determine what type of object needs to be passed to this method Create an object of that type Implement the methods necessary to handle the event Add the code to the methods to handle the event

20 Events Time to look at some code to get a little more understanding about what an event is

21 Example basic commands
turnRight(double degree) and turnLeft(double degree) turn the robot by a specified degree. ahead(double distance) and back(double distance) move the robot by the specified pixel distance These methods are exited if the robot hits a wall or another robot turnGunRight(double degree) and turnGunLeft(double degree) turn the gun This is independent of the vehicle's direction. turnRadarRight(double degree) and turnRadarLeft(double degree) turn the radar on top of the gun This is also independent of both the gun's direction and the vehicle's direction

22 Example basic commands
When the vehicle is turned, the direction of the gun (and radar) will also move, unless indicate differently by calling the following methods: setAdjustGunForRobotTurn(boolean flag) If the flag is set to true, the gun will remain in the same direction while the vehicle turns setAdjustRadarForRobotTurn(boolean flag) If the flag is set to true, the radar will remain in the same direction while the vehicle (and the gun) turns setAdjustRadarForGunTurn(boolean flag) If the flag is set to true, the radar will remain in the same direction while the gun turns It will also act as if setAdjustRadarForRobotTurn(true) has been called

23 Getting Info Methods exist for getting information about the robot
getX() and getY() get the current coordinate of the robot getHeading(), getGunHeading(), and getRadarHeading() get the current heading of the vehicle, gun, or radar in degrees getBattleFieldWidth() and getBattleFieldHeight() get the dimension of the battlefield for the current round

24 Firing and controlling damage
Each robot starts out with a default "energy level," and is considered destroyed when its energy level falls to zero When firing, the robot can use up to three units of energy The more energy supplied to the bullet, the more damage it will inflict on the target robot fire(double power) and fireBullet(double power) are used to fire a bullet with the specified energy (fire power) the fireBullet() version of the call returns a reference to a robocode Bullet object that can be used in advanced robots.

25 USE THE WEB Lots of info available on building bots
Remember once you have become an experienced user you can then have a look at the actual source for the system Available at source forge You may even become a developer


Download ppt "How does Robocode work? In short it is a framework"

Similar presentations


Ads by Google