SOLVE IT
토르의 망치, Mjöllnir 는 모든 힘을 잃었다…. 망치의 힘을 되찾기 위해 힘의 빛으로 안내해 줄 수 있겠는가?
주제: 조건문 (if…).
이 퍼즐은 과거 라그나로크 컨테스트에 제안되었던 시리즈중의 첫번째이다. 망치의 힘을 되찾게 되면, 다음 퍼즐로 건너가서 “토르 대 거인”에서 거인을 물리쳐라“. 더욱 어려울것이다.
가로 40, 세로 18의 맵에서 움직인다. 토르는 지도위 임의의 지점에서 시작할 것이고, 최대한 빨리 힘의 빛에 도착해야 한다.
각 턴에서, 어느 방향으로 이동할지 다음 경우중에서 결정해야 한다.
힘의 빛에 도달하면 당신이 승리한다.
<sxh perl>
select(STDOUT); $| = 1; # DO NOT REMOVE
chomp($tokens=<STDIN>);
($LX, $LY, $TX, $TY) = split(/ /,$tokens);
while (1) {
chomp($E = <STDIN>); # The level of Thor's remaining energy, representing the number of moves he can still make. # Write an action using print # To debug: print STDERR "Debug messages...\n";
print "SE\n"; # A single line providing the move to be made: N NE E SE S SW W or NW
}
</sxh>
<sxh perl>
select(STDOUT); $| = 1; # DO NOT REMOVE
chomp($tokens=<STDIN>);
($LX, $LY, $TX, $TY) = split(/ /,$tokens);
$x = $LX - $TX;
$y = $LY - $TY;
# game loop
while (1) {
chomp($E = <STDIN>); # The level of Thor's remaining energy, representing the number of moves he can still make. # Write an action using print # To debug: print STDERR "Debug messages...\n"; print STDERR "energy:",$E,"\n";
print STDERR "X:",$x,"\tY:",$y,"\n"; if ($x > 0) { if ($y > 0) { $d = "SE"; $x--; $y--; } elsif ($y < 0) { $d = "NE"; $x--; $y++; } else{ $d = "E"; $x--; } } elsif ($x < 0) { if ($y > 0) { $d = "SW"; $x++; $y--; } elsif ($y < 0) { $d = "NW"; $x++; $y++; } else{ $d = "W"; $x++; } } else{ if ($y > 0) { $d = "S"; $y--; } elsif ($y < 0) { $d = "N"; $y++; } } print $d,"\n"; # A single line providing the move to be made: N NE E SE S SW W or NW
}
</sxh>
<sxh perl>
select(STDOUT); $| = 1; # DO NOT REMOVE
chomp($tokens=<STDIN>);
($LX, $LY, $TX, $TY) = split(/ /,$tokens);
$x = $LX - $TX;
$y = $LY - $TY;
# game loop
while (1) {
chomp($E = <STDIN>); # The level of Thor's remaining energy, representing the number of moves he can still make. $d =""; if ($y > 0) {$d.="S";$y--} elsif ($y < 0) {$d.="N";$y++} if ($x > 0) {$d.="E";$x--} elsif ($x < 0) {$d.="W";$x++}; print $d,"\n"; # A single line providing the move to be made: N NE E SE S SW W or NW
}
</sxh>