Skip to content

Commit

Permalink
Fixed a bug with armories turning on the wrong mines while building.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmjones committed Jan 22, 2011
1 parent 6e493a6 commit 5ac2743
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
38 changes: 27 additions & 11 deletions team094/castes/Armory.java
Expand Up @@ -8,15 +8,18 @@ private static enum State {
START,
IDLE,
BUILD,
DELAY,
YIELD
}
private static final int MAX_UNITS = 10;
private static final int MAX_UNITS = 10,
DELAY = 100;
private State state;

private final Builder builder;
private MapLocation[] locations;
private int locIndex,
units;
units,
cooldown;

public Armory(RobotProperties rp) {
super(rp);
Expand All @@ -40,6 +43,9 @@ public void SM() {
case BUILD:
build();
break;
case DELAY:
delay();
break;
case YIELD:
default:
yield();
Expand Down Expand Up @@ -78,25 +84,26 @@ private void start() throws GameActionException {
}

private void idle() throws GameActionException {
Robot r = (Robot)myRP.sensor.senseObjectAtLocation(locations[locIndex], RobotLevel.ON_GROUND);

if(myRP.sensor.senseObjectAtLocation(locations[locIndex], RobotLevel.IN_AIR) == null &&
r != null) {
if(myRP.sensor.senseObjectAtLocation(locations[locIndex], RobotLevel.IN_AIR) == null) {
builder.startBuild(false, 2, locations[locIndex], Chassis.FLYING);
if(r.getTeam() == myRP.myTeam && !myRP.sensor.senseRobotInfo(r).on)
myRC.turnOn(locations[locIndex], RobotLevel.ON_GROUND);
state = state.BUILD;
build(); // Call build function here to save time.
}

locIndex = (locIndex+1+locations.length)%locations.length;
}

@SuppressWarnings("fallthrough")
private void build() throws GameActionException {
switch (builder.doBuild()) {
case ACTIVE:
Robot r = (Robot)myRP.sensor.senseObjectAtLocation(locations[locIndex], RobotLevel.ON_GROUND);
if(r.getTeam() == myRP.myTeam && !myRP.sensor.senseRobotInfo(r).on)
myRC.turnOn(locations[locIndex], RobotLevel.ON_GROUND);
break;
case DONE:
units++;
locIndex = (locIndex+1+locations.length)%locations.length;
cooldown = DELAY;
state = state.DELAY;
break;
case FAIL:
if(units >= MAX_UNITS)
state = State.YIELD;
Expand All @@ -107,4 +114,13 @@ private void build() throws GameActionException {
break;
}
}

private void delay() {
if(--cooldown <= 0) {
if(units >= MAX_UNITS)
state = State.YIELD;
else
state = State.IDLE;
}
}
}
4 changes: 2 additions & 2 deletions team094/castes/Miner.java
Expand Up @@ -10,8 +10,8 @@ private static enum State {
BUILD,
YIELD
}
private static final int MAX_SCOUTS = 3,
OFF_ROUNDS = 20;
private static final int MAX_SCOUTS = 10,
OFF_ROUNDS = 5;

private final Builder builder;
private final MapLocation myLoc; // Buildings can't move.
Expand Down

0 comments on commit 5ac2743

Please sign in to comment.