diff --git a/src/group10player/DeliveryDrone.java b/src/group10player/DeliveryDrone.java index 9c5ef3e..9b6b991 100644 --- a/src/group10player/DeliveryDrone.java +++ b/src/group10player/DeliveryDrone.java @@ -280,7 +280,6 @@ public void dropOnWall() throws GameActionException { } int distance = myLocation.distanceSquaredTo(dropTarget); - if(distance <= 0) { // System.out.println("Drone too close!"); tryMoveDirection(randomDirection()); @@ -333,7 +332,6 @@ public void searchForEnemy() public void searchForLandscaper() throws GameActionException { RobotInfo[] allied_robots = rc.senseNearbyRobots(24, rc.getTeam()); RobotInfo[] enemy_robots = rc.senseNearbyRobots(24, rc.getTeam().opponent()); - if (HQLocation == null){ tryFindHQLocation(); return; diff --git a/test/group10player/DeliveryDroneTest.java b/test/group10player/DeliveryDroneTest.java index db77bf4..c22021c 100644 --- a/test/group10player/DeliveryDroneTest.java +++ b/test/group10player/DeliveryDroneTest.java @@ -7,6 +7,7 @@ import org.scalactic.Or; import scala.collection.immutable.Map; +import java.util.ArrayList; import java.util.Vector; import static org.junit.Assert.assertEquals; @@ -242,4 +243,149 @@ public void dropOnWallTest2() throws GameActionException{ DDtest.dropOnWall(); } + @Test + public void dropOnWallTest3() throws GameActionException{ + when(RCtest.getLocation()).thenReturn(new MapLocation(100,100)); + DDtest.HQLocation = new MapLocation(2,2); + DDtest.dropOnWall(); + } + + @Test + public void dropOnWallTest4() throws GameActionException{ + MapLocation temp = new MapLocation(1,1); + when(RCtest.getLocation()).thenReturn(temp); + DDtest.HQLocation = new MapLocation(2,2); + when(RCtest.canSenseLocation(temp.add(Direction.NORTH))).thenReturn(true); + when(RCtest.isLocationOccupied(temp.add(Direction.NORTH))).thenReturn(false); + DDtest.dropOnWall(); + } + + @Test + public void dropOnWallTest5() throws GameActionException{ + MapLocation temp = new MapLocation(1,1); + when(RCtest.getLocation()).thenReturn(temp); + DDtest.HQLocation = new MapLocation(1,1); + when(RCtest.canSenseLocation(temp.add(Direction.NORTH))).thenReturn(true); + when(RCtest.isLocationOccupied(temp.add(Direction.NORTH))).thenReturn(false); + when(RCtest.canDropUnit(temp.directionTo(temp.add(Direction.NORTH)))).thenReturn(true); + DDtest.dropOnWall(); + } + + @Test + public void dropOnWallTest6() throws GameActionException{ + MapLocation temp = new MapLocation(4,4); + when(RCtest.getLocation()).thenReturn(temp); + DDtest.HQLocation = new MapLocation(1,1); + when(RCtest.canSenseLocation(temp.add(Direction.NORTH))).thenReturn(true); + when(RCtest.isLocationOccupied(temp.add(Direction.NORTH))).thenReturn(false); + DDtest.dropOnWall(); + } + + @Test + public void searchForLandscaperTest1() throws GameActionException{ + DDtest.searchForLandscaper(); + } + + @Test + public void searchForLandscaperTest2() throws GameActionException{ + DDtest.HQLocation = new MapLocation(1,1); + DDtest.searchForLandscaper(); + } + + @Test + public void searchForLandscaperTest3() throws GameActionException{ + when(RCtest.senseNearbyRobots(24,Team.A)).thenReturn(new RobotInfo[]{new RobotInfo(12, Team.A, RobotType.DELIVERY_DRONE, 0, true, 0, 0, 0, new MapLocation(4, 4))}); + when(RCtest.senseNearbyRobots(24,Team.B)).thenReturn(new RobotInfo[]{new RobotInfo(12, Team.B, RobotType.DELIVERY_DRONE, 0, true, 0, 0, 0, new MapLocation(5, 5))}); + DDtest.HQLocation = new MapLocation(1,1); + DDtest.searchForLandscaper(); + } + + @Test + public void searchForLandscaperTest4() throws GameActionException{ + when(RCtest.senseNearbyRobots(24,Team.A)).thenReturn(new RobotInfo[]{new RobotInfo(12, Team.A, RobotType.DELIVERY_DRONE, 0, true, 0, 0, 0, new MapLocation(4, 4))}); + when(RCtest.senseNearbyRobots(24,Team.B)).thenReturn(new RobotInfo[]{new RobotInfo(12, Team.B, RobotType.LANDSCAPER, 0, true, 0, 0, 0, new MapLocation(5, 5))}); + DDtest.HQLocation = new MapLocation(1,1); + DDtest.searchForLandscaper(); + } + + @Test + public void searchForLandscaperTest5() throws GameActionException{ + when(RCtest.senseNearbyRobots(24,Team.A)).thenReturn(new RobotInfo[]{new RobotInfo(12, Team.A, RobotType.DELIVERY_DRONE, 0, true, 0, 0, 0, new MapLocation(4, 4))}); + when(RCtest.senseNearbyRobots(24,Team.B)).thenReturn(new RobotInfo[]{new RobotInfo(12, Team.B, RobotType.MINER, 0, true, 0, 0, 0, new MapLocation(5, 5))}); + DDtest.HQLocation = new MapLocation(1,1); + DDtest.searchForLandscaper(); + } + + @Test + public void searchForLandscaperTest6() throws GameActionException{ + when(RCtest.senseNearbyRobots(24,Team.A)).thenReturn(new RobotInfo[]{new RobotInfo(12, Team.A, RobotType.LANDSCAPER, 0, true, 0, 0, 0, new MapLocation(4, 4))}); + when(RCtest.senseNearbyRobots(24,Team.B)).thenReturn(new RobotInfo[]{new RobotInfo(12, Team.B, RobotType.DELIVERY_DRONE, 0, true, 0, 0, 0, new MapLocation(5, 5))}); + DDtest.HQLocation = new MapLocation(1,1); + DDtest.searchForLandscaper(); + } + + @Test + public void searchForLandscaperTest7() throws GameActionException{ + DDtest.HQLocation = new MapLocation(1,1); + DDtest.target = 1; + when(RCtest.senseNearbyRobots(24,Team.A)).thenReturn(new RobotInfo[]{new RobotInfo(12, Team.A, RobotType.LANDSCAPER, 0, true, 0, 0, 0, new MapLocation(4, 4))}); + when(RCtest.senseNearbyRobots(24,Team.B)).thenReturn(new RobotInfo[]{new RobotInfo(12, Team.B, RobotType.DELIVERY_DRONE, 0, true, 0, 0, 0, new MapLocation(5, 5))}); + when(RCtest.senseRobot(1)).thenReturn(new RobotInfo(12, Team.A, RobotType.LANDSCAPER, 0, true, 0, 0, 0, new MapLocation(4, 4))); + when(RCtest.getLocation()).thenReturn(new MapLocation(2,2)); + DDtest.HQLocation = new MapLocation(1,1); + DDtest.searchForLandscaper(); + } + + @Test + public void grabLandscaperTest1() throws GameActionException{ + DDtest.grabLandscaper(); + } + + @Test + public void grabLandscaperTest2() throws GameActionException{ + DDtest.target = 1; + when(RCtest.senseRobot(1)).thenReturn(new RobotInfo(12, Team.A, RobotType.LANDSCAPER, 0, true, 0, 0, 0, new MapLocation(3, 3))); + DDtest.HQLocation = new MapLocation(2,2); + DDtest.grabLandscaper(); + } + + @Test + public void grabLandscaperTest3() throws GameActionException{ + DDtest.target = 1; + when(RCtest.senseRobot(1)).thenReturn(new RobotInfo(12, Team.A, RobotType.LANDSCAPER, 0, true, 0, 0, 0, new MapLocation(5, 5))); + DDtest.HQLocation = new MapLocation(2,2); + when(RCtest.getLocation()).thenReturn(new MapLocation(1,1)); + DDtest.grabLandscaper(); + } + + @Test + public void grabLandscaperTest4() throws GameActionException{ + DDtest.target = 1; + when(RCtest.senseRobot(1)).thenReturn(new RobotInfo(12, Team.A, RobotType.LANDSCAPER, 0, true, 0, 0, 0, new MapLocation(5, 5))); + DDtest.HQLocation = new MapLocation(2,2); + when(RCtest.getLocation()).thenReturn(new MapLocation(4,4)); + when(RCtest.canPickUpUnit(1)).thenReturn(true); + DDtest.grabLandscaper(); + } + + @Test + public void surroundHQtest1() throws GameActionException{ + DDtest.surroundHQ(); + } + + @Test + public void surroundHQtest2() throws GameActionException{ + DDtest.current_ring_pos = 10; + DDtest.ring_positions = new ArrayList(5); + DDtest.surroundHQ(); + } + + @Test + public void surroundHQtest3() throws GameActionException{ + DDtest.current_ring_pos = 3; + DDtest.ring_positions = new ArrayList(5); + when(RCtest.getLocation()).thenReturn(new MapLocation(2,2)); + DDtest.surroundHQ(); + } + }