Advertisement
Guest User

Untitled

a guest
Jan 30th, 2015
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 1.44 KB | None | 0 0
  1. import 'dart:io';
  2. import 'dart:math';
  3.  
  4. /**
  5.  * The code below will read all the game information for you.
  6.  * On each game turn, information will be available on the standard input, you will be sent:
  7.  * -> the total number of visible enemies
  8.  * -> for each enemy, its name and distance from you
  9.  * The system will wait for you to write an enemy name on the standard output.
  10.  * Once you have designated a target:
  11.  * -> the cannon will shoot
  12.  * -> the enemies will move
  13.  * -> new info will be available for you to read on the standard input.
  14.  **/
  15. void main() {
  16.     List inputs;
  17.    
  18.     String closestEnemy = "";
  19.     int minDist = 100000;
  20.    
  21.     // game loop
  22.     while (true) {
  23.         stderr.writeln('Debug messages...');
  24.         int count = int.parse(stdin.readLineSync()); // The number of current enemy ships within range
  25.  
  26.         for (int i = 0; i < count; i++) {
  27.             inputs = stdin.readLineSync().split(' ');
  28.             String enemy = inputs[0]; // The name of this enemy
  29.             int dist = int.parse(inputs[1]); // The distance to your cannon of this enemy
  30.            
  31.             if (dist < minDist) {
  32.                 closestEnemy = enemy;
  33.                 minDist = dist;
  34.             }
  35.         }
  36.        
  37.         print(closestEnemy); // The name of the most threatening enemy (HotDroid is just one example)
  38.  
  39.         // Write an action using print()
  40.         // To debug: stderr.writeln('Debug messages...');
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement