Skip to content
Merged

Sync #16

Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f640892
Merge pull request #5 from androidmage/master
vilasopher Jan 9, 2016
5f31991
Merge pull request #6 from androidmage/master
vilasopher Jan 9, 2016
0f475e3
Merge pull request #7 from androidmage/master
vilasopher Jan 10, 2016
2df9b82
Merge pull request #8 from androidmage/master
vilasopher Jan 11, 2016
4f9ebea
Merge pull request #38 from Soupdoop/master
androidmage Jan 12, 2016
500506d
Archons also try to escape where it will be safe
androidmage Jan 12, 2016
2782926
Merge pull request #39 from androidmage/androidmage-archon-escape-pat…
androidmage Jan 12, 2016
66359df
Merge pull request #9 from androidmage/master
vilasopher Jan 12, 2016
a2a22e7
Update RobotPlayer.java
vilasopher Jan 12, 2016
7d984e4
Merge pull request #40 from vilasopher/master
androidmage Jan 12, 2016
326743e
Update RobotPlayer.java
vilasopher Jan 12, 2016
51e5117
Update RobotPlayer.java
vilasopher Jan 12, 2016
311a51c
Merge pull request #41 from vilasopher/master
androidmage Jan 12, 2016
b235e32
Get rid of guard nullpointerexception
androidmage Jan 12, 2016
463aee8
Merge pull request #42 from androidmage/androidmage-guard-patch-2
androidmage Jan 12, 2016
315be25
Merge pull request #10 from androidmage/master
vilasopher Jan 12, 2016
04d7828
Update RobotPlayer.java
vilasopher Jan 12, 2016
c961a9b
Merge pull request #43 from vilasopher/master
androidmage Jan 12, 2016
37f8c15
Guard Null pointer exception actually fixed
androidmage Jan 12, 2016
129bfd2
Merge pull request #44 from androidmage/androidmage-guard-patch-3
androidmage Jan 12, 2016
fa3ee5b
Merge pull request #11 from androidmage/master
vilasopher Jan 12, 2016
b424885
Update RobotPlayer.java
vilasopher Jan 12, 2016
31c541e
Merge pull request #45 from vilasopher/master
androidmage Jan 12, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 45 additions & 41 deletions RobotPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public void run() {
RESOURCE_FUNCTIONS.BUG(RESOURCE_FUNCTIONS.mostRecentEnemyArchonLocation());
}*/

Clock.yield();
} catch (Exception e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -173,13 +174,15 @@ public void run() {
if(rc.isCoreReady()){
RobotInfo[] robots = rc.senseNearbyRobots();
boolean targetFound = false;
for(RobotInfo robot:robots){
if(robot.location.distanceSquaredTo(archonLocation) < 25){
targetFound = true;
break;
if(robots != null && archonLocation != null){
for(RobotInfo robot:robots){
if(robot.location.distanceSquaredTo(archonLocation) < 25){
targetFound = true;
break;
}
}
}
if(targetFound == false){
if(targetFound == false && archonLocation != null){
RESOURCE_FUNCTIONS.BUG(archonLocation);
}
}
Expand All @@ -200,7 +203,7 @@ public void run() {

RESOURCE_FUNCTIONS.attackWeakestEnemy();
//If didn't attack anyone that is adjacent
if(rc.isWeaponReady()){
if(rc.isWeaponReady() && robots != null && archonLocation != null){
MapLocation target = null;
for(RobotInfo robot: robots) {
if((robot.team == Team.ZOMBIE) && robot.location.distanceSquaredTo(archonLocation) < 25) {
Expand Down Expand Up @@ -259,7 +262,7 @@ public void run(){
FancyMessage x = FancyMessage.getFromRecievedSignal(signals[i]);
if(x.isMessage){
if(x.type == 2){
mostRecentEnemyArchonLocations.add(new Triple<Integer,MapLocation,Integer>(0,new MapLocation(x.ints.first,x.ints.second),rc.getRoundNum()));
mostRecentEnemyArchonLocations.add(new Triple<Integer,MapLocation,Integer>(0,new MapLocation(x.ints.first - 16000,x.ints.second - 16000),rc.getRoundNum()));
}
}
}
Expand All @@ -273,8 +276,18 @@ public void run(){
RobotType type = RESOURCE_FUNCTIONS.chooseRobotType();
if(RESOURCE_FUNCTIONS.tryBuild(type)){ //See function in RESOURCE_FUNCTIONS to know what it does
//After building scout, waits a turn, then signals it the location, so it has a good idea of where base is
//Also signals the scout which type to become
Clock.yield();
Triple<Integer,Integer,Integer> scoutType = getScoutInitType();
//Check if near zombie round
int roundNum = rc.getRoundNum();
boolean isCloseToZombieRound = false;
for (int i = 0; i < zombieRounds.length && !isCloseToZombieRound; i++) {
isCloseToZombieRound = (Math.abs(roundNum - zombieRounds[i]) < 10);
}
if (mostRecentEnemyArchonLocations.size() != 0 && isCloseToZombieRound) {
scoutType = getScoutHerdingType();
}
FancyMessage.sendMessage(0,scoutType.first | scoutType.second,scoutType.third,3);
}
}
Expand All @@ -288,6 +301,14 @@ public void run(){
public Triple<Integer,Integer,Integer> getScoutInitType(){
return new Triple<Integer,Integer,Integer>(0,0,0);
}

public Triple<Integer, Integer, Integer> getScoutHerdingType(){
MapLocation enemyArchonLocation = RESOURCE_FUNCTIONS.mostRecentEnemyArchonLocation();
System.out.println("enemyArchonLocation =" + enemyArchonLocation);
int xPosition = (enemyArchonLocation.x + 16000) << 2;
int yPosition = (enemyArchonLocation.y + 16000);
return new Triple<Integer, Integer, Integer>(1,xPosition,yPosition);
}
}

/**
Expand Down Expand Up @@ -338,9 +359,8 @@ public void run(){
if((x.ints.first & 3) == 0){
runAsArchonSearcher();
}else if((x.ints.first & 3) == 1){
if(x.bits[2]){
mostRecentArchonLocation = new MapLocation(x.ints.first >> 16,x.ints.second);
}
mostRecentArchonLocation = new MapLocation((x.ints.first >>> 2) - 16000,x.ints.second - 16000);
System.out.println("Running as zombie herder to archon at (" + mostRecentArchonLocation.x + "," + mostRecentArchonLocation.y + ")");
runAsZombieHerder();
}else if((x.ints.first & 3) == 2){
runAsTurretSights(x.ints.second);
Expand Down Expand Up @@ -413,6 +433,7 @@ public void runAsTurretSights(int turretID){
while(true){
try{

Clock.yield();
}catch(Exception e){
e.printStackTrace();
}
Expand All @@ -431,6 +452,7 @@ public void runAsZombieBomber(){
}else{
runAsArchonSearcher();
}
Clock.yield();
}catch(Exception e){
e.printStackTrace();
}
Expand Down Expand Up @@ -869,16 +891,23 @@ public static void escapeEnemy(){
if(enemies == null){
return;
}
ArrayList<RobotInfo> dangerousEnemies = dangerousRobotLocation(enemies);
ArrayList<RobotInfo> dangerousEnemies = dangerousRobots(enemies, rc.getLocation());
if(dangerousEnemies == null){
return;
}
try{
for(RobotInfo dangerousEnemy: dangerousEnemies){
Direction escapeDirection = calculateEscapeDirection(dangerousEnemy.location);
if(rc.canMove(escapeDirection)){
System.out.println("success");
rc.move(escapeDirection);
return;
}
}
for(Direction possibleDirection: DIRECTIONS){
dangerousEnemies = dangerousRobots(enemies, rc.getLocation().add(possibleDirection));
if(rc.canMove(possibleDirection) && dangerousEnemies == null){
rc.move(possibleDirection);
return;
}
}
}
Expand All @@ -896,7 +925,7 @@ public static RobotInfo[] locateEnemy(){
return null;
}

public static ArrayList<RobotInfo> dangerousRobotLocation(RobotInfo[] enemies){
public static ArrayList<RobotInfo> dangerousRobots(RobotInfo[] enemies, MapLocation location){
ArrayList<RobotInfo> dangerousEnemies = new ArrayList<RobotInfo>();
for(RobotInfo enemy: enemies){
if(enemy.location.distanceSquaredTo(rc.getLocation()) <= enemy.type.attackRadiusSquared){
Expand All @@ -905,36 +934,11 @@ public static ArrayList<RobotInfo> dangerousRobotLocation(RobotInfo[] enemies){
}
return dangerousEnemies;
}

public static Direction calculateEscapeDirection(MapLocation enemyLocation){
MapLocation myLocation = rc.getLocation();
int xDifference = enemyLocation.x - myLocation.x;
int yDifference = enemyLocation.y - myLocation.y;
if(xDifference>0 && yDifference>0){
return Direction.NORTH_WEST;
}
else if(xDifference>0 && yDifference<0){
return Direction.SOUTH_WEST;
}
else if(xDifference<0 && yDifference<0){
return Direction.SOUTH_EAST;
}
else if(xDifference<0 && yDifference>0){
return Direction.NORTH_EAST;
}
else if(xDifference>0){
return Direction.WEST;
}
else if(xDifference<0){
return Direction.EAST;
}
else if(yDifference>0){
return Direction.NORTH;
}
return Direction.SOUTH;

Direction enemyDirection = rc.getLocation().directionTo(enemyLocation);
return enemyDirection.opposite();
}

public static void attackWeakestEnemy(){
MapLocation weakestEnemyLocation = locateWeakestEnemy();
if(weakestEnemyLocation==null){
Expand Down