Discussion:
Count Robots on Field, place in array
Jesse Bevil
2016-10-06 03:45:50 UTC
Permalink
So I'm looking to count the number of robots on the field. Not really sure
how I can accomplish that. I was thinking that if I make a multi-dimension
array and on each scanned robot save e.getName and e.getDistance and then
sort the array from lowest to highest distance, then select the target at
the top index of the array that I could improve survivability. I'm new to
RoboCode (about an hour ago), I am also new to Java (Fundamentals I class
in college, received an A, but doesn't really mean much without
experience).

So I suppose my problem is basically how to go about creating the array
that stores both the string and the integer short of creating two arrays.
I'm sure this idea is fairly basic and has likely already been done, but it
was my first thought when I considered avoiding shooting at the first thing
I saw (something could be closer).

Also while looking at the API I noticed that there was an option to
getClassName() which I suppose if I can use that within the scanner I could
get the specific class name for a robot, IE: if
e.GetClassName().Equals(Tracker) { handle tracker robot code goes here}. I
could handle specific sample robots. Though I don't think the goal would be
to beat the sample robots, more so the other robots other people code?

I would like to say that I have a clue where to start so that I could
provide some level of attempted code, but honestly I can't think of how to
approach the array situation, which is the basic question. I can write the
code to sort the information after I've got an idea of how to store it.

Thanks in advance for any assistance.
--
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 email to robocode+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Maciej Hrynczyszyn
2016-10-06 19:57:08 UTC
Permalink
Post by Jesse Bevil
So I'm looking to count the number of robots on the field. Not really sure
how I can accomplish that. I was thinking that if I make a multi-dimension
array and on each scanned robot save e.getName and e.getDistance and then
sort the array from lowest to highest distance, then select the target at
the top index of the array that I could improve survivability. I'm new to
RoboCode (about an hour ago), I am also new to Java (Fundamentals I class in
college, received an A, but doesn't really mean much without experience).
[...]
Hi Jesse,

I can't remember much of Robocode API but if you're only looking for
the closest robot, you don't have to keep them all (in an array or
other collection). You could just have two fields (String name; long
distance oslt) and on each ::onScannedRobot(...) you could check if
the distance to newly observed robot is smaller than smallest observed
so far. If it is, update name and distance values. Reset the values
between game ticks (turns, I guess). If you really want to look for a
min value in an array/collection, preferred idiom these days would be
to use Stream::min.

Best regards,
--
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 email to robocode+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Jesse Bevil
2016-10-07 17:25:06 UTC
Permalink
On contemplating the issue. I've decided to try and create an ArrayList of
the object type, and then in a seperate class, create the object Enemy
which will store each enemy on the play field. Moving forward with the
idea. Though I feel it will require a bit of tweaking to get it sorted,
assuming it even works.
Post by Jesse Bevil
So I'm looking to count the number of robots on the field. Not really sure
how I can accomplish that. I was thinking that if I make a multi-dimension
array and on each scanned robot save e.getName and e.getDistance and then
sort the array from lowest to highest distance, then select the target at
the top index of the array that I could improve survivability. I'm new to
RoboCode (about an hour ago), I am also new to Java (Fundamentals I class
in college, received an A, but doesn't really mean much without
experience).
So I suppose my problem is basically how to go about creating the array
that stores both the string and the integer short of creating two arrays.
I'm sure this idea is fairly basic and has likely already been done, but it
was my first thought when I considered avoiding shooting at the first thing
I saw (something could be closer).
Also while looking at the API I noticed that there was an option to
getClassName() which I suppose if I can use that within the scanner I could
get the specific class name for a robot, IE: if
e.GetClassName().Equals(Tracker) { handle tracker robot code goes here}. I
could handle specific sample robots. Though I don't think the goal would be
to beat the sample robots, more so the other robots other people code?
I would like to say that I have a clue where to start so that I could
provide some level of attempted code, but honestly I can't think of how to
approach the array situation, which is the basic question. I can write the
code to sort the information after I've got an idea of how to store it.
Thanks in advance for any assistance.
--
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 email to robocode+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
l***@gmail.com
2017-11-29 22:33:38 UTC
Permalink
Could you share this code?
Post by Jesse Bevil
On contemplating the issue. I've decided to try and create an ArrayList of
the object type, and then in a seperate class, create the object Enemy
which will store each enemy on the play field. Moving forward with the
idea. Though I feel it will require a bit of tweaking to get it sorted,
assuming it even works.
Post by Jesse Bevil
So I'm looking to count the number of robots on the field. Not really
sure how I can accomplish that. I was thinking that if I make a
multi-dimension array and on each scanned robot save e.getName and
e.getDistance and then sort the array from lowest to highest distance, then
select the target at the top index of the array that I could improve
survivability. I'm new to RoboCode (about an hour ago), I am also new to
Java (Fundamentals I class in college, received an A, but doesn't really
mean much without experience).
So I suppose my problem is basically how to go about creating the array
that stores both the string and the integer short of creating two arrays.
I'm sure this idea is fairly basic and has likely already been done, but it
was my first thought when I considered avoiding shooting at the first thing
I saw (something could be closer).
Also while looking at the API I noticed that there was an option to
getClassName() which I suppose if I can use that within the scanner I could
get the specific class name for a robot, IE: if
e.GetClassName().Equals(Tracker) { handle tracker robot code goes here}. I
could handle specific sample robots. Though I don't think the goal would be
to beat the sample robots, more so the other robots other people code?
I would like to say that I have a clue where to start so that I could
provide some level of attempted code, but honestly I can't think of how to
approach the array situation, which is the basic question. I can write the
code to sort the information after I've got an idea of how to store it.
Thanks in advance for any assistance.
--
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 email to robocode+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...