Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/robocode/robots/sampleex/Alien.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: 2.0 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 sampleex;
9
10
11import robocode.*;
12import robocode.robotinterfaces.IBasicEvents;
13import robocode.robotinterfaces.IBasicRobot;
14import robocode.robotinterfaces.peer.IBasicRobotPeer;
15import robocode.robotinterfaces.peer.IStandardRobotPeer;
16
17import java.io.PrintStream;
18
19
20/**
21 * A sample robot.
22 * Is not inherited from classic base robots, uses new experimental access to RobotPeer.
23 * Use -DEXPERIMENTAL=true to start robocode for this robot.
24 *
25 * @author Pavel Savara (original)
26 */
27public class Alien implements IBasicEvents, IBasicRobot, Runnable {
28
29  PrintStream out;
30  IStandardRobotPeer peer;
31
32  public Runnable getRobotRunnable() {
33    return this;
34  }
35
36  public IBasicEvents getBasicEventListener() {
37    return this;
38  }
39
40  public void setPeer(IBasicRobotPeer iRobotPeer) {
41    peer = (IStandardRobotPeer) iRobotPeer;
42  }
43
44  public void setOut(PrintStream printStream) {
45    out = printStream;
46  }
47
48  public void run() {
49    while (true) {
50      peer.move(100); // Move ahead 100
51      peer.turnGun(Math.PI * 2); // Spin gun around
52      peer.move(-100); // Move back 100
53      peer.turnGun(Math.PI * 2); // Spin gun around
54    }
55  }
56
57  public void onScannedRobot(ScannedRobotEvent e) {
58    peer.setFire(1);
59  }
60
61  public void onHitByBullet(HitByBulletEvent e) {
62    peer.turnBody(Math.PI / 2 + e.getBearingRadians());
63  }
64
65  public void onStatus(StatusEvent e) {}
66
67  public void onBulletHit(BulletHitEvent e) {}
68
69  public void onBulletHitBullet(BulletHitBulletEvent e) {}
70
71  public void onBulletMissed(BulletMissedEvent e) {}
72
73  public void onDeath(DeathEvent e) {}
74
75  public void onHitRobot(HitRobotEvent e) {}
76
77  public void onHitWall(HitWallEvent e) {}
78
79  public void onRobotDeath(RobotDeathEvent e) {}
80
81  public void onWin(WinEvent e) {}
82}
Note: See TracBrowser for help on using the repository browser.