open:codingame-onboarding

OnBoarding

접속주소

게임방법

다가오는 적기들을 물리쳐야 합니다.

적기들의 이름과 거리를 알려줍니다.

STDOUT 으로 이름을 출력하면, 해당 적기를 향해 미사일을 발사합니다.

모든 적기가 다가오기전에 모두 물리쳐야 합니다.

5 threats approaching fast !
Threats within range:
HotDroid 60m
HotDroid 60m
HotDroid 60m
HotDroid 60m
Standard Output Stream:
HotDroid

$enemy 에는 적기의 이름이, $dist에는 적기와의 거리가 입력됩니다.

snippet.perl
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($count = <STDIN>); # The number of current enemy ships within range
    print STDERR "COUNT:".$count ."\n";
    @enemies = ();
 
    for(my $i=0; $i<$count; $i++) {
        # enemy: The name of this enemy
        # dist: The distance to your cannon of this enemy
        chomp($tokens=<STDIN>);
        ($enemy, $dist) = split(/ /,$tokens);
 
        print STDERR "name:".$enemy."\tdist:".$dist ."\n";
 
        my $e->{name}=$enemy;
        $e->{dist}=$dist;
        push @enemies,$e;
 
    }
 
    $min_e = $enemy;
    $min_d = $dist;
    print STDERR "enemies:".$#enemies . "\n";
 
    for my $href (@enemies) {
         print STDERR "x:". $href->{name} . "\n";
 
         $name = $href->{name};
         $dist = $href->{dist};
         if($min_d > $dist){
                $min_d = $dist;
                $min_e = $name;
            }
    }
 
    print $min_e."\n";
 
 # Write an action using print
    # To debug: print STDERR "Debug messages...\n";
 
    #print "HotDroid\n"; # The name of the most threatening enemy (HotDroid is just one example)
}

  • open/codingame-onboarding.txt
  • 마지막으로 수정됨: 2020/06/02 09:25
  • 저자 127.0.0.1