Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'dart:io';
- import 'dart:math';
- /**
- * The code below will read all the game information for you.
- * On each game turn, information will be available on the standard input, you will be sent:
- * -> the total number of visible enemies
- * -> for each enemy, its name and distance from you
- * The system will wait for you to write an enemy name on the standard output.
- * Once you have designated a target:
- * -> the cannon will shoot
- * -> the enemies will move
- * -> new info will be available for you to read on the standard input.
- **/
- void main() {
- List inputs;
- String closestEnemy = "";
- int minDist = 100000;
- // game loop
- while (true) {
- stderr.writeln('Debug messages...');
- int count = int.parse(stdin.readLineSync()); // The number of current enemy ships within range
- for (int i = 0; i < count; i++) {
- inputs = stdin.readLineSync().split(' ');
- String enemy = inputs[0]; // The name of this enemy
- int dist = int.parse(inputs[1]); // The distance to your cannon of this enemy
- if (dist < minDist) {
- closestEnemy = enemy;
- minDist = dist;
- }
- }
- print(closestEnemy); // The name of the most threatening enemy (HotDroid is just one example)
- // Write an action using print()
- // To debug: stderr.writeln('Debug messages...');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement