Re: Not Painting When Firing
Davide Cappellini <[email protected]> Tue, 3 Aug 2021 06:25:30 -0700 (PDT)
| Newsgroups | gmane.comp.java.robocode |
|---|---|
| Message-ID | <[email protected]> |
------=_Part_3192_807154413.1627997130251
Content-Type: multipart/alternative;
boundary="----=_Part_3193_1913261853.1627997130251"
------=_Part_3193_1913261853.1627997130251
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
I've tested your code myself and your problem is related with the way you=
=20
move your radar and scan with it.
try to replace this code
*/*
*/ Robot main loopwhile(true) { // Replace the next 4 lines with any=20
behavior you would like if (!found) { turnGunRight(5); } else { =
=20
scan(); }}*
with this code:
*// Robot main loopwhile(true) { // Replace the next 4 lines with any=20
behaviour you would like =20
setTurnRadarRightRadians(Double.POSITIVE_INFINITY); scan();}*
this simple code will make your radar spin forever and and every time the=
=20
radar hits the target the paint (aka the latestScan variable) is updated.
This will make you see that the paint is not blocked by the firing but just=
=20
painting the same not up-to-date latestScan variable giving the impression=
=20
that the paint method hanged.
From the code itself I can see that you are at the beginning of this, don't=
=20
give up and you will find a beautiful journey in front of you.
Il giorno gioved=C3=AC 22 ottobre 2020 alle 20:58:32 UTC+2 [email protected]=
om ha=20
scritto:
> When I run this robot=20
> <http://www.mathcs.emory.edu/~lxiong/cs170/share/robocode/robots/sample/P=
aintingRobot.java>,=20
> it still doesn't work. It seems to not paint the turn it fires and then=
=20
> double paints the turn after.
>
> On Thursday, October 22, 2020 at 1:58:21 PM UTC-4 fnl wrote:
>
>> This is my design.
>> If every robot paint itself, it will be hard to see what is going on on=
=20
>> the battlefield. Hence, the developer needs to enable painting for the=
=20
>> individual robot in the robot console.
>>
>> This is described on this RoboWiki page:
>> https://robowiki.net/wiki/Robocode/Graphical_Debugging
>>
>> torsdag den 22. oktober 2020 kl. 19.55.55 UTC+2 skrev [email protected]=
:
>>
>>> For some reason, the turn my robot fires, it doesn't seem to paint. Any=
=20
>>> fixes for this? Code is below.
>>>
>>> import java.awt.BasicStroke;
>>> import java.awt.Color;
>>> import java.awt.Graphics2D;
>>>
>>> import robocode.AdvancedRobot;
>>> import robocode.Bullet;
>>> import robocode.HitByBulletEvent;
>>> import robocode.HitWallEvent;
>>> import robocode.ScannedRobotEvent;
>>>
>>> public class BasicRobot extends AdvancedRobot {
>>> //Attributes
>>> private int scanX, scanY;
>>> private boolean found =3D false;
>>> private ScannedRobotEvent latestScan =3D null;
>>> /**
>>> * run: BasicRobot's default behavior
>>> */
>>> public void run() {
>>> // Initialization of the robot should be put here
>>>
>>> // After trying out your robot, try uncommenting the import at the top,
>>> // and the next line:
>>>
>>> setColors(Color.BLACK, Color.GRAY, Color.RED); // body,gun,radar
>>> setScanColor(Color.WHITE);
>>>
>>> // Robot main loop
>>> while(true) {
>>> // Replace the next 4 lines with any behavior you would like
>>> if (!found) {
>>> turnGunRight(5);
>>> } else {
>>> scan();
>>> }
>>> }
>>> }
>>> /**
>>> * onScannedRobot: What to do when you see another robot
>>> */
>>> public void onScannedRobot(ScannedRobotEvent e) {
>>> found =3D true;
>>> latestScan =3D e;
>>> // Replace the next line with any behavior you would like
>>> if (getGunHeat() =3D=3D 0)=20
>>> fireBullet(3);
>>> }
>>> private void drawScannedRobot(ScannedRobotEvent e) {
>>> double angle =3D Math.toRadians((getHeading() + e.getBearing()) % 360);
>>> scanX =3D (int) (getX() + Math.sin(angle) * e.getDistance());
>>> scanY =3D (int) (getY() + Math.cos(angle) * e.getDistance());
>>> Graphics2D g =3D this.getGraphics();
>>> g.setColor(new Color(0xff, 0x00, 0x00, 0x80));
>>> g.drawLine((int) getX(), (int) getY(), scanX, scanY);
>>> int w =3D (int) getWidth();
>>> g.fillRect(scanX - w/2, scanY - w/2, 40, 40);
>>> }
>>> public void onPaint(Graphics2D g) {
>>> g.setStroke(new BasicStroke(2));
>>> g.setColor(Color.GRAY);
>>> int r =3D (int) (getWidth() * 1.5);
>>> if (latestScan !=3D null)
>>> drawScannedRobot(latestScan);
>>> }
>>> private void draw(Graphics2D g) {
>>> g.setStroke(new BasicStroke(2));
>>> g.setColor(Color.GRAY);
>>> int r =3D (int) (getWidth() * 1.5);
>>> if (latestScan !=3D null)
>>> drawScannedRobot(latestScan);
>>> }
>>> }
>>>
>>
--=20
You received this message because you are subscribed to the Google Groups "=
Robocode" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/=
robocode/bc1f9572-66c2-4935-86dc-ea8864b563dan%40googlegroups.com.
------=_Part_3193_1913261853.1627997130251
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<br>I've tested your code myself and your problem is related with the way y=
ou move your radar and scan with it.<div>try to replace this code</div><div=
><br></div><div><i>/</i><b>/ Robot main loop<br>while(true) {<br> =
// Replace the next 4 lines with any behavior you would like<br> =
if (!found) {<br> turnGunRight(5);<br> =
} else {<br> scan();<br> }<=
br>}</b><br></div><div><br></div><div>with this code:</div><div><br></div><=
div><b>// Robot main loop<br>while(true) {<br> // Replace t=
he next 4 lines with any behaviour you would like<br> setTu=
rnRadarRightRadians(Double.<span style=3D"font-style: italic;">POSITIVE_INF=
INITY</span>);<br> scan();<br>}</b><br></div><div><br></div=
><div>this simple code will make your radar spin forever and and every time=
the radar hits the target the paint (aka the latestScan variable) is updat=
ed.</div><div><br></div><div>This will make you see that the paint is not b=
locked by the firing but just painting the same not up-to-date latestScan v=
ariable giving the impression that the paint method hanged.</div><div><br><=
/div><div>From the code itself I can see that you are at the beginning of t=
his, don't give up and you will find a beautiful journey in front of you.</=
div><div><br></div><div class=3D"gmail_quote"><div dir=3D"auto" class=3D"gm=
ail_attr">Il giorno gioved=C3=AC 22 ottobre 2020 alle 20:58:32 UTC+2 veget.=
[email protected] ha scritto:<br></div><blockquote class=3D"gmail_quote" style=
=3D"margin: 0 0 0 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding=
-left: 1ex;">When I run <a href=3D"http://www.mathcs.emory.edu/~lxiong/cs17=
0/share/robocode/robots/sample/PaintingRobot.java" target=3D"_blank" rel=3D=
"nofollow" data-saferedirecturl=3D"https://www.google.com/url?hl=3Dit&q=
=3Dhttp://www.mathcs.emory.edu/~lxiong/cs170/share/robocode/robots/sample/P=
aintingRobot.java&source=3Dgmail&ust=3D1628081929073000&usg=3DA=
FQjCNFFouhvqVMRdLo_h-gE7eh5XMmgYQ">this robot</a>, it still doesn't work. I=
t seems to not paint the turn it fires and then double paints the turn afte=
r.<br><br><div class=3D"gmail_quote"><div dir=3D"auto" class=3D"gmail_attr"=
>On Thursday, October 22, 2020 at 1:58:21 PM UTC-4 fnl wrote:<br></div><blo=
ckquote class=3D"gmail_quote" style=3D"margin:0 0 0 0.8ex;border-left:1px s=
olid rgb(204,204,204);padding-left:1ex">This is my design.<div>If every rob=
ot paint itself, it will be hard to see what is going on on the battlefield=
. Hence, the developer needs to enable painting for the individual robot in=
the robot console.<br><br>This is described on this RoboWiki page:<br><a h=
ref=3D"https://robowiki.net/wiki/Robocode/Graphical_Debugging" rel=3D"nofol=
low" target=3D"_blank" data-saferedirecturl=3D"https://www.google.com/url?h=
l=3Dit&q=3Dhttps://robowiki.net/wiki/Robocode/Graphical_Debugging&s=
ource=3Dgmail&ust=3D1628081929073000&usg=3DAFQjCNFnko6LaZT8mn73kKyr=
WgBgTFTXTA">https://robowiki.net/wiki/Robocode/Graphical_Debugging</a><br><=
br></div><div class=3D"gmail_quote"><div dir=3D"auto" class=3D"gmail_attr">=
torsdag den 22. oktober 2020 kl. 19.55.55 UTC+2 skrev <a rel=3D"nofollow">v=
[email protected]</a>:<br></div><blockquote class=3D"gmail_quote" style=3D"=
margin:0 0 0 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"=
>For some reason, the turn my robot fires, it doesn't seem to paint. Any fi=
xes for this? Code is below.<div><br></div><div><div><font face=3D"Courier =
New">import java.awt.BasicStroke;</font></div><div><font face=3D"Courier Ne=
w">import java.awt.Color;</font></div><div><font face=3D"Courier New">impor=
t java.awt.Graphics2D;</font></div><div><font face=3D"Courier New"><br></fo=
nt></div><div><font face=3D"Courier New">import robocode.AdvancedRobot;</fo=
nt></div><div><font face=3D"Courier New">import robocode.Bullet;</font></di=
v><div><font face=3D"Courier New">import robocode.HitByBulletEvent;</font><=
/div><div><font face=3D"Courier New">import robocode.HitWallEvent;</font></=
div><div><font face=3D"Courier New">import robocode.ScannedRobotEvent;</fon=
t></div><div><font face=3D"Courier New"><br></font></div><div><font face=3D=
"Courier New">public class BasicRobot extends AdvancedRobot {</font></div><=
div><font face=3D"Courier New"><span style=3D"white-space:pre"> </span>//At=
tributes</font></div><div><font face=3D"Courier New"><span style=3D"white-s=
pace:pre"> </span>private int scanX, scanY;</font></div><div><font face=3D"=
Courier New"><span style=3D"white-space:pre"> </span>private boolean found =
=3D false;</font></div><div><font face=3D"Courier New"><span style=3D"white=
-space:pre"> </span>private ScannedRobotEvent latestScan =3D null;</font></=
div><div><span style=3D"white-space:pre"><font face=3D"Courier New"> </font=
></span></div><div><font face=3D"Courier New"><span style=3D"white-space:pr=
e"> </span>/**</font></div><div><font face=3D"Courier New"><span style=3D"w=
hite-space:pre"> </span> * run: BasicRobot's default behavior</font></div><=
div><font face=3D"Courier New"><span style=3D"white-space:pre"> </span> */<=
/font></div><div><font face=3D"Courier New"><span style=3D"white-space:pre"=
> </span>public void run() {</font></div><div><font face=3D"Courier New"><s=
pan style=3D"white-space:pre"> </span>// Initialization of the robot shoul=
d be put here</font></div><div><font face=3D"Courier New"><br></font></div>=
<div><font face=3D"Courier New"><span style=3D"white-space:pre"> </span>//=
After trying out your robot, try uncommenting the import at the top,</font=
></div><div><font face=3D"Courier New"><span style=3D"white-space:pre"> </=
span>// and the next line:</font></div><div><font face=3D"Courier New"><br>=
</font></div><div><font face=3D"Courier New"><span style=3D"white-space:pre=
"> </span> setColors(Color.BLACK, Color.GRAY, Color.RED); // body,gun,rada=
r</font></div><div><font face=3D"Courier New"><span style=3D"white-space:pr=
e"> </span> setScanColor(Color.WHITE);</font></div><div><font face=3D"Cour=
ier New"><br></font></div><div><font face=3D"Courier New"><span style=3D"wh=
ite-space:pre"> </span>// Robot main loop</font></div><div><font face=3D"C=
ourier New"><span style=3D"white-space:pre"> </span>while(true) {</font></=
div><div><font face=3D"Courier New"><span style=3D"white-space:pre"> </sp=
an>// Replace the next 4 lines with any behavior you would like</font></div=
><div><font face=3D"Courier New"><span style=3D"white-space:pre"> </span>=
if (!found) {</font></div><div><font face=3D"Courier New"><span style=3D"wh=
ite-space:pre"> </span>turnGunRight(5);</font></div><div><font face=3D"C=
ourier New"><span style=3D"white-space:pre"> </span>} else {</font></div>=
<div><font face=3D"Courier New"><span style=3D"white-space:pre"> </span>=
scan();</font></div><div><font face=3D"Courier New"><span style=3D"white-sp=
ace:pre"> </span>}</font></div><div><font face=3D"Courier New"><span styl=
e=3D"white-space:pre"> </span>}</font></div><div><font face=3D"Courier New=
"><span style=3D"white-space:pre"> </span>}</font></div><div><span style=3D=
"white-space:pre"><font face=3D"Courier New"> </font></span></div><div><fon=
t face=3D"Courier New"><span style=3D"white-space:pre"> </span>/**</font></=
div><div><font face=3D"Courier New"><span style=3D"white-space:pre"> </span=
> * onScannedRobot: What to do when you see another robot</font></div><div>=
<font face=3D"Courier New"><span style=3D"white-space:pre"> </span> */</fon=
t></div><div><font face=3D"Courier New"><span style=3D"white-space:pre"> </=
span>public void onScannedRobot(ScannedRobotEvent e) {</font></div><div><fo=
nt face=3D"Courier New"><span style=3D"white-space:pre"> </span>found =3D =
true;</font></div><div><font face=3D"Courier New"><span style=3D"white-spac=
e:pre"> </span>latestScan =3D e;</font></div><div><font face=3D"Courier Ne=
w"><span style=3D"white-space:pre"> </span>// Replace the next line with a=
ny behavior you would like</font></div><div><font face=3D"Courier New"><spa=
n style=3D"white-space:pre"> </span>if (getGunHeat() =3D=3D 0) </font=
></div><div><font face=3D"Courier New"><span style=3D"white-space:pre"> <=
/span>fireBullet(3);</font></div><div><font face=3D"Courier New"><span styl=
e=3D"white-space:pre"> </span>}</font></div><div><span style=3D"white-space=
:pre"><font face=3D"Courier New"> </font></span></div><div><span style=3D"w=
hite-space:pre"><font face=3D"Courier New"> </font></span></div><div><font =
face=3D"Courier New"><span style=3D"white-space:pre"> </span>private void d=
rawScannedRobot(ScannedRobotEvent e) {</font></div><div><font face=3D"Couri=
er New"><span style=3D"white-space:pre"> </span>double angle =3D Math.toRa=
dians((getHeading() + e.getBearing()) % 360);</font></div><div><font face=
=3D"Courier New"><span style=3D"white-space:pre"> </span>scanX =3D (int) (=
getX() + Math.sin(angle) * e.getDistance());</font></div><div><font face=3D=
"Courier New"><span style=3D"white-space:pre"> </span>scanY =3D (int) (get=
Y() + Math.cos(angle) * e.getDistance());</font></div><div><span style=3D"w=
hite-space:pre"><font face=3D"Courier New"> </font></span></div><div><font=
face=3D"Courier New"><span style=3D"white-space:pre"> </span>Graphics2D g=
=3D this.getGraphics();</font></div><div><font face=3D"Courier New"><span =
style=3D"white-space:pre"> </span>g.setColor(new Color(0xff, 0x00, 0x00, 0=
x80));</font></div><div><span style=3D"white-space:pre"><font face=3D"Couri=
er New"> </font></span></div><div><font face=3D"Courier New"><span style=
=3D"white-space:pre"> </span>g.drawLine((int) getX(), (int) getY(), scanX,=
scanY);</font></div><div><font face=3D"Courier New"><span style=3D"white-s=
pace:pre"> </span>int w =3D (int) getWidth();</font></div><div><font face=
=3D"Courier New"><span style=3D"white-space:pre"> </span>g.fillRect(scanX =
- w/2, scanY - w/2, 40, 40);</font></div><div><font face=3D"Courier New"><s=
pan style=3D"white-space:pre"> </span>}</font></div><div><span style=3D"whi=
te-space:pre"><font face=3D"Courier New"> </font></span></div><div><font fa=
ce=3D"Courier New"><span style=3D"white-space:pre"> </span>public void onPa=
int(Graphics2D g) {</font></div><div><font face=3D"Courier New"><span style=
=3D"white-space:pre"> </span>g.setStroke(new BasicStroke(2));</font></div>=
<div><font face=3D"Courier New"><span style=3D"white-space:pre"> </span>g.=
setColor(Color.GRAY);</font></div><div><font face=3D"Courier New"><span sty=
le=3D"white-space:pre"> </span>int r =3D (int) (getWidth() * 1.5);</font><=
/div><div><span style=3D"white-space:pre"><font face=3D"Courier New"> </fo=
nt></span></div><div><font face=3D"Courier New"><span style=3D"white-space:=
pre"> </span>if (latestScan !=3D null)</font></div><div><font face=3D"Cour=
ier New"><span style=3D"white-space:pre"> </span>drawScannedRobot(latestS=
can);</font></div><div><font face=3D"Courier New"><span style=3D"white-spac=
e:pre"> </span>}</font></div><div><span style=3D"white-space:pre"><font fac=
e=3D"Courier New"> </font></span></div><div><font face=3D"Courier New"><spa=
n style=3D"white-space:pre"> </span>private void draw(Graphics2D g) {</font=
></div><div><font face=3D"Courier New"><span style=3D"white-space:pre"> </=
span>g.setStroke(new BasicStroke(2));</font></div><div><font face=3D"Courie=
r New"><span style=3D"white-space:pre"> </span>g.setColor(Color.GRAY);</fo=
nt></div><div><font face=3D"Courier New"><span style=3D"white-space:pre"> =
</span>int r =3D (int) (getWidth() * 1.5);</font></div><div><span style=3D"=
white-space:pre"><font face=3D"Courier New"> </font></span></div><div><fon=
t face=3D"Courier New"><span style=3D"white-space:pre"> </span>if (latestS=
can !=3D null)</font></div><div><font face=3D"Courier New"><span style=3D"w=
hite-space:pre"> </span>drawScannedRobot(latestScan);</font></div><div><f=
ont face=3D"Courier New"><span style=3D"white-space:pre"> </span>}</font></=
div><div><font face=3D"Courier New">}</font></div></div></blockquote></div>=
</blockquote></div></blockquote></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;Robocode" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:[email protected]">robocode+u=
[email protected]</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/d/msgid/robocode/bc1f9572-66c2-4935-86dc-ea8864b563dan%40googlegroups.co=
m?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.com/d/msgid=
/robocode/bc1f9572-66c2-4935-86dc-ea8864b563dan%40googlegroups.com</a>.<br =
/>
------=_Part_3193_1913261853.1627997130251--
------=_Part_3192_807154413.1627997130251--