1 /** 2 * Copyright (c) 2001-2014 Mathew A. Nelson and Robocode contributors 3 * All rights reserved. This program and the accompanying materials 4 * are made available under the terms of the Eclipse Public License v1.0 5 * which accompanies this distribution, and is available at 6 * http://robocode.sourceforge.net/license/epl-v10.html 7 */ 8 package sample; 9 10 11 import robocode.HitByBulletEvent; 12 import robocode.HitWallEvent; 13 import robocode.RateControlRobot; 14 import robocode.ScannedRobotEvent; 15 16 17 /** 18 * This is a sample of a robot using the RateControlRobot class 19 * 20 * @author Joshua Galecki (original) 21 */ 22 public class VelociRobot extends RateControlRobot { 23 24 int turnCounter; run()25 public void run() { 26 27 turnCounter = 0; 28 setGunRotationRate(15); 29 30 while (true) { 31 if (turnCounter % 64 == 0) { 32 // Straighten out, if we were hit by a bullet and are turning 33 setTurnRate(0); 34 // Go forward with a velocity of 4 35 setVelocityRate(4); 36 } 37 if (turnCounter % 64 == 32) { 38 // Go backwards, faster 39 setVelocityRate(-6); 40 } 41 turnCounter++; 42 execute(); 43 } 44 } 45 onScannedRobot(ScannedRobotEvent e)46 public void onScannedRobot(ScannedRobotEvent e) { 47 fire(1); 48 } 49 onHitByBullet(HitByBulletEvent e)50 public void onHitByBullet(HitByBulletEvent e) { 51 // Turn to confuse the other robot 52 setTurnRate(5); 53 } 54 onHitWall(HitWallEvent e)55 public void onHitWall(HitWallEvent e) { 56 // Move away from the wall 57 setVelocityRate(-1 * getVelocityRate()); 58 } 59 } 60