Re: the purpose of calling scan() in onScannedRobot()

fnl <[email protected]> Sat, 2 Dec 2023 10:42:08 -0800 (PST)
Newsgroups gmane.comp.java.robocode
Message-ID <[email protected]>
------=_Part_68746_1203071089.1701542528670
Content-Type: multipart/alternative; 
	boundary="----=_Part_68747_1734487200.1701542528670"

------=_Part_68747_1734487200.1701542528670
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Hi Kent,

You are referring to the documentation for scan() here:
https://robocode.sourceforge.io/docs/robocode/robocode/Robot.html#scan--

A scan() contains an execute()=20
<https://robocode.sourceforge.io/docs/robocode/robocode/AdvancedRobot.html#=
execute-->=20
method implicitly, which means that it executes its turn *now* by sending=
=20
all its pending actions to the game, and "waiting" for the event handlers=
=20
to be called.
Hence, the current onScannedRobot() handler is "interrupted" now due to=20
scan() being called (executed), and the remaining code in the handler will=
=20
not be called, at least not in the current turn.
And called scan() in the handler prevents commands following scan() from=20
being called.

I see that the documentation is not very clear here, so I will need to=20
update it.

For info, calling a scan() inside an onScannedRobot() handler is treated as=
=20
a rescan. The code is here:

https://github.com/robo-code/robocode/blob/main/robocode.host/src/main/java=
/net/sf/robocode/host/proxies/BasicRobotProxy.java?plain=3D1#L321

public void rescan() {
    boolean reset =3D false;
    boolean origInterruptableValue =3D false;

    if (eventManager.getCurrentTopEventPriority() =3D=3D eventManager.getSc=
annedRobotEventPriority())=20
{
        reset =3D true;
        origInterruptableValue =3D eventManager.isInterruptible(eventManage=
r
.getScannedRobotEventPriority());
        eventManager.setInterruptible(eventManager.getScannedRobotEventPrio=
rity(),=20
true);
    }

    commands.setScan(true);
    executeImpl();

    if (reset) {
        eventManager.setInterruptible(eventManager.getScannedRobotEventPrio=
rity(),=20
origInterruptableValue);
    }
}


l=C3=B8rdag den 2. december 2023 kl. 16.42.06 UTC+1 skrev [email protected]=
om:

> Hi,
>
> I understand that calling scan() in onScannedRobot() will restart the=20
> event handler if a robot is indeed detected, but the event handler seems =
to=20
> be called in the next turn instead of immediately as stated by the api do=
c.
>
> This issue aside, my primary question is with the purpose of calling=20
> scan() in onScannedRobot(). Is it to prevent the movement in run()?=20
>
> Many thanks in advance
>

--=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/94c170cf-a67c-4ec3-a29a-3fbf178b8af8n%40googlegroups.com.

------=_Part_68747_1734487200.1701542528670
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Hi Kent,<div><br /></div><div>You are referring to the documentation for sc=
an() here:<br />https://robocode.sourceforge.io/docs/robocode/robocode/Robo=
t.html#scan--</div><div><br /></div><div>A scan() contains an <a href=3D"ht=
tps://robocode.sourceforge.io/docs/robocode/robocode/AdvancedRobot.html#exe=
cute--">execute()</a> method implicitly, which means that it executes its t=
urn <b>now</b> by sending all its pending actions to the game, and "waiting=
" for the event handlers to be called.</div><div>Hence, the current onScann=
edRobot() handler is "interrupted" now due to scan() being called (executed=
), and the remaining code in the handler will not be called, at least not i=
n the current turn.</div><div>And called scan() in the handler prevents com=
mands following scan() from being called.</div><div><br />I see that the do=
cumentation is not very clear here, so I will need to update it.<br /><br /=
>For info, calling a scan() inside an onScannedRobot() handler is treated a=
s a rescan. The code is here:<br /><br />https://github.com/robo-code/roboc=
ode/blob/main/robocode.host/src/main/java/net/sf/robocode/host/proxies/Basi=
cRobotProxy.java?plain=3D1#L321<br /><br /></div><div><div style=3D"backgro=
und-color: rgb(30, 31, 34); color: rgb(188, 190, 196);"><span style=3D"font=
-family: &quot;JetBrains Mono&quot;, monospace;"><span style=3D"color: rgb(=
207, 142, 109);">public void </span><span style=3D"color: rgb(86, 168, 245)=
;">rescan</span>() {<br />    <span style=3D"color: rgb(207, 142, 109);">=
=C2=A0 =C2=A0 boolean </span>reset =3D <span style=3D"color: rgb(207, 142, =
109);">false</span>;<br />    <span style=3D"color: rgb(207, 142, 109);">=
=C2=A0 =C2=A0 boolean </span>origInterruptableValue =3D <span style=3D"colo=
r: rgb(207, 142, 109);">false</span>;<br /><br />    <span style=3D"color: =
rgb(207, 142, 109);">=C2=A0 =C2=A0 if </span>(<span style=3D"color: rgb(199=
, 125, 187);">eventManager</span>.getCurrentTopEventPriority() =3D=3D <span=
 style=3D"color: rgb(199, 125, 187);">eventManager</span>.getScannedRobotEv=
entPriority()) {<br />=C2=A0 =C2=A0 =C2=A0 =C2=A0 reset =3D <span style=3D"=
color: rgb(207, 142, 109);">true</span>;<br />=C2=A0 =C2=A0 =C2=A0 =C2=A0 o=
rigInterruptableValue =3D <span style=3D"color: rgb(199, 125, 187);">eventM=
anager</span>.isInterruptible(<span style=3D"color: rgb(199, 125, 187);">ev=
entManager</span>.getScannedRobotEventPriority());<br />       <span style=
=3D"color: rgb(199, 125, 187);">=C2=A0 =C2=A0 =C2=A0 =C2=A0 eventManager</s=
pan>.setInterruptible(<span style=3D"color: rgb(199, 125, 187);">eventManag=
er</span>.getScannedRobotEventPriority(), <span style=3D"color: rgb(207, 14=
2, 109);">true</span>);<br />=C2=A0 =C2=A0 }<br /><br />    <span style=3D"=
color: rgb(199, 125, 187);">=C2=A0 =C2=A0 commands</span>.setScan(<span sty=
le=3D"color: rgb(207, 142, 109);">true</span>);<br />=C2=A0 =C2=A0 executeI=
mpl();<br /><br />    <span style=3D"color: rgb(207, 142, 109);">=C2=A0 =C2=
=A0 if </span>(reset) {<br />       <span style=3D"color: rgb(199, 125, 187=
);">=C2=A0 =C2=A0 =C2=A0 =C2=A0 eventManager</span>.setInterruptible(<span =
style=3D"color: rgb(199, 125, 187);">eventManager</span>.getScannedRobotEve=
ntPriority(), origInterruptableValue);<br />=C2=A0 =C2=A0 }<br />}<br /></s=
pan></div><br /><br /></div><div class=3D"gmail_quote"><div dir=3D"auto" cl=
ass=3D"gmail_attr">l=C3=B8rdag den 2. december 2023 kl. 16.42.06 UTC+1 skre=
v [email protected]:<br/></div><blockquote class=3D"gmail_quote" style=3D=
"margin: 0 0 0 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-le=
ft: 1ex;">Hi,<div><br></div><div>I understand that calling scan() in=C2=A0o=
nScannedRobot() will restart the event handler if a robot is indeed detecte=
d, but the event handler seems to be called in the next turn instead of imm=
ediately as stated by the api doc.</div><div><br></div><div>This issue asid=
e, my primary question is with the purpose of calling scan() in onScannedRo=
bot(). Is it to prevent the movement in run()?=C2=A0</div><div><br></div><d=
iv>Many thanks in advance</div></blockquote></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;Robocode&quot; 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/94c170cf-a67c-4ec3-a29a-3fbf178b8af8n%40googlegroups.co=
m?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.com/d/msgid=
/robocode/94c170cf-a67c-4ec3-a29a-3fbf178b8af8n%40googlegroups.com</a>.<br =
/>

------=_Part_68747_1734487200.1701542528670--

------=_Part_68746_1203071089.1701542528670--