Skip to content

Commit

Permalink
created sample robot backup
Browse files Browse the repository at this point in the history
  • Loading branch information
greenec committed Sep 29, 2015
1 parent 3eb8d3c commit 6414d26
Show file tree
Hide file tree
Showing 59 changed files with 1,808 additions and 388 deletions.
1 change: 0 additions & 1 deletion .idea/.name

This file was deleted.

22 changes: 0 additions & 22 deletions .idea/compiler.xml

This file was deleted.

3 changes: 0 additions & 3 deletions .idea/copyright/profiles_settings.xml

This file was deleted.

21 changes: 0 additions & 21 deletions .idea/misc.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

9 changes: 0 additions & 9 deletions .idea/robocode.iml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

318 changes: 0 additions & 318 deletions .idea/workspace.xml

This file was deleted.

Binary file added sample/Corners.class
Binary file not shown.
140 changes: 140 additions & 0 deletions sample/Corners.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/**
* Copyright (c) 2001-2014 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
package sample;


import robocode.DeathEvent;
import robocode.Robot;
import robocode.ScannedRobotEvent;
import static robocode.util.Utils.normalRelativeAngleDegrees;

import java.awt.*;


/**
* Corners - a sample robot by Mathew Nelson.
* <p/>
* This robot moves to a corner, then swings the gun back and forth.
* If it dies, it tries a new corner in the next round.
*
* @author Mathew A. Nelson (original)
* @author Flemming N. Larsen (contributor)
*/
public class Corners extends Robot {
int others; // Number of other robots in the game
static int corner = 0; // Which corner we are currently using
// static so that it keeps it between rounds.
boolean stopWhenSeeRobot = false; // See goCorner()

/**
* run: Corners' main run function.
*/
public void run() {
// Set colors
setBodyColor(Color.red);
setGunColor(Color.black);
setRadarColor(Color.yellow);
setBulletColor(Color.green);
setScanColor(Color.green);

// Save # of other bots
others = getOthers();

// Move to a corner
goCorner();

// Initialize gun turn speed to 3
int gunIncrement = 3;

// Spin gun back and forth
while (true) {
for (int i = 0; i < 30; i++) {
turnGunLeft(gunIncrement);
}
gunIncrement *= -1;
}
}

/**
* goCorner: A very inefficient way to get to a corner. Can you do better?
*/
public void goCorner() {
// We don't want to stop when we're just turning...
stopWhenSeeRobot = false;
// turn to face the wall to the "right" of our desired corner.
turnRight(normalRelativeAngleDegrees(corner - getHeading()));
// Ok, now we don't want to crash into any robot in our way...
stopWhenSeeRobot = true;
// Move to that wall
ahead(5000);
// Turn to face the corner
turnLeft(90);
// Move to the corner
ahead(5000);
// Turn gun to starting point
turnGunLeft(90);
}

/**
* onScannedRobot: Stop and fire!
*/
public void onScannedRobot(ScannedRobotEvent e) {
// Should we stop, or just fire?
if (stopWhenSeeRobot) {
// Stop everything! You can safely call stop multiple times.
stop();
// Call our custom firing method
smartFire(e.getDistance());
// Look for another robot.
// NOTE: If you call scan() inside onScannedRobot, and it sees a robot,
// the game will interrupt the event handler and start it over
scan();
// We won't get here if we saw another robot.
// Okay, we didn't see another robot... start moving or turning again.
resume();
} else {
smartFire(e.getDistance());
}
}

/**
* smartFire: Custom fire method that determines firepower based on distance.
*
* @param robotDistance the distance to the robot to fire at
*/
public void smartFire(double robotDistance) {
if (robotDistance > 200 || getEnergy() < 15) {
fire(1);
} else if (robotDistance > 50) {
fire(2);
} else {
fire(3);
}
}

/**
* onDeath: We died. Decide whether to try a different corner next game.
*/
public void onDeath(DeathEvent e) {
// Well, others should never be 0, but better safe than sorry.
if (others == 0) {
return;
}

// If 75% of the robots are still alive when we die, we'll switch corners.
if ((others - getOthers()) / (double) others < .75) {
corner += 90;
if (corner == 270) {
corner = -90;
}
out.println("I died and did poorly... switching corner to " + corner);
} else {
out.println("I died but did well. I will still use corner " + corner);
}
}
}
9 changes: 9 additions & 0 deletions sample/Corners.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#Robot Properties
#Sun Aug 20 21:14:27 EST 2006
robot.description=\ A sample robot\n Moves to a corner, then swings the gun back and forth.\n If it dies, it tries a new corner in the next round.
robot.webpage=
robocode.version=1.1.2
robot.java.source.included=true
robot.author.name=Mathew Nelson and Flemming N. Larsen
robot.classname=sample.Corners
robot.name=Corners
Binary file added sample/Crazy.class
Binary file not shown.
103 changes: 103 additions & 0 deletions sample/Crazy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/**
* Copyright (c) 2001-2014 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
package sample;


import robocode.*;

import java.awt.*;


/**
* Crazy - a sample robot by Mathew Nelson.
* <p/>
* This robot moves around in a crazy pattern.
*
* @author Mathew A. Nelson (original)
* @author Flemming N. Larsen (contributor)
*/
public class Crazy extends AdvancedRobot {
boolean movingForward;

/**
* run: Crazy's main run function
*/
public void run() {
// Set colors
setBodyColor(new Color(0, 200, 0));
setGunColor(new Color(0, 150, 50));
setRadarColor(new Color(0, 100, 100));
setBulletColor(new Color(255, 255, 100));
setScanColor(new Color(255, 200, 200));

// Loop forever
while (true) {
// Tell the game we will want to move ahead 40000 -- some large number
setAhead(40000);
movingForward = true;
// Tell the game we will want to turn right 90
setTurnRight(90);
// At this point, we have indicated to the game that *when we do something*,
// we will want to move ahead and turn right. That's what "set" means.
// It is important to realize we have not done anything yet!
// In order to actually move, we'll want to call a method that
// takes real time, such as waitFor.
// waitFor actually starts the action -- we start moving and turning.
// It will not return until we have finished turning.
waitFor(new TurnCompleteCondition(this));
// Note: We are still moving ahead now, but the turn is complete.
// Now we'll turn the other way...
setTurnLeft(180);
// ... and wait for the turn to finish ...
waitFor(new TurnCompleteCondition(this));
// ... then the other way ...
setTurnRight(180);
// .. and wait for that turn to finish.
waitFor(new TurnCompleteCondition(this));
// then back to the top to do it all again
}
}

/**
* onHitWall: Handle collision with wall.
*/
public void onHitWall(HitWallEvent e) {
// Bounce off!
reverseDirection();
}

/**
* reverseDirection: Switch from ahead to back & vice versa
*/
public void reverseDirection() {
if (movingForward) {
setBack(40000);
movingForward = false;
} else {
setAhead(40000);
movingForward = true;
}
}

/**
* onScannedRobot: Fire!
*/
public void onScannedRobot(ScannedRobotEvent e) {
fire(1);
}

/**
* onHitRobot: Back up!
*/
public void onHitRobot(HitRobotEvent e) {
// If we're moving the other robot, reverse!
if (e.isMyFault()) {
reverseDirection();
}
}
}
9 changes: 9 additions & 0 deletions sample/Crazy.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#Robot Properties
#Sun Aug 20 21:16:04 EST 2006
robot.description=\ A sample robot\n\n Moves around in a crazy pattern
robot.webpage=
robocode.version=1.1.2
robot.java.source.included=true
robot.author.name=Mathew Nelson and Flemming N. Larsen
robot.classname=sample.Crazy
robot.name=Crazy
Binary file added sample/Fire.class
Binary file not shown.
Loading

0 comments on commit 6414d26

Please sign in to comment.