-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
greenec
committed
Sep 29, 2015
1 parent
3eb8d3c
commit 6414d26
Showing
59 changed files
with
1,808 additions
and
388 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Oops, something went wrong.