Questions

Jump to navigation Jump to search
Revision as of 21 April 2012 at 10:06.
This is the thread's initial revision.

Hi. Has somebody an idear how to make this smaller. I need the max bearing difference between all enemys. My gut feeling says it should be easier, but i can't see it.

	private void calcBearingDiff()
	{
		if (myScans.isEmpty()) return;
		
		Comparator<ATarget> compi = new Comparator<ATarget>() 
		{
			@Override
			public int compare(ATarget a, ATarget b) 
			{
				double eAbsBearA = a.getBearing() + myRobot.getHeadingRadians();
				double eAbsBearB = b.getBearing() + myRobot.getHeadingRadians();
				return Double.compare(eAbsBearA, eAbsBearB);
			}
		};
		ArrayList<ATarget> enemys = new ArrayList<ATarget>(myScans.values());
		Collections.sort(enemys, compi);
		
		enemys.add(enemys.get(0));
		
		ATarget last = null;
		for (ATarget target : enemys) 
		{
			if (last != null) 
			{
				double eAbsBearingA = last.getBearing() + myRobot.getHeadingRadians();
				double eAbsBearingB = target.getBearing() + myRobot.getHeadingRadians();
				double diff = Utils.normalRelativeAngle(eAbsBearingA - eAbsBearingB);	

	                        // .... sort out the max
			}
			last = target;
		}
	}
    Wompi12:06, 21 April 2012