From 84103b8a292dd9f22c1da8c97dfabcb9efb12c33 Mon Sep 17 00:00:00 2001 From: androidmage Date: Sat, 9 Jan 2016 23:36:37 -0500 Subject: [PATCH 1/8] Guards stay close to creator and more scouts made --- RobotPlayer.java | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/RobotPlayer.java b/RobotPlayer.java index 9aa776a..6979a87 100644 --- a/RobotPlayer.java +++ b/RobotPlayer.java @@ -143,9 +143,11 @@ public void run() { private class Guard { public MapLocation startLocation; + public int moveCount; public Guard() { startLocation = rc.getLocation(); + moveCount = 0; } public void run() { @@ -154,7 +156,7 @@ public void run() { Signal[] signals = rc.emptySignalQueue(); if(signals.length > 0){ //if == 0, no signals, so not ready for(Signal s: signals){ - if(s.getTeam() == ourTeam && rc.senseRobot(s.getID()).type == RobotType.ARCHON){ + if(moveCount < 1 && s.getTeam() == ourTeam && rc.senseRobot(s.getID()).type == RobotType.ARCHON){ FancyMessage f = FancyMessage.getFromRecievedSignal(s); MapLocation archonLocation = f.senderLocation; Direction archonDirection = rc.getLocation().directionTo(archonLocation); @@ -162,11 +164,25 @@ public void run() { if(rc.isCoreReady()){ if(rc.canMove(oppositeDirection)){ rc.move(oppositeDirection); + moveCount += 1; } } } } } + if(rc.isCoreReady()){ + RobotInfo[] robots = rc.senseNearbyRobots(); + boolean targetFound = false; + for(RobotInfo robot:robots){ + if(robot.location.distanceSquaredTo(startLocation) < 25){ + targetFound = true; + break; + } + } + if(targetFound == false){ + RESOURCE_FUNCTIONS.BUG(startLocation); + } + } if(rc.isWeaponReady()){ RobotInfo[] robots = rc.senseNearbyRobots(); for(RobotInfo robot: robots) { @@ -578,10 +594,13 @@ public static RobotType chooseRobotType() { if(numberOfRobotsInRadiusAndThoseRobots(RobotType.GUARD,3,ourTeam).first == 7){ return RobotType.SCOUT; } - int fate = randall.nextInt(2); - if(fate == 1){ + int fate = randall.nextInt(3); + if(fate == 0){ return RobotType.SOLDIER; } + if(fate == 1){ + return RobotType.SCOUT; + } return RobotType.GUARD; } From 4183a2169ae75e1e9fd1c75d11595b36f6d330cd Mon Sep 17 00:00:00 2001 From: androidmage Date: Sat, 9 Jan 2016 23:36:58 -0500 Subject: [PATCH 2/8] Guards stay close to creator and more scouts made --- RobotPlayer.java | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/RobotPlayer.java b/RobotPlayer.java index 9aa776a..6979a87 100644 --- a/RobotPlayer.java +++ b/RobotPlayer.java @@ -143,9 +143,11 @@ public void run() { private class Guard { public MapLocation startLocation; + public int moveCount; public Guard() { startLocation = rc.getLocation(); + moveCount = 0; } public void run() { @@ -154,7 +156,7 @@ public void run() { Signal[] signals = rc.emptySignalQueue(); if(signals.length > 0){ //if == 0, no signals, so not ready for(Signal s: signals){ - if(s.getTeam() == ourTeam && rc.senseRobot(s.getID()).type == RobotType.ARCHON){ + if(moveCount < 1 && s.getTeam() == ourTeam && rc.senseRobot(s.getID()).type == RobotType.ARCHON){ FancyMessage f = FancyMessage.getFromRecievedSignal(s); MapLocation archonLocation = f.senderLocation; Direction archonDirection = rc.getLocation().directionTo(archonLocation); @@ -162,11 +164,25 @@ public void run() { if(rc.isCoreReady()){ if(rc.canMove(oppositeDirection)){ rc.move(oppositeDirection); + moveCount += 1; } } } } } + if(rc.isCoreReady()){ + RobotInfo[] robots = rc.senseNearbyRobots(); + boolean targetFound = false; + for(RobotInfo robot:robots){ + if(robot.location.distanceSquaredTo(startLocation) < 25){ + targetFound = true; + break; + } + } + if(targetFound == false){ + RESOURCE_FUNCTIONS.BUG(startLocation); + } + } if(rc.isWeaponReady()){ RobotInfo[] robots = rc.senseNearbyRobots(); for(RobotInfo robot: robots) { @@ -578,10 +594,13 @@ public static RobotType chooseRobotType() { if(numberOfRobotsInRadiusAndThoseRobots(RobotType.GUARD,3,ourTeam).first == 7){ return RobotType.SCOUT; } - int fate = randall.nextInt(2); - if(fate == 1){ + int fate = randall.nextInt(3); + if(fate == 0){ return RobotType.SOLDIER; } + if(fate == 1){ + return RobotType.SCOUT; + } return RobotType.GUARD; } From af6341da78c0f075194f88e3d9862a6ba10d1a67 Mon Sep 17 00:00:00 2001 From: androidmage Date: Sat, 9 Jan 2016 23:44:26 -0500 Subject: [PATCH 3/8] Got rid of no longer necessary println statements --- RobotPlayer.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/RobotPlayer.java b/RobotPlayer.java index 6979a87..0a9745b 100644 --- a/RobotPlayer.java +++ b/RobotPlayer.java @@ -86,9 +86,7 @@ public void run() { // receive a message containing enemy archon ID if (s.getTeam() == ourTeam) { FancyMessage f = FancyMessage.getFromRecievedSignal(s); - System.out.println(f.type); if(f.type == 2){ - System.out.println("66"); int xPos = f.ints.first; int yPos = f.ints.second; enemyArchonLocation = new MapLocation(xPos, yPos); @@ -208,15 +206,12 @@ public void run() { } for(RobotInfo robot: robots) { if((robot.team == opponentTeam) && robot.location.distanceSquaredTo(startLocation) < 25) { - System.out.println("pikachu"); target = robot.location; break; } } if(target != null){ - System.out.println("target found"); RESOURCE_FUNCTIONS.BUG(target); - System.out.println("Still alive"); } } } @@ -312,7 +307,6 @@ public void run(){ try{ MapLocation enemyArchonLocation = RESOURCE_FUNCTIONS.scanArchonLocation(); if(enemyArchonLocation != null){ - System.out.println("XXXXXXXXXXXXXXX"); int xPos = enemyArchonLocation.x; int yPos = enemyArchonLocation.y; FancyMessage.sendMessage(2, xPos, yPos, 1000); From 58c5477fc9265b6a531d21a7deb5d99c97b45f4a Mon Sep 17 00:00:00 2001 From: katiekang1998 Date: Sun, 10 Jan 2016 13:39:10 -0500 Subject: [PATCH 4/8] newArchonRunAway --- RobotPlayer.java | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/RobotPlayer.java b/RobotPlayer.java index 0a9745b..d286886 100644 --- a/RobotPlayer.java +++ b/RobotPlayer.java @@ -251,6 +251,7 @@ public void run(){ try{ //If it can, always tries to build Scouts. if(rc.isCoreReady()){ + RESOURCE_FUNCTIONS.escapeEnemy(rc); if(rc.getRoundNum() % 100 == 0){ FancyMessage.sendMessage(1, 1, 1, 3); } @@ -759,6 +760,60 @@ public static boolean BUG(MapLocation target) throws GameActionException{ rc.setIndicatorString(0,"Failed outside of branch"); return false; } + public static void escapeEnemy(RobotController rc){ + MapLocation enemyLocation = locateEnemy(rc); + Direction moveDirection = calculateEscapeDirection(rc, enemyLocation); + if(rc.canMove(moveDirection)){ + try{ + rc.move(moveDirection); + } + catch (Exception e) { + System.out.println(e.getMessage()); + e.printStackTrace(); + } + + } + } + + public static MapLocation locateEnemy(RobotController rc){ + RobotInfo[] sensedRobots = rc.senseNearbyRobots(); + MapLocation closest = null; + for(RobotInfo robot: sensedRobots){ + if(robot.team == opponentTeam || robot.team == Team.ZOMBIE){ + return robot.location; + } + } + return null; + } + + public static Direction calculateEscapeDirection(RobotController rc, 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; + + } } /** From 069f39a44f17c8f265991311d97a95d8f32ff749 Mon Sep 17 00:00:00 2001 From: androidmage Date: Sun, 10 Jan 2016 13:59:36 -0500 Subject: [PATCH 5/8] Got rid of nullpointerexception for archon --- RobotPlayer.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/RobotPlayer.java b/RobotPlayer.java index d286886..19d0f6e 100644 --- a/RobotPlayer.java +++ b/RobotPlayer.java @@ -762,6 +762,9 @@ public static boolean BUG(MapLocation target) throws GameActionException{ } public static void escapeEnemy(RobotController rc){ MapLocation enemyLocation = locateEnemy(rc); + if(enemyLocation == null){ + return; + } Direction moveDirection = calculateEscapeDirection(rc, enemyLocation); if(rc.canMove(moveDirection)){ try{ @@ -776,11 +779,13 @@ public static void escapeEnemy(RobotController rc){ } public static MapLocation locateEnemy(RobotController rc){ - RobotInfo[] sensedRobots = rc.senseNearbyRobots(); + RobotInfo[] sensedRobots = rc.senseHostileRobots(rc.getLocation(),rc.getType().sensorRadiusSquared); MapLocation closest = null; - for(RobotInfo robot: sensedRobots){ - if(robot.team == opponentTeam || robot.team == Team.ZOMBIE){ - return robot.location; + if(sensedRobots != null){ + for(RobotInfo robot: sensedRobots){ + if(robot.team == opponentTeam || robot.team == Team.ZOMBIE){ + return robot.location; + } } } return null; From 59442b4a76a2d0a0a3241a997632560dda67f3a3 Mon Sep 17 00:00:00 2001 From: androidmage Date: Sun, 10 Jan 2016 14:53:25 -0500 Subject: [PATCH 6/8] archon only moves away if in range of enemy attack --- RobotPlayer.java | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/RobotPlayer.java b/RobotPlayer.java index 19d0f6e..67ebb27 100644 --- a/RobotPlayer.java +++ b/RobotPlayer.java @@ -251,7 +251,7 @@ public void run(){ try{ //If it can, always tries to build Scouts. if(rc.isCoreReady()){ - RESOURCE_FUNCTIONS.escapeEnemy(rc); + RESOURCE_FUNCTIONS.escapeEnemy(); if(rc.getRoundNum() % 100 == 0){ FancyMessage.sendMessage(1, 1, 1, 3); } @@ -760,12 +760,16 @@ public static boolean BUG(MapLocation target) throws GameActionException{ rc.setIndicatorString(0,"Failed outside of branch"); return false; } - public static void escapeEnemy(RobotController rc){ - MapLocation enemyLocation = locateEnemy(rc); + public static void escapeEnemy(){ + RobotInfo[] enemies = locateEnemy(); + if(enemies == null){ + return; + } + MapLocation enemyLocation = dangerousRobotLocation(enemies); if(enemyLocation == null){ return; } - Direction moveDirection = calculateEscapeDirection(rc, enemyLocation); + Direction moveDirection = calculateEscapeDirection(enemyLocation); if(rc.canMove(moveDirection)){ try{ rc.move(moveDirection); @@ -778,20 +782,24 @@ public static void escapeEnemy(RobotController rc){ } } - public static MapLocation locateEnemy(RobotController rc){ + public static RobotInfo[] locateEnemy(){ RobotInfo[] sensedRobots = rc.senseHostileRobots(rc.getLocation(),rc.getType().sensorRadiusSquared); - MapLocation closest = null; if(sensedRobots != null){ - for(RobotInfo robot: sensedRobots){ - if(robot.team == opponentTeam || robot.team == Team.ZOMBIE){ - return robot.location; - } + return sensedRobots; + } + return null; + } + + public static MapLocation dangerousRobotLocation(RobotInfo[] enemies){ + for(RobotInfo enemy: enemies){ + if(enemy.location.distanceSquaredTo(rc.getLocation()) <= enemy.type.attackRadiusSquared){ + return enemy.location; } } return null; } - public static Direction calculateEscapeDirection(RobotController rc, MapLocation enemyLocation){ + public static Direction calculateEscapeDirection(MapLocation enemyLocation){ MapLocation myLocation = rc.getLocation(); int xDifference = enemyLocation.x - myLocation.x; int yDifference = enemyLocation.y - myLocation.y; From 3476ccad126061f9929ddb3a8ac6a2ef39efff6b Mon Sep 17 00:00:00 2001 From: androidmage Date: Sun, 10 Jan 2016 15:17:13 -0500 Subject: [PATCH 7/8] Guards follow our archons --- RobotPlayer.java | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/RobotPlayer.java b/RobotPlayer.java index 67ebb27..2ab91b1 100644 --- a/RobotPlayer.java +++ b/RobotPlayer.java @@ -140,17 +140,17 @@ public void run() { */ private class Guard { - public MapLocation startLocation; + public MapLocation archonLocation; public int moveCount; public Guard() { - startLocation = rc.getLocation(); moveCount = 0; } public void run() { while(true){ try{ + archonLocation = RESOURCE_FUNCTIONS.scanFriendlyArchonLocation(); Signal[] signals = rc.emptySignalQueue(); if(signals.length > 0){ //if == 0, no signals, so not ready for(Signal s: signals){ @@ -172,13 +172,13 @@ public void run() { RobotInfo[] robots = rc.senseNearbyRobots(); boolean targetFound = false; for(RobotInfo robot:robots){ - if(robot.location.distanceSquaredTo(startLocation) < 25){ + if(robot.location.distanceSquaredTo(archonLocation) < 25){ targetFound = true; break; } } if(targetFound == false){ - RESOURCE_FUNCTIONS.BUG(startLocation); + RESOURCE_FUNCTIONS.BUG(archonLocation); } } if(rc.isWeaponReady()){ @@ -199,13 +199,13 @@ public void run() { if(rc.isWeaponReady()){ MapLocation target = null; for(RobotInfo robot: robots) { - if((robot.team == Team.ZOMBIE) && robot.location.distanceSquaredTo(startLocation) < 25) { + if((robot.team == Team.ZOMBIE) && robot.location.distanceSquaredTo(archonLocation) < 25) { target = robot.location; break; } } for(RobotInfo robot: robots) { - if((robot.team == opponentTeam) && robot.location.distanceSquaredTo(startLocation) < 25) { + if((robot.team == opponentTeam) && robot.location.distanceSquaredTo(archonLocation) < 25) { target = robot.location; break; } @@ -431,6 +431,23 @@ public static MapLocation scanArchonLocation() { } return null; } + + /** + * + * MapLocation scanFriendlyArchonLocation + * @return location of friendly archon + * + */ + public static MapLocation scanFriendlyArchonLocation() { + RobotInfo[] robots; + robots = rc.senseNearbyRobots(RobotType.SCOUT.sensorRadiusSquared, ourTeam); + for(int i = 0; i < robots.length; i++) { + if(robots[i].type == RobotType.ARCHON) { + return robots[i].location; + } + } + return null; + } /** * int dirToInt From f83fb5f0730de7101204973e747e8e5e3739d2f0 Mon Sep 17 00:00:00 2001 From: katiekang1998 Date: Sun, 10 Jan 2016 15:26:20 -0500 Subject: [PATCH 8/8] attackweakestenemy --- RobotPlayer.java | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/RobotPlayer.java b/RobotPlayer.java index 2ab91b1..ea4883d 100644 --- a/RobotPlayer.java +++ b/RobotPlayer.java @@ -5,6 +5,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.ArrayList; +import java.lang.Math; public class RobotPlayer{ /** @@ -112,13 +113,14 @@ public void run() { RESOURCE_FUNCTIONS.BUG(enemyArchonLocation); } if(rc.isWeaponReady()){ - RobotInfo[] robots = rc.senseNearbyRobots(); + /* RobotInfo[] robots = rc.senseNearbyRobots(); for(RobotInfo robot: robots) { if((robot.team == Team.ZOMBIE || robot.team == opponentTeam) && rc.canAttackLocation(robot.location)) { rc.attackLocation(robot.location); break; } - } + }*/ + RESOURCE_FUNCTIONS.attackWeakestEnemy(); } // If there are enough scouts around, move out towards enemy Archon /* (mostRecentEnemyArchonLocations.size() > 0 && RESOURCE_FUNCTIONS.numberOfRobotsInRadiusAndThoseRobots(RobotType.SOLDIER, RobotType.SOLDIER.sensorRadiusSquared, rc.getTeam()).first > 5) { @@ -183,7 +185,7 @@ public void run() { } if(rc.isWeaponReady()){ RobotInfo[] robots = rc.senseNearbyRobots(); - for(RobotInfo robot: robots) { + /*for(RobotInfo robot: robots) { if((robot.team == Team.ZOMBIE) && rc.canAttackLocation(robot.location)) { rc.attackLocation(robot.location); break; @@ -194,7 +196,9 @@ public void run() { rc.attackLocation(robot.location); break; } - } + }*/ + + RESOURCE_FUNCTIONS.attackWeakestEnemy(); //If didn't attack anyone that is adjacent if(rc.isWeaponReady()){ MapLocation target = null; @@ -844,6 +848,40 @@ else if(yDifference>0){ return Direction.SOUTH; } + + public static void attackWeakestEnemy(){ + MapLocation weakestEnemyLocation = locateWeakestEnemy(); + if(weakestEnemyLocation==null){ + return; + } + try{ + rc.attackLocation(weakestEnemyLocation); + } + catch (Exception e) { + System.out.println(e.getMessage()); + e.printStackTrace(); + } + + } + + public static MapLocation locateWeakestEnemy(){ + RobotInfo[] sensedRobots = rc.senseHostileRobots(rc.getLocation(),Math.min(rc.getType().sensorRadiusSquared, rc.getType().attackRadiusSquared)); + RobotInfo weakest=null; + if(sensedRobots != null){ + for(RobotInfo robot: sensedRobots){ + if(robot.team == opponentTeam || robot.team == Team.ZOMBIE){ + if(weakest == null || robot.health