package battlecode.world.signal;

import java.util.Arrays;

import battlecode.common.GameConstants;
import battlecode.common.MapLocation;
import battlecode.common.RobotType;
import battlecode.engine.signal.Signal;
import battlecode.world.InternalObject;
import battlecode.world.InternalRobot;

/**
 * TODO: describes which cow tiles are owned by which team
 *
 * @author axc
 */
public class NeutralsTeamSignal extends Signal {
    private final int[][] teams; // 0 = none, 1 = A, 2 = B, 3 = both
    public NeutralsTeamSignal(InternalObject[] objs, int width, int height) {
        this.teams = new int[width][height];
        for (InternalObject obj : objs) {
            InternalRobot ir = (InternalRobot) obj;
            if (ir.type != RobotType.PASTR && ir.type != RobotType.SOLDIER) {
                continue;
            }
            int captureRange = 0;
            if (ir.type == RobotType.PASTR) {
                captureRange = GameConstants.PASTR_RANGE;
            }
            MapLocation[] affected = MapLocation.getAllMapLocationsWithinRadiusSq(ir.getLocation(), captureRange);
            for (MapLocation ml : affected) {
                if (ml.x >= 0 && ml.x < width && ml.y >= 0 && ml.y < height) {
                    teams[ml.x][ml.y] |= (1 << ir.getTeam().ordinal());
                }
            }
        }
    }

    public int[][] getTeams() {
        return teams;
    }
}

@@ -613,16 +613,774 @@
 eight%5D;%0A
+        int%5B%5D%5B%5D ids = new int%5Bwidth%5D%5Bheight%5D;%0A        for (int i = 0; i %3C width; i++) %7B%0A            for (int j = 0; j %3C height; j++) %7B%0A                ids%5Bi%5D%5Bj%5D = Integer.MAX_VALUE;%0A            %7D%0A        %7D%0A%0A        for (InternalObject obj : objs) %7B%0A            InternalRobot ir = (InternalRobot) obj;%0A            if (ir.type == RobotType.PASTR) %7B%0A                MapLocation%5B%5D affected = MapLocation.getAllMapLocationsWithinRadiusSq(ir.getLocation(), GameConstants.PASTR_RANGE);%0A                for (MapLocation ml : affected) %7B%0A                    if (ml.x %3E= 0 && ml.x %3C width && ml.y %3E= 0 && ml.y %3C height) %7B%0A                        ids%5Bml.x%5D%5Bml.y%5D = Math.min(ids%5Bml.x%5D%5Bml.y%5D, ir.getID());%0A                    %7D%0A                %7D%0A            %7D%0A        %7D%0A%0A
         
@@ -1405,32 +1405,32 @@
 t obj : objs) %7B%0A
-
             Inte
@@ -1575,32 +1575,187 @@
 ;%0A            %7D%0A
+            if (ir.type == RobotType.SOLDIER && ids%5Bir.getLocation().x%5D%5Bir.getLocation().y%5D %3C Integer.MAX_VALUE) %7B%0A                continue;%0A            %7D%0A
             int 
@@ -2118,32 +2118,129 @@
 && ml.y %3C height
+ && (ir.type == RobotType.SOLDIER %7C%7C ir.type == RobotType.PASTR && ir.getID() == ids%5Bml.x%5D%5Bml.y%5D)
 ) %7B%0A            
@@ -2265,17 +2265,16 @@
 %5D%5Bml.y%5D 
-%7C
 = (1 %3C%3C 

Fix signal