Difference between revisions of "GravityWave/Code"
Jump to navigation
Jump to search
J Litewski (talk | contribs) (Added Scan.java source) |
J Litewski (talk | contribs) m (added navbox) |
||
Line 1: | Line 1: | ||
+ | {{Navbox small | ||
+ | | title = GravityWave pages | ||
+ | | parent = GravityWave | ||
+ | | page1 = Versions | ||
+ | | page2 = Code | ||
+ | | page3 = Tests | ||
+ | }} | ||
+ | |||
==Scan.java== | ==Scan.java== | ||
This is GravityWave's Scan class. It's still being expanded and debugged, but I feel it's good enough to release so newer people to Robocode have a nice Scan class with little effort on using it. | This is GravityWave's Scan class. It's still being expanded and debugged, but I feel it's good enough to release so newer people to Robocode have a nice Scan class with little effort on using it. |
Revision as of 20:26, 14 June 2009
- GravityWave pages:
- GravityWave - Versions - Code - Tests
Scan.java
This is GravityWave's Scan class. It's still being expanded and debugged, but I feel it's good enough to release so newer people to Robocode have a nice Scan class with little effort on using it.
package hackhalotwo.utils; import robocode.*; //Robocode stuff import java.awt.geom.Point2D; //for Point2D stuff import java.lang.System; //for outputing debug text //Version 0.5 public class Scan { //Debug stuff private static final boolean debug = true; //set to true for debug text //Set up the main varibles for the class public static String _name; public static double _bearing; public static double _bearingR; public static double _distance; public static double _energy; public static double _heading; public static double _headingR; public static double _velocity; public static int _tick; //last scan tick //Enemy Stuff public static long bulletTick; //tick the bullet was fired on public static int nextFire; //when the enemy could fire again public static boolean canFire = false; //Can the Enemy fire? //Your Robot public static AdvancedRobot _robot; //Your robot //Location Stuff public static Point2D.Double _location; //Last Scan Location public static Point2D.Double _enemyLocation; //Enemy Location //Helper Varibles public static double absBearing; //Absolute Bearing public static double latVelocity; //Lateral Velocity public static double bulletPower; //Bullet Power and Distance Traveled //Inner class designed to be a placeholder for storing scans public class Scanner { public String name; public double bearing, bearingR, distance, energy, heading, headingR; public long tick; protected Scanner() { } } //Functions public static void init(AdvancedRobot r) { _robot = r; _tick = (int)(_robot.getTime()); //set the time to correctly reduce ticks nextFire = 29; //since guns are hot at the begining of the round for 30 ticks (minus 1 for safety) canFire = false; //make sure it's set correctly //debug stuff if(debug) { System.out.println("Scan.class :: Scan.init(AdvancedRobot) called"); } } public static void update(AdvancedRobot r, ScannedRobotEvent e) { //debug stuff if(debug) { System.out.println("Scan.class :: Scan.update(AdvancedRobot, ScannedRobotEvent) called"); } //update the varibles _robot = r; _name = e.getName(); _bearing = e.getBearing(); _bearingR = e.getBearingRadians(); _distance = e.getDistance(); _energy = e.getEnergy(); _heading = e.getHeading(); _headingR = e.getHeadingRadians(); _velocity = e.getVelocity(); //get the current tick int tick = (int)(_robot.getTime()); //check to see if the enemy can fire if(!canFire) { //he can't fire if(nextFire > 0) { //check to see how many ticks to take away nextFire -= (tick - _tick); //correctly reduce the number of ticks remaining if(nextFire < 0) { nextFire = 0; } //just in case if(debug) { System.out.println("Scan.class :: Time till enemy can fire again: "+ nextFire); } } else { canFire = true; } } //update the scan tick _tick = tick; //set up some of the advanced functions //updateAdv(); } public static void updateAdv() { } public static void bulletFired(double power) { if(debug) { System.out.println("Scan.class :: Scan.bulletFired(time, power) called"); } bulletTick = _robot.getTime(); //calculate the number of ticks until the next fire nextFire = (int)((1D + power / 5D)*10); canFire = false; //Set the boolean if(debug) { System.out.println("Scan.class :: "+nextFire+" ticks until enemy can fire again"); } } public static boolean canFire() { if(canFire) { return true; } else { return false; } } public static double calcTurn() { return Math.PI/720d*(40d - 3d*Math.abs(_velocity)); } // public final double calcHeading(double heading, double _heading) // { return (heading - _heading); } public final double calcRelativeHeading() { return (_heading - (_bearing + _robot.getHeading())); } }
Features
(Version 0.5)
- Gun Heat Tracker using a simple and quick math equation
- Internal Scanner Class to store scans
- Fast Execution Time
- Plug and Play