Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/robocode/robots/sample/RamFire.java @ 13019

Last change on this file since 13019 was 13019, checked in by gkronber, 9 years ago

#2069: added necessary robocode files to project to make sure that the robocode problem is self-contained (only a java installation is necessary)

File size: 1.9 KB
Line 
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 */
8package sample;
9
10
11import robocode.HitRobotEvent;
12import robocode.Robot;
13import robocode.ScannedRobotEvent;
14
15import java.awt.*;
16
17
18/**
19 * RamFire - a sample robot by Mathew Nelson.
20 * <p/>
21 * Drives at robots trying to ram them.
22 * Fires when it hits them.
23 *
24 * @author Mathew A. Nelson (original)
25 * @author Flemming N. Larsen (contributor)
26 */
27public class RamFire extends Robot {
28  int turnDirection = 1; // Clockwise or counterclockwise
29
30  /**
31   * run: Spin around looking for a target
32   */
33  public void run() {
34    // Set colors
35    setBodyColor(Color.lightGray);
36    setGunColor(Color.gray);
37    setRadarColor(Color.darkGray);
38
39    while (true) {
40      turnRight(5 * turnDirection);
41    }
42  }
43
44  /**
45   * onScannedRobot:  We have a target.  Go get it.
46   */
47  public void onScannedRobot(ScannedRobotEvent e) {
48
49    if (e.getBearing() >= 0) {
50      turnDirection = 1;
51    } else {
52      turnDirection = -1;
53    }
54
55    turnRight(e.getBearing());
56    ahead(e.getDistance() + 5);
57    scan(); // Might want to move ahead again!
58  }
59
60  /**
61   * onHitRobot:  Turn to face robot, fire hard, and ram him again!
62   */
63  public void onHitRobot(HitRobotEvent e) {
64    if (e.getBearing() >= 0) {
65      turnDirection = 1;
66    } else {
67      turnDirection = -1;
68    }
69    turnRight(e.getBearing());
70
71    // Determine a shot that won't kill the robot...
72    // We want to ram him instead for bonus points
73    if (e.getEnergy() > 16) {
74      fire(3);
75    } else if (e.getEnergy() > 10) {
76      fire(2);
77    } else if (e.getEnergy() > 4) {
78      fire(1);
79    } else if (e.getEnergy() > 2) {
80      fire(.5);
81    } else if (e.getEnergy() > .4) {
82      fire(.1);
83    }
84    ahead(40); // Ram him again!
85  }
86}
Note: See TracBrowser for help on using the repository browser.