point object::findPosition(float margin, float x0, float x_size, float y0, float y_size)
{
	point dest (0, 0, this.position.z);
	float dist = 0;
	do
	{
		dest.x = x0+rand()*x_size;
		dest.y = y0+rand()*y_size;
		dist = distance(dest,this.position);
		if( radar(PracticeBot, direction(dest), 90) != null ) // find path that won't lead directly into PracticeBot
		{
			dist *= -1; // make sure the loop will be run again
		}
	}
	while( dist < margin );
	return dest;
}

extern void object::Hare2( )
{
	int nb = 0;
	point dest;
	float dist = 10; // minimal distance between target point and current position
	object bot;
	
	errmode(0);
	
	while ( true )
	{
		dest = findPosition(dist, cmdline(0), cmdline(1), cmdline(2), cmdline(3));
		turn(direction(dest)); // avoids goto() shenanigans, causing robots to drive into each other, see issue #1491
		goto(dest);
		wait(2);
		bot = radar(PracticeBot, 0, 360, 0, 10);
		if ( bot == null )
		{
			nb = 0;
			message("Failure, you are too far away. Start again 10x.", DisplayError);
		}
		else
		{
			nb ++;
			if ( nb < 10 )
			{
				message("Distance OK, "+(10-nb)+" more to come");
			}
			else
			{
				message("Well done, let's go home.", DisplayInfo);
				turn(direction(10, -77.5)); // same as above
				goto(10, -77.5, 1); // make shadow ride right on platform
				goto(-2, -77.5, 0);
				break;
			}
		}
	}
}
