Talk:Wall Smoothing/Implementations

From Robowiki
< Talk:Wall Smoothing
Revision as of 18:58, 11 April 2011 by Khanguy (talk | contribs) (my wall hugging code)
Jump to navigation Jump to search

Hey, I need some help with wall hugging(my question is here because I base my wall smoothing implementation on wall smoothing). I am using PEZ's wall smoothing code to hug walls. The only differences being that when I call the method I use getHeadingRadians() instead of absoluteBearing and I also removed -Math.PI/2*direction from the variable goalDirection. My problem here is not when it hug the walls clockwise(it hugs them perfectly), but when it tries reverse direction by going anticlockwise. It seizes up and oscillates between a few pixels. Thanks in advance --Khanguy 21:44, 10 April 2011 (UTC)

Hmm, kind of hard to say without seeing the code. My guesses would be your back-as-front method is messed up (you have right angle to move in but aren't moving that way correctly), you're not calculating current direction correctly, or you just lost some direction-sensitive piece of logic in your adaptation of the code. Can you draw (or even just print out) the angles that are being considered, like in this YouTube video? That should offer some clues. --Voidious 02:01, 11 April 2011 (UTC)

static double direction;	//1 for clockwise or -1 for counterclockwise
.
.
.
//in the onscannedmethod
wallhugging(getHeadingRadians()); //Dunno why I did this, but it works!
.
.
.
//in the onHitByBullet method
direction = -direction; // reverse direction when hit
.
.
.
// this is the absolute heading I want to move in to go clockwise or
// counterclockwise around my enemy if I want to move closer to them,
// I would use less of an offset from absBearing (I'll go right toward
// them if I move at absBearing)
public void wallhugging{
double goalDirection = absBearing;// I want to go straight to the wall
Rectangle2D fieldRect = new Rectangle2D.Double(18, 18, getBattleFieldWidth()-36,
    getBattleFieldHeight()-36);
while (!fieldRect.contains(getX()+Math.sin(goalDirection)*160, getY()+
        Math.cos(goalDirection)*160))
{
	goalDirection += direction*.1;	//turn a little toward enemy and try again
}
double turn =
    robocode.util.Utils.normalRelativeAngle(goalDirection-getHeadingRadians());
if (Math.abs(turn) > Math.PI/2)
{
	turn = robocode.util.Utils.normalRelativeAngle(turn + Math.PI);
	setBack(100);
}
else
	setAhead(100);
setTurnRightRadians(turn);
}

I don't know how to find the angles, but the code I was testing is above. This works clockwise, but it sometimes stalls when trying to hug walls counterclockwise. --Khanguy 17:58, 11 April 2011 (UTC)

You cannot post new threads to this discussion page because it has been protected from new threads, or you do not currently have permission to edit.

There are no threads on this page yet.