Paulo Coelho
2008-10-06 20:24:23 UTC
I resolve my problem creating a method goToPoint(x,y). In this method the values of 'x' and 'y' are limited to borders of the arena (minus the radius of the robot). Try this.... you sure will learn more...
Sorry for my english.
/\ A vida, nada mais é que uma enorme montanha russa! /\
\/ Só nos resta aproveitar! \/
Flw, Mumak Gnod
----- Mensagem original ----
De: Julian Kent <***@fastmail.net>
Para: ***@yahoogroups.com
Enviadas: Quinta-feira, 2 de Outubro de 2008 11:01:48
Assunto: Re: [Robocode] simple wall avoidance
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)
Julian Kent
***@fastmail. net
Sorry for my english.
/\ A vida, nada mais é que uma enorme montanha russa! /\
\/ Só nos resta aproveitar! \/
Flw, Mumak Gnod
----- Mensagem original ----
De: Julian Kent <***@fastmail.net>
Para: ***@yahoogroups.com
Enviadas: Quinta-feira, 2 de Outubro de 2008 11:01:48
Assunto: Re: [Robocode] simple wall avoidance
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)
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.
public void onScannedRobot( ScannedRobotEven t 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(HitWallEv ent 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 = getBattleFieldHeigh t();
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
--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.
public void onScannedRobot( ScannedRobotEven t 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(HitWallEv ent 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 = getBattleFieldHeigh t();
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
***@fastmail. net
--
http://www.fastmail .fm - The way an email service should be
Novos endereços, o Yahoo! que você conhece. Crie um email novo com a sua cara @ymail.com ou @rocketmail.com.
http://br.new.mail.yahoo.com/addresses
http://www.fastmail .fm - The way an email service should be
Novos endereços, o Yahoo! que você conhece. Crie um email novo com a sua cara @ymail.com ou @rocketmail.com.
http://br.new.mail.yahoo.com/addresses