SurfMover { void orbit(Point2D.Double myLocation, MoveEnemy duelEnemy) { _robot.setMaxVelocity(8); RobotState enemyState = duelEnemy.lastScanState; double orbitAbsBearing = DiaUtils.absoluteBearing(enemyState.location, myLocation); double retreatAngle = _distancer.orbitAttackAngle(myLocation.distance(enemyState.location)); double counterGoAngle = orbitAbsBearing + (SurfOption.COUNTER_CLOCKWISE.getDirection() * ((Math.PI / 2) + retreatAngle)); counterGoAngle = wallSmoothing(myLocation, counterGoAngle, SurfOption.COUNTER_CLOCKWISE); double clockwiseGoAngle = orbitAbsBearing + (SurfOption.CLOCKWISE.getDirection() * ((Math.PI / 2) + retreatAngle)); clockwiseGoAngle = wallSmoothing(myLocation, clockwiseGoAngle, SurfOption.CLOCKWISE); double goAngle; if (Math.abs( Utils.normalRelativeAngle(clockwiseGoAngle - orbitAbsBearing)) < Math.abs( Utils.normalRelativeAngle(counterGoAngle - orbitAbsBearing))) { _lastSurfOption = SurfOption.CLOCKWISE; goAngle = clockwiseGoAngle; } else { _lastSurfOption = SurfOption.COUNTER_CLOCKWISE; goAngle = counterGoAngle; } DiaUtils.setBackAsFront(_robot, goAngle); } SurfMover(AdvancedRobot robot, BattleField battleField,
      Collection<RoboGraphic> renderables, OutputStream out); void initRound(); void move(RobotState myRobotState, MoveEnemy duelEnemy,
      int wavesToSurf, boolean painting); void roundOver(MoveEnemy duelEnemy);  }
@Test public void testOrbit() { SurfMover mover = newSurfMover(); mover.orbit(newLocation(400, 300), newDuelEnemy(newLocation(400, 500))); verifySomeRobotMovement(); }
@Test public void testOrbitAwayFromWestWall() { SurfMover mover = newSurfMover(); when(diamond.getHeadingRadians()).thenReturn(Math.PI / 2); mover.orbit(newLocation(100, 200), newDuelEnemy(newLocation(100, 550))); verify(diamond).setMaxVelocity(8.0); verify(diamond).setAhead(anyDouble()); verify(diamond).setTurnRightRadians(anyDouble()); }
@Test public void testOrbitAwayFromEastWall() { SurfMover mover = newSurfMover(); when(diamond.getHeadingRadians()).thenReturn(Math.PI / 2); mover.orbit(newLocation(700, 200), newDuelEnemy(newLocation(700, 550))); verify(diamond).setMaxVelocity(8.0); verify(diamond).setBack(anyDouble()); verify(diamond).setTurnLeftRadians(anyDouble()); }
@Test public void testOrbitAwayFromNorthWall() { SurfMover mover = newSurfMover(); when(diamond.getHeadingRadians()).thenReturn(0D); mover.orbit(newLocation(300, 550), newDuelEnemy(newLocation(700, 550))); verify(diamond).setMaxVelocity(8.0); verify(diamond).setBack(anyDouble()); verify(diamond).setTurnRightRadians(anyDouble()); }
@Test public void testOrbitAwayFromSouthWall() { SurfMover mover = newSurfMover(); when(diamond.getHeadingRadians()).thenReturn(0D); mover.orbit(newLocation(300, 50), newDuelEnemy(newLocation(700, 50))); verify(diamond).setMaxVelocity(8.0); verify(diamond).setAhead(anyDouble()); verify(diamond).setTurnLeftRadians(anyDouble()); }
@Test public void testOrbitAwayFromCorner() { SurfMover mover = newSurfMover(); when(diamond.getHeadingRadians()).thenReturn(0D); mover.orbit(newLocation(50, 50), newDuelEnemy(newLocation(300, 100))); verify(diamond).setMaxVelocity(8.0); verify(diamond).setAhead(anyDouble()); verify(diamond).setTurnLeftRadians(anyDouble()); }