2121 * is created!
2222 */
2323public class RobotPlayer {
24- private record ImportantGameObservations (int numNearbyAllyRobots , int numNearbyEnemyRobots ) {}
25-
2624 /**
2725 * We will use this variable to count the number of turns this robot has been alive.
2826 * You can use static variables like this to save any information you want. Keep in mind that even though
@@ -61,7 +59,7 @@ private record ImportantGameObservations(int numNearbyAllyRobots, int numNearbyE
6159 public static void run (RobotController rc ) throws GameActionException {
6260 // Hello world! Standard output is very useful for debugging.
6361 // Everything you say here will be directly viewable in your terminal when you run a match!
64- // System.out.println("I'm alive");
62+ System .out .println ("I'm alive" );
6563
6664 // You can also use indicators to save debug notes in replays.
6765 rc .setIndicatorString ("Hello world!" );
@@ -79,43 +77,6 @@ public static void run(RobotController rc) throws GameActionException {
7977 // different types. Here, we separate the control depending on the UnitType, so we can
8078 // use different strategies on different robots. If you wish, you are free to rewrite
8179 // this into a different control structure!
82-
83- // Check that various Java features haven't broken
84- UnitType enumValue = UnitType .SOLDIER ;
85- boolean canAttack = enumValue .isTowerType ();
86- Map <UnitType , Integer > enumMap = new EnumMap <>(UnitType .class );
87- enumMap .put (UnitType .SOLDIER , 42 );
88- Map <Integer , Integer > hashMap = new HashMap <>();
89- hashMap .put (123 , 456 );
90- PriorityQueue <Integer > priorityQueue = new PriorityQueue <>();
91- priorityQueue .add (4 );
92- priorityQueue .add (7 );
93- priorityQueue .add (2 );
94- int [] intArr = new int []{3 , 3 , 5 , 8 , 5 , 3 , 4 , 6 , 8 , 5 , 7 , 4 , 3 , 7 , 6 , 4 , 3 };
95- Arrays .sort (intArr );
96- Integer [] objArr = new Integer []{3 , 3 , 5 , 8 , 5 , 3 , 4 , 6 , 8 , 5 , 7 , 4 , 3 , 7 , 6 , 4 , 3 };
97- Arrays .sort (objArr );
98- Integer [] data = new Integer []{1 , 2 , 3 , 4 , 5 };
99- List <Integer > dataList = Arrays .asList (data );
100- Stream <Integer > dataStream = dataList .stream ();
101- Stream <Integer > evenDataStream = dataStream .filter (x -> x % 2 == 0 );
102- //Object[] evenData = evenDataStream.toArray();
103- // This seems to fail, because jdk.internal.misc.SharedSecrets hardcodes class names as strings
104- // See https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/jdk/internal/access/SharedSecrets.java#L101
105- // TODO: these strings probably need to be sanitized on a case-by-case basis
106- List <Integer > listData = evenDataStream .toList ();
107- System .out .println ("DATA " + listData );
108- // Let's use some features from Java 9+
109- // var was introduced with Java 10, and record types with Java 16
110- var numNearbyAllies = rc .senseNearbyRobots (-1 , rc .getTeam ()).length ;
111- var numNearbyEnemies = rc .senseNearbyRobots (-1 , rc .getTeam ().opponent ()).length ;
112- var observations = new ImportantGameObservations (numNearbyAllies , numNearbyEnemies );
113- if (observations .numNearbyAllyRobots () > observations .numNearbyEnemyRobots ()) {
114- System .out .println ("I have a good feeling about this!" );
115- } else {
116- System .out .println ("I have a baaaaad feeling about this!" );
117- }
118-
11980 switch (rc .getType ()){
12081 case SOLDIER : runSoldier (rc ); break ;
12182 case MOPPER : runMopper (rc ); break ;
0 commit comments