Skip to content

Commit

Permalink
serialized classes, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
nage117 committed Apr 25, 2010
1 parent 62efdb3 commit dcb93dd
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 9 deletions.
2 changes: 1 addition & 1 deletion chris.battle
Expand Up @@ -5,4 +5,4 @@ robocode.battleField.height=600
robocode.battle.numRounds=10
robocode.battle.gunCoolingRate=0.1
robocode.battle.rules.inactivityTime=450
robocode.battle.selectedRobots=sample.SittingDuck,com.jaxelson.Chris01Bot01
robocode.battle.selectedRobots=sample.SittingDuck,com.jaxelson.Chris01Bot01Team
58 changes: 52 additions & 6 deletions src/com/jaxelson/Chris01Bot01.java
Expand Up @@ -2,14 +2,20 @@

import java.awt.Color;
import java.awt.Graphics2D;
import java.io.IOException;
import java.util.Hashtable;

import navigation.ExtendedBot;
import robocode.HitByBulletEvent;
import robocode.MessageEvent;
import robocode.ScannedRobotEvent;

public class Chris01Bot01 extends ExtendedBot {
import java.io.Serializable;


public class Chris01Bot01 extends ExtendedBot implements Serializable {

private static final long serialVersionUID = 7742997431699620804L;

/**
* run: Chris01's default behavior
Expand All @@ -18,12 +24,13 @@ public class Chris01Bot01 extends ExtendedBot {
Hashtable<String,EnemyBot> _enemies = new Hashtable<String,EnemyBot>();

int state = 0;
Boolean leader = false;
long fireTime = 0;

public void run() {
//setColors(Color.red,Color.blue,Color.green);

setColors(Color.white,Color.white,Color.white);


// Robocode order
// Battle view (re)painted
Expand All @@ -35,9 +42,22 @@ public void run() {
// All robots are resumed to take new action
// Each robot processes its event queue

if(this.getEnergy() >= 200) {
leader = true;
}


do
{
quickestScan(0, true);
if(leader) {
quickestScan(0, true);
}
else {
if(fireTime == getTime() && getGunTurnRemaining() == 0) {
setFire(0.1);
}
fireTime = getTime() + 1;
}
execute();

} while(true);
Expand All @@ -47,8 +67,30 @@ public void run() {
* onScannedRobot: What to do when you see another robot
*/
public void onScannedRobot(ScannedRobotEvent e) {
updateEnemies(e, _enemies);

String enemyName = e.getName().replace(" ", "* ");
/*
System.out.println(enemyName);
System.out.println("TEAM MATES:");
System.out.println(this.getTeammates()[0]);
System.out.println(this.getTeammates()[1]);
*/
if(!this.isTeammate(enemyName)) {
updateEnemies(e, _enemies);
if(leader) {
try {
broadcastMessage(_enemies.get(e.getName()));
System.out.println("SENT MESSAGE:");
System.out.println(_enemies.get(e.getName()));
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}

}


/**
* onHitByBullet: What to do when you're hit by a bullet
Expand All @@ -59,8 +101,12 @@ public void onHitByBullet(HitByBulletEvent e) {

public void onMessageReceived(MessageEvent e)
{
if(e.getMessage().equals("Attack"))
fire(1);
if(!leader) {
EnemyBot temp = (EnemyBot)e.getMessage();
System.out.println(e.getMessage());
System.out.println("(" + temp.getX() + "," + temp.getY() + ")");
turnGunToXY(temp.getX(),temp.getY(),0.1);
}
}

public void onPaint(Graphics2D g) {
Expand Down
8 changes: 7 additions & 1 deletion src/com/jaxelson/EnemyBot.java
Expand Up @@ -4,8 +4,14 @@

import robocode.AdvancedRobot;
import robocode.ScannedRobotEvent;
import java.io.Serializable;

public class EnemyBot {
public class EnemyBot implements Serializable{
/**
*
*/
private static final long serialVersionUID = -6633270333555835298L;

private String _name;
private double _bearing;
private double _bearingRadians;
Expand Down
3 changes: 2 additions & 1 deletion src/com/jaxelson/ExtendedPoint2D.java
@@ -1,8 +1,9 @@
package com.jaxelson;

import java.awt.geom.Point2D;
import java.io.Serializable;

public class ExtendedPoint2D extends Point2D.Double{
public class ExtendedPoint2D extends Point2D.Double implements Serializable{

private static final long serialVersionUID = 74324L;
public ExtendedPoint2D(double x, double y) {
Expand Down

0 comments on commit dcb93dd

Please sign in to comment.