> // when we get closer to a wall than "double wall_avoid_distance"
> change direction and go back
> private double avoidWalls() {
>
> double wall_avoid_distance = 60;
> double fieldHeight = getBattleFieldHeight();
> double fieldWidth = getBattleFieldWidth();
> double centerX = (fieldWidth / 2);
> double centerY = (fieldHeight / 2);
> double currentHeading = getHeading();
> double x = getX();
> double y = getY();
> if (x < wall_avoid_distance || x > fieldWidth -
> wall_avoid_distance) {
> moveDirection *= -1;
> }
> if (y < wall_avoid_distance || y > fieldHeight -
> wall_avoid_distance) {
> moveDirection *= -1;
> }
> return moveDirection;
> }
One problem I can see with that is that if you are approaching a
corner you will reverse direction twice and end up carrying on in the
same direction. The second "if" should be an "else if". Other than
that, it looks like your method should work fairly well in most
situations (I assume you are initialising moveDirection to 1
somewhere). You would be better off taking the direction of travel
into account, though. If you're really close to the wall but moving
roughly parallel to it, there is no need to change direction (while
changing direction you're roughly stationary which makes you easier to
hit by head on targetting, which I guess most of your opponents are
using).