Created
September 3, 2014 13:50
-
-
Save dolmen/f7501d899744cd64f1e6 to your computer and use it in GitHub Desktop.
Basic code for the Codingame tuto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; use warnings; use 5.014; | |
select(STDOUT); $| = 1; # DO NOT REMOVE | |
# 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. | |
# game loop | |
while (1) { | |
chomp(my $count = <>); # The number of current enemy ships within range | |
my @e; | |
while ($count--) { | |
chomp(my $tokens = <>); | |
# dist: The distance to your cannon of this enemy | |
my ($enemy, $dist) = split / /, $tokens; | |
push @e, [ $enemy, $dist ]; | |
} | |
# Write an action using print | |
# To debug: print STDERR "Debug messages...\n"; | |
print "$e[0][0]\n" # Just kill the first enemy | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment