codingame/FACILE/Le pouvoir de Thor/script.php
2015-03-02 19:42:39 +01:00

104 lines
2.1 KiB
PHP

<?php
/**
* Auto-generated code below aims at helping you parse
* the standard input according to the problem statement.
**/
fscanf(STDIN, "%d %d %d %d",
$LX, // the X position of the light of power
$LY, // the Y position of the light of power
$TX, // Thor's starting X position
$TY // Thor's starting Y position
);
// game loop
while (TRUE)
{
fscanf(STDIN, "%d",
$E // The level of Thor's remaining energy, representing the number of moves he can still make.
);
if ($TX === $LX) {
if ($TY >= $LT) {
echo "N\n";
$TY--;
} else {
$TY++;
echo "S\n";
}
}
if ($TY === $LY) {
if ($TX > $LX) {
echo "W\n";
$TX--;
} else {
echo "E\n";
$TX++;
}
}
if ($TX > $LX && $LY > $TY) {
if (($TX - $LX) > ($LY - $TY)) {
echo "W\n";
$TX--;
}
elseif (($TX - $LX) < ($LY - $TY)) {
echo "S\n";
$TY++;
}
else {
$TY++;
$TX--;
echo "SW\n";
}
}
if ($TX < $LX && $LY > $TY) {
if ($LX - $TX > $LY - $TY) {
echo "E\n";
$TX++;
}
elseif ($LX - $TX < $LY - $TY) {
echo "S\n";
$TY++;
}
else {
echo "SE\n";
$TY++;
$TX++;
}
}
if ($TX > $LX && $LY < $TY) {
if ($TX - $LX > $TY - $LY) {
echo "W\n";
$TX--;
}
elseif ($TX - $LX < $TY - $LY) {
echo "N\n";
$TY--;
}
else {
echo "NW\n";
$TX--;
$TY--;
}
}
if ($TX < $LX && $LY < $TY) {
if ($LX - $TX > $TY - $LY) {
echo "E\n";
$TX++;
}
elseif ($LX - $TX < $TY - $LY) {
echo "N\n";
$TY--;
}
else {
echo "NE\n";
$TX++;
$TY--;
}
}
}