From 500506da780356b65db8cc2301c44c85469899d4 Mon Sep 17 00:00:00 2001 From: androidmage Date: Mon, 11 Jan 2016 20:48:32 -0500 Subject: [PATCH 1/8] Archons also try to escape where it will be safe --- RobotPlayer.java | 44 +++++++++++++------------------------------- 1 file changed, 13 insertions(+), 31 deletions(-) diff --git a/RobotPlayer.java b/RobotPlayer.java index b26b279..86f8316 100644 --- a/RobotPlayer.java +++ b/RobotPlayer.java @@ -869,7 +869,7 @@ public static void escapeEnemy(){ if(enemies == null){ return; } - ArrayList dangerousEnemies = dangerousRobotLocation(enemies); + ArrayList dangerousEnemies = dangerousRobots(enemies, rc.getLocation()); if(dangerousEnemies == null){ return; } @@ -877,8 +877,15 @@ public static void escapeEnemy(){ 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; } } } @@ -896,7 +903,7 @@ public static RobotInfo[] locateEnemy(){ return null; } - public static ArrayList dangerousRobotLocation(RobotInfo[] enemies){ + public static ArrayList dangerousRobots(RobotInfo[] enemies, MapLocation location){ ArrayList dangerousEnemies = new ArrayList(); for(RobotInfo enemy: enemies){ if(enemy.location.distanceSquaredTo(rc.getLocation()) <= enemy.type.attackRadiusSquared){ @@ -905,36 +912,11 @@ public static ArrayList 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){ From a2a22e76a77c277da28d3793c965b6b339800537 Mon Sep 17 00:00:00 2001 From: vilasopher Date: Mon, 11 Jan 2016 21:30:10 -0500 Subject: [PATCH 2/8] Update RobotPlayer.java --- RobotPlayer.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/RobotPlayer.java b/RobotPlayer.java index 86f8316..abf068e 100644 --- a/RobotPlayer.java +++ b/RobotPlayer.java @@ -127,6 +127,7 @@ public void run() { RESOURCE_FUNCTIONS.BUG(RESOURCE_FUNCTIONS.mostRecentEnemyArchonLocation()); }*/ + Clock.yield(); } catch (Exception e) { e.printStackTrace(); } @@ -273,8 +274,17 @@ 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 scoutType = getScoutInitType(); + int roundNum = rc.getRoundNum(); + boolean isCloseToZombieRound = false; + for (int i = 0; i < zombieRounds.length && !isCloseToZombieRound; i++) { + isCloseToZombieRound = (Math.abs(roundNum - zombieRounds[i]) < 5); + } + if (isCloseToZombieRound) { + scoutType = getScoutHerdingType(); + } FancyMessage.sendMessage(0,scoutType.first | scoutType.second,scoutType.third,3); } } @@ -288,6 +298,10 @@ public void run(){ public Triple getScoutInitType(){ return new Triple(0,0,0); } + + public Triple getScoutHerdingType(){ + return new Triple(1,1,1); + } } /** @@ -341,6 +355,7 @@ public void run(){ if(x.bits[2]){ mostRecentArchonLocation = new MapLocation(x.ints.first >> 16,x.ints.second); } + System.out.println("Running as zombie herder"); runAsZombieHerder(); }else if((x.ints.first & 3) == 2){ runAsTurretSights(x.ints.second); @@ -413,6 +428,7 @@ public void runAsTurretSights(int turretID){ while(true){ try{ + Clock.yield(); }catch(Exception e){ e.printStackTrace(); } @@ -431,6 +447,7 @@ public void runAsZombieBomber(){ }else{ runAsArchonSearcher(); } + Clock.yield(); }catch(Exception e){ e.printStackTrace(); } From 326743ed82458a0b2d564c73f25005d92cf1e44c Mon Sep 17 00:00:00 2001 From: vilasopher Date: Mon, 11 Jan 2016 22:09:45 -0500 Subject: [PATCH 3/8] Update RobotPlayer.java --- RobotPlayer.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/RobotPlayer.java b/RobotPlayer.java index abf068e..8428e8a 100644 --- a/RobotPlayer.java +++ b/RobotPlayer.java @@ -260,7 +260,7 @@ public void run(){ FancyMessage x = FancyMessage.getFromRecievedSignal(signals[i]); if(x.isMessage){ if(x.type == 2){ - mostRecentEnemyArchonLocations.add(new Triple(0,new MapLocation(x.ints.first,x.ints.second),rc.getRoundNum())); + mostRecentEnemyArchonLocations.add(new Triple(0,new MapLocation(x.ints.first - 16000,x.ints.second - 16000),rc.getRoundNum())); } } } @@ -277,12 +277,13 @@ public void run(){ //Also signals the scout which type to become Clock.yield(); Triple 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]) < 5); + isCloseToZombieRound = (Math.abs(roundNum - zombieRounds[i]) < 10); } - if (isCloseToZombieRound) { + if (mostRecentEnemyArchonLocations.size() != 0 && isCloseToZombieRound) { scoutType = getScoutHerdingType(); } FancyMessage.sendMessage(0,scoutType.first | scoutType.second,scoutType.third,3); @@ -300,7 +301,11 @@ public Triple getScoutInitType(){ } public Triple getScoutHerdingType(){ - return new Triple(1,1,1); + MapLocation enemyArchonLocation = RESOURCE_FUNCTIONS.mostRecentEnemyArchonLocation(); + System.out.println("enemyArchonLocation =" + enemyArchonLocation); + int xPosition = enemyArchonLocation.x << 4; + int yPosition = enemyArchonLocation.y; + return new Triple(1,xPosition,yPosition); } } @@ -353,9 +358,9 @@ public void run(){ 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 >> 4,x.ints.second); } - System.out.println("Running as zombie herder"); + 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); From 51e5117a5753bcf83a3ced4a02057d48f683305e Mon Sep 17 00:00:00 2001 From: vilasopher Date: Mon, 11 Jan 2016 22:26:43 -0500 Subject: [PATCH 4/8] Update RobotPlayer.java --- RobotPlayer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RobotPlayer.java b/RobotPlayer.java index 8428e8a..ebae454 100644 --- a/RobotPlayer.java +++ b/RobotPlayer.java @@ -303,7 +303,7 @@ public Triple getScoutInitType(){ public Triple getScoutHerdingType(){ MapLocation enemyArchonLocation = RESOURCE_FUNCTIONS.mostRecentEnemyArchonLocation(); System.out.println("enemyArchonLocation =" + enemyArchonLocation); - int xPosition = enemyArchonLocation.x << 4; + int xPosition = enemyArchonLocation.x << 2; int yPosition = enemyArchonLocation.y; return new Triple(1,xPosition,yPosition); } @@ -358,7 +358,7 @@ public void run(){ runAsArchonSearcher(); }else if((x.ints.first & 3) == 1){ if(x.bits[2]){ - mostRecentArchonLocation = new MapLocation(x.ints.first >> 4,x.ints.second); + mostRecentArchonLocation = new MapLocation(x.ints.first >> 2,x.ints.second); } System.out.println("Running as zombie herder to archon at (" + mostRecentArchonLocation.x + "," + mostRecentArchonLocation.y + ")"); runAsZombieHerder(); From b235e327c461b53381f9f3ec0882426eb0d6dc35 Mon Sep 17 00:00:00 2001 From: androidmage Date: Mon, 11 Jan 2016 22:44:07 -0500 Subject: [PATCH 5/8] Get rid of guard nullpointerexception --- RobotPlayer.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/RobotPlayer.java b/RobotPlayer.java index ebae454..d91ee99 100644 --- a/RobotPlayer.java +++ b/RobotPlayer.java @@ -174,10 +174,12 @@ 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){ + for(RobotInfo robot:robots){ + if(robot.location.distanceSquaredTo(archonLocation) < 25){ + targetFound = true; + break; + } } } if(targetFound == false){ From 04d7828633f411b213d36676db2d02acd60f4172 Mon Sep 17 00:00:00 2001 From: vilasopher Date: Mon, 11 Jan 2016 22:46:45 -0500 Subject: [PATCH 6/8] Update RobotPlayer.java --- RobotPlayer.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/RobotPlayer.java b/RobotPlayer.java index d91ee99..0181a80 100644 --- a/RobotPlayer.java +++ b/RobotPlayer.java @@ -359,9 +359,7 @@ 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 >> 2,x.ints.second); - } + mostRecentArchonLocation = new MapLocation(x.ints.first >> 2,x.ints.second); System.out.println("Running as zombie herder to archon at (" + mostRecentArchonLocation.x + "," + mostRecentArchonLocation.y + ")"); runAsZombieHerder(); }else if((x.ints.first & 3) == 2){ From 37f8c150b7bca905a4cd19793649cfdb6409cdd4 Mon Sep 17 00:00:00 2001 From: androidmage Date: Mon, 11 Jan 2016 23:07:13 -0500 Subject: [PATCH 7/8] Guard Null pointer exception actually fixed --- RobotPlayer.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/RobotPlayer.java b/RobotPlayer.java index 0181a80..14737c7 100644 --- a/RobotPlayer.java +++ b/RobotPlayer.java @@ -174,7 +174,7 @@ public void run() { if(rc.isCoreReady()){ RobotInfo[] robots = rc.senseNearbyRobots(); boolean targetFound = false; - if(robots != null){ + if(robots != null && archonLocation != null){ for(RobotInfo robot:robots){ if(robot.location.distanceSquaredTo(archonLocation) < 25){ targetFound = true; @@ -182,7 +182,7 @@ public void run() { } } } - if(targetFound == false){ + if(targetFound == false && archonLocation != null){ RESOURCE_FUNCTIONS.BUG(archonLocation); } } @@ -203,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) { From b424885984060cac202dc581504d5670349394da Mon Sep 17 00:00:00 2001 From: vilasopher Date: Tue, 12 Jan 2016 06:40:16 -0500 Subject: [PATCH 8/8] Update RobotPlayer.java --- RobotPlayer.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/RobotPlayer.java b/RobotPlayer.java index 14737c7..d8855c3 100644 --- a/RobotPlayer.java +++ b/RobotPlayer.java @@ -305,8 +305,8 @@ public Triple getScoutInitType(){ public Triple getScoutHerdingType(){ MapLocation enemyArchonLocation = RESOURCE_FUNCTIONS.mostRecentEnemyArchonLocation(); System.out.println("enemyArchonLocation =" + enemyArchonLocation); - int xPosition = enemyArchonLocation.x << 2; - int yPosition = enemyArchonLocation.y; + int xPosition = (enemyArchonLocation.x + 16000) << 2; + int yPosition = (enemyArchonLocation.y + 16000); return new Triple(1,xPosition,yPosition); } } @@ -359,7 +359,7 @@ public void run(){ if((x.ints.first & 3) == 0){ runAsArchonSearcher(); }else if((x.ints.first & 3) == 1){ - mostRecentArchonLocation = new MapLocation(x.ints.first >> 2,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){