Watermelon/Code

From Robowiki
Jump to navigation Jump to search

Code on this page is freely available for whoever wants to use it. .

Debug Graphics

public void doPaint(Graphics2D g) {
	g.setStroke(new java.awt.BasicStroke(2f));
	if (bot.getOthers() == 1) {
		double radius, arcSegment, segmentHeading;
		double time = bot.getTime();
		for (Wave w : waves) {
			if (w.paint) {
				radius = (time - w.ctime) * w.velocity;
				arcSegment = w.extent / NUM_WAVEBUCKETS;
				for (int i = 0; i < NUM_WAVEBUCKETS; i++) {
					segmentHeading = w.heading + w.clockwise * (arcSegment * i - w.extent / 2);
					g.setColor(Color.getHSBColor( // this is Hue, Saturation, and Brightness
						0.058333f,
						1.0f,
						(float) (0.15 + 0.85 * waveBuckets[w.segment][i] / bucketMax[w.segment])
					));
					g.draw(new Line2D.Double(
						w.origin.x + (radius+2) * Math.sin(segmentHeading - arcSegment/2),
						w.origin.y + (radius+2) * Math.cos(segmentHeading - arcSegment/2),
						w.origin.x + (radius+2) * Math.sin(segmentHeading + arcSegment/2),
						w.origin.y + (radius+2) * Math.cos(segmentHeading + arcSegment/2)
					));
				}
			}
		}
	}
}

This function is called in the main robot's onPaint(Graphics2D).

Already defined:

  • bot - reference to this AdvancedRobot.
  • waves - collection of Waves with properties:
    • double extent - the size of an angle covering -1 to +1 on the wave in radians
    • boolean paint - I don't always paint all my waves
    • long ctime - tick when the wave was fired
    • double velocity - the bullet speed of this wave - how fast it's traveling
    • double heading - wave's heading
    • int clockwise - +1 for clockwise, -1 for counterclockwise (widdershins)
    • int segment - which segment applies to this wave
    • Point2D.Double origin - wave's origin
  • int NUM_WAVEBUCKETS - have a guess? :)
  • double[number of segments][NUM_WAVEBUCKETS] waveBuckets - array of segmentation data
  • bucketMax[number of segments] - maximum for each segment

Looks Like

Watermelon and GrubbmGrb duking it out.


Autoselected Segmentation

See Autoselected Segmentation.

for (int i = 0; i < segments.length; ++i) { // length already set to 2^num_of_axes
	LinkedList<Axis> segAx = new LinkedList<Axis>(); // so we can flexibly add axes
	for (int j = 0; j < axes.size(); ++j) { // counting up from 0 to num_of_axes-1
		if ((i & (1<<j)) > 0) // if the place value for that axis is 1
			segAx.add(axes.get(j)); // then add it
	}
	// add a new segment with the given axes, with rolling weight 10
	segments[i] = new Segmentation(NUM_WAVEBUCKETS, segAx.toArray(new Axis[0]), 10);
}