move($X, $Y); echo $ret . "\n"; class Robot { /** @var array 現在いる座標*/ private $position; /** @var string 現在向いている方向*/ private $orientation; /** @var integer 一回の前進で移動できる最大値 */ private $maxMigrationLength; /** @var RegisterExecHistoryCommand */ private $RegisterExecHistoryCommand; public function __construct(int $maxMigrationLength) { $this->position = [0, 0]; $this->orientation = Direction::NORTH; $this->maxMigrationLength = $maxMigrationLength; } /** * 指定された座標に移動する * * @param integer $x * @param integer $y * @return void */ public function move(int $x, int $y): int { $positionType = $this->getPositionType($x, $y); switch ($positionType) { case PositonType::ZERO: return 0; case PositonType::ON_X: return $this->calcCntExceed($x) + 1; case PositonType::ON_Y: return $this->calcCntExceed($y) + (($y > 0) ? 0 : 1); case PositonType::FIRST_QUADRANT: case PositonType::SECOND_QUADRANT: return $this->calcCntExceed($x) + $this->calcCntExceed($y) + 1; case PositonType::THIRD_QUADRANT: case PositonType::FOURTH_QUADRANT: return $this->calcCntExceed($x) + $this->calcCntExceed($y) + 2; } } private function calcCntExceed($num) { return ceil(abs($num) / $this->maxMigrationLength); } private function getPositionType(int $x, int $y): int { if ($x == 0 && $y == 0) { return PositonType::ZERO; } elseif ($x != 0 && $y == 0) { return PositonType::ON_X; } elseif ($x == 0 && $y != 0) { return PositonType::ON_Y; } elseif ($x > 0 && $y > 0) { return PositonType::FIRST_QUADRANT; } elseif ($x < 0 && $y > 0) { return PositonType::SECOND_QUADRANT; } elseif ($x < 0 && $y < 0) { return PositonType::THIRD_QUADRANT; } elseif ($x > 0 && $y < 0) { return PositonType::FOURTH_QUADRANT; } } } class PositonType { public const FIRST_QUADRANT = 1; public const SECOND_QUADRANT = 2; public const THIRD_QUADRANT = 3; public const FOURTH_QUADRANT = 4; public const ON_X = 5; public const ON_Y = 6; public const ZERO = 7; } class Direction { public const NORTH = 0; public const SOUTH = 1; public const EAST = 2; public const WEST = 3; }