« Return to Thread: simple wall avoidance

Re: simple wall avoidance

by Julian Kent :: Rate this Message:

Reply to Author | View in Thread

I'm not sure what's wrong with your code, but there are better ways of
avoiding walls than simply reversing. For example, you can test 3 points
in front of you, one straight, one to the left, one to the right, and
see which ones are inside the field. If the one straight ahead is in the
field keep going straight, otherwise try the one on the right, if that's
in the field turn right, otherwise turn left. There is also a method
called "wall smoothing" where you see how far you would have to 'rotate'
this point straight in front of you towards the enemy in order for it to
be inside the field. A good value for the distance of the point is 160.

Good luck with the project,
Julian (AKA Skilgannon on RoboWiki)


On Thu, 02 Oct 2008 08:21:28 -0000, "aatomik" <aatomik@...>
said:

> Hi, I'm relatively new to java and robocode as well, but slowly I am
> getting the hang of it. At the moment I'm building a robot to
> participate in our school competition, and it is evolving quite nicely.
> It shoots the enemy using head on targeting and moves around it in a
> circular way. The problem that I have now is that it collides with the
> walls all the time and I'm trying to find some kind of solution to
> solve it.
> I came to an idea to calculate my x,y position and compare it to a
> double wall_avoid_distance. At any point when my tank is closer to the
> wall than wall_avoid_distance it should change it's direction.
> Well, I put in code and it chages the direction with one major problem
> - it collides with the wall and only after that it  seems to
> understand that it's time to go the other way. Maybe someone here can
> tell me, what am I doing wrong here.
> This is a part of my code:
>
> public void onScannedRobot(ScannedRobotEvent event) {
> // move around enemy tank in a circular way
> setTurnRight(event.getBearing() + 90);
> setAhead(100 * avoidWalls());
> double vastase_peilung = event.getBearing();
> double tuki_suund = getGunHeading();
> double minu_suund = getHeading();
> // this is for shooting and calculating enemy position
> double vastase_suund = minu_suund + vastase_peilung;
> double keeramisnurk = vastase_suund - tuki_suund;
> keeramisnurk = normalRelativeAngle(keeramisnurk);
>
> turnGunRight(keeramisnurk);
>
> setFire(3);
> execute();
> }
>
> public void onHitWall(HitWallEvent event) {
>       out.println("Ouch, I hit a wall bearing " + event.getBearing()
> + " degrees.");
>   }
>
> // 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;
> }
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
--
  Julian Kent
  jkflying@...

--
http://www.fastmail.fm - The way an email service should be

 « Return to Thread: simple wall avoidance