How does Robocode work? In short it is a framework

Slides:



Advertisements
Similar presentations
Understanding an Apps Architecture ASFA Computer Science: Principles Fall 2013.
Advertisements

Robocode Some Methods and Ideas. Robot anatomy 101 Just like the real thing … it has a gun that rotates a radar on top that also rotates tank, gun and.
Robocode. What is Robocode? Robocode is an easy-to-use robotics battle simulator. You create a robot, put it onto a battlefield, and let it battle to.
Component Patterns – Architecture and Applications with EJB copyright © 2001, MATHEMA AG Component Patterns Architecture and Applications with EJB JavaForum.
Graduate Capstone Project Breaking Walls: Developing a Successful Robot in Robocode Chris Velez Summer 2011 Advisor :Dr. Xiang.
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
R R R CSE870: Advanced Software Engineering: Frameworks (Cheng, Sp2003)1 Frameworks A Brief Introduction.
HST 952 Computing for Biomedical Scientists Lecture 2.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
Object-Oriented Analysis and Design
Use Case Analysis – continued
Great teaching/ learning aid … OO Threading Packaging Inheritance Polymorphism Calling API code Event handling Inner classes Java docs How to duck… Consume.
C++ fundamentals.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Introduction to AppInventor Dr. José M. Reyes Álamo.
C# Event Processing Model Solving The Mystery. Agenda Introduction C# Event Processing Macro View Required Components Role of Each Component How To Create.
UNIT-V The MVC architecture and Struts Framework.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 11 Slide 1 Architectural Design.
SuperCorners. Problem The Corners sample robot has a simple strategy: first, move into a corner of the arena, and second sweep the gun back and forth.
PROG Mobile Java Application Development PROG Mobile Java Application Development Event Handling Creating Menus.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
Software Design Refinement Using Design Patterns Instructor: Dr. Hany H. Ammar Dept. of Computer Science and Electrical Engineering, WVU.
Model View Controller (MVC) Rick Mercer with a wide variety of others 1.
Software Construction Lecture 10 Frameworks
Welcome to CIS 083 ! Events CIS 068.
CSE AI Game Programming. Installation 
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 10Slide 1 Architectural Design l Establishing the overall structure of a software system.
Patterns in programming 1. What are patterns? “A design pattern is a general, reusable solution to a commonly occurring problem in software. A design.
C H A P T E R T E N Event-Driven Programming Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
CSE AI Game Programming. Installation 
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 10Slide 1 Architectural Design l Establishing the overall structure of a software system.
1 Extend is a simulation tool to create models quickly, with all the blocks you need and without even having to type an equation. You can use a series.
Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation.
Assignments. AnatomyBot.java Create a robot that turns all of it parts independently (vehicle, gun, and radar). Turn the vehicle left 360 o Turn the gun.
Introduction to Java Beans CIS 421 Web-based Java Programming.
Frameworks CompSci 230 S Software Construction.
University of Limerick1 Computer Applications CS 4815 Robocode.
Chapter 14 Applets and Advanced GUI  The Applet Class  The HTML Tag F Passing Parameters to Applets F Conversions Between Applications and Applets F.
Object Oriented Programming.  Interface  Event Handling.
CSE 331 Software Design & Implementation Hal Perkins Autumn 2012 Event-Driven Programming 1.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 27 JavaBeans and.
My Second Robot. Anatomy of a Robot A robot consists of 3 independently moving parts: Vehicle - determines the direction in which the robot will move.
CS324e - Elements of Graphics and Visualization Timing Framework.
CSCI 444 / CIS 644 Event Driven Programming. Outline I.What is an event driven system? II.What is event driven programming? III.Course Overview.
Seminar for Participants An Introduction on Robocode.
Event Handling Tonga Institute of Higher Education.
CHAPTER 3 MODELING COMPONENT-LEVEL DESIGN.
Component Patterns – Architecture and Applications with EJB copyright © 2001, MATHEMA AG Component Patterns Architecture and Applications with EJB Markus.
Classes, Interfaces and Packages
Programming Logic and Design Fourth Edition, Comprehensive Chapter 14 Event-Driven Programming with Graphical User Interfaces.
(1) Introduction to Robocode Philip Johnson Collaborative Software Development Laboratory Information and Computer Sciences University of Hawaii Honolulu.
Robocode. Robocode: basics Coords. are (x,y), with bottom left as (0,0) Heading: degrees, straight up = 0, pos. clockwise (0
PaintPictureBoxDemo Refers to the PaintPictureBoxDemo Visual Basic Program Included With The Lecture.
Event Driven (Asynchronous) Programming. Event handling in Unity Subclass a class that contains event handling methods, and then override those methods.
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
Abstract Factory Pattern
Winning Strategy in Programming Game Robocode
CONTENT MANAGEMENT SYSTEM CSIR-NISCAIR, New Delhi
Behavioral Design Patterns
Part 3 Design What does design mean in different fields?
Abstract Factory Pattern
Intent (Thanks to Jim Fawcett for the slides)
Event Driven Programming
EE 422C Java FX.
C# Event Processing Model
MTAT , 2CP Seminar Ilja Livenson
Patterns.
Constructors, GUI’s(Using Swing) and ActionListner
Robocode A robot is made up of 3 things:
Presentation transcript:

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

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].

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

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

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

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

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

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

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

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

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

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

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

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

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

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); }

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()

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()

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

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

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

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

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

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.

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