Difference between revisions of "Talk:Watermelon/Code"

From Robowiki
Jump to navigation Jump to search
(painting costs cpu)
(not anymore)
Line 39: Line 39:
  
 
: Nope -- I noticed in one of the changelogs that painting is now done by the robot's thread and counts against your cpu time.  Makes sense, since you can really put any code (movement, targeting, etc.) inside of onPaint().  Nice waves, by the way!  --[[User:Darkcanuck|Darkcanuck]] 14:54, 10 June 2009 (UTC)
 
: Nope -- I noticed in one of the changelogs that painting is now done by the robot's thread and counts against your cpu time.  Makes sense, since you can really put any code (movement, targeting, etc.) inside of onPaint().  Nice waves, by the way!  --[[User:Darkcanuck|Darkcanuck]] 14:54, 10 June 2009 (UTC)
 +
 +
:: Yeah, v1.6.1 does. But later changelogs (1.6.2beta) state that "Bug <nowiki>[</nowiki>[https://sourceforge.net/tracker/index.php?func=detail&aid=2214620&group_id=37202&atid=419489 2214620]<nowiki>]</nowiki>: Robots were paying CPU time for painting. Now Robocode gives a robot unlimited time when painting is enabled on UI (in the robot dialog) for that robot.". =) &raquo; <span style="font-size:0.9em;color:darkgreen;">[[User:Nat|Nat]] | [[User_talk:Nat|Talk]]</span> &raquo; 15:11, 10 June 2009 (UTC)

Revision as of 17:11, 10 June 2009

It will be more fun if you do this instead:

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 Arc2D.Double(
						w.origin.x - radius,
						w.origin.y - radius,
						radius * 2,
						radius * 2,
						segmentHeading,
						arcSegment,
						Arc2D.OPEN
					));
				}
			}
		}
	}
}

=) » Nat | Talk » 13:43, 10 June 2009 (UTC)

Originally, that's what I did, but with more waves on the screen I was skipping turns. -- Synapse 14:37, 10 June 2009 (UTC)

Really? I think robocode allow unlimited time when you are drawing. » Nat | Talk » 14:43, 10 June 2009 (UTC)

Nope -- I noticed in one of the changelogs that painting is now done by the robot's thread and counts against your cpu time. Makes sense, since you can really put any code (movement, targeting, etc.) inside of onPaint(). Nice waves, by the way! --Darkcanuck 14:54, 10 June 2009 (UTC)
Yeah, v1.6.1 does. But later changelogs (1.6.2beta) state that "Bug [2214620]: Robots were paying CPU time for painting. Now Robocode gives a robot unlimited time when painting is enabled on UI (in the robot dialog) for that robot.". =) » Nat | Talk » 15:11, 10 June 2009 (UTC)