Robot (Robot v0.1.0) View Source

Given a robot which can only move in four directions, UP(U), DOWN(D), LEFT(L), RIGHT(R).

Given a string consisting of instructions to move. Output the coordinates of a robot after executing the instructions. Initial position of robot is at origin(0, 0).

If the robot exceeds the established limits it will travel to the negative limit of the maximum position.

The maximum position by default is set to 5, but it can be changed. For more details, see Robot.setBounds/2.

Link to this section Summary

Functions

Get the current position of the Robot.

Move the Robot to the desired location according to the given commands.

Change the Robot bounds by a given tuple {x, y}.

Initialize a Robot process.

Stop a Robot process.

Link to this section Functions

Specs

get(pid()) :: %Robot.Models.Point{bounds: term(), x: term(), y: term()}

Get the current position of the Robot.

Returns %Robot.Models.Point{}.

Examples

iex> {:ok, pid} = Robot.start()
iex> Robot.get(pid)
%Robot.Models.Point{x: 0, y: 0}

Specs

move(pid(), String.t()) :: :ok

Move the Robot to the desired location according to the given commands.

Returns :ok.

Examples

iex> {:ok, pid} = Robot.start()
iex> Robot.move(pid, "UUUDR")
:ok

Specs

setBounds(pid(), tuple()) :: :ok

Change the Robot bounds by a given tuple {x, y}.

Returns :ok.

Examples

iex> {:ok, pid} = Robot.start()
iex> :ok = Robot.setBounds(pid, {10, 10})
:ok

Specs

start() :: {:ok, pid()}

Initialize a Robot process.

Returns {:ok, #PID<0.162.0>}.

Examples

iex> {:ok, _pid} = Robot.start()

Specs

stop(pid()) :: :ok

Stop a Robot process.

Returns :ok.

Examples

iex> {:ok, pid} = Robot.start()
iex> :ok = Robot.stop(pid)
:ok