Skip to content

NatanaelBorges/ToyRobotSimulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🤖 Toy Robot Simulator

.NET DockerCoverage Commits License

The application is a simulation of a toy robot moving a robot on a grid, There are no other obstructions on the table surface. The robot is free to roam around the surface, but must be prevented from falling to destruction. Any movement that would result in the robot falling from the table must be prevented. Utilizing architectural principles such as the Command Pattern, Inversion of Control (IoC), and Test-Driven Development (TDD) to ensure robustness and extensibility.

🛠️ Technologies and Architecture

  • Language: C# 14
  • Framework .NET 9
  • Architecture Command Pattern
  • Testing xUnit and FluentAssertions
  • Container Docker

📦 Installation and Execution

There are two main ways to run the application: locally (via SDK) or using containers (via Docker).

Option 1: Execution via .NET SDK (Local)

Prerequisites

  • .NET 9 SDK or higher.

Instructions

1. Clone the Repository:

git clone git@github.com:NatanaelBorges/ToyRobotSimulator.git
cd ToyRobotSimulator  

2. Restore Dependencies:

dotnet restore  

3. Run the Application: The dotnet run command starts the executable project (ToyRobot.App).

dotnet run --project src/ToyRobot.App  

4. Command Interface: The application will start, and you can enter commands interactively:

🤖 Advanced Toy Robot Simulator (6x6). Type commands or 'EXIT'.

PLACE 1,2,NORTH
MOVE
REPORT
Output: 1,3,NORTH
EXIT

Option 2: Execution via Docker (Recommended)

Prerequisites

  • Docker Desktop installed and running.

Instructions

1. Build the Image: Execute the build command from the solution root, using the Dockerfile located in ToyRobot.App/.

docker build -t toyrobot-simulator:v1.0 -f src/ToyRobot.App/Dockerfile .  

2. Run in Interactive Mode: Since the simulator is a console application requiring input (STDIN), it must be run with the -it flag.

docker run -it --rm toyrobot-simulator:v1.0  

3. Use the Application: The container console will be open to receive commands.

🕹️ Robot Commands

The simulator accepts commands in uppercase or lowercase. The first valid command must always be PLACE X,Y,DIRECTION.

Command Format Description Error Handling
PLACE PLACE X,Y,DIR Positions the robot at coordinate (X, Y) and facing direction DIR (NORTH, SOUTH, EAST, WEST). Must be the first command. If outside bounds (configured in appsettings.json), the command is ignored and an error is returned.
MOVE MOVE Moves the robot one unit forward in the current direction. If the movement would result in the robot falling (leaving the bounds), the robot remains in its current position and returns an informative error.
LEFT LEFT Rotates the robot 90 degrees left (changes direction). Ignored if the robot has not been placed yet.
RIGHT RIGHT Rotates the robot 90 degrees right (changes direction). Ignored if the robot has not been placed yet.

🧪 Running Unit Tests

The project uses xUnit to guarantee 100% coverage of the domain logic and command parser, ensuring the robot behaves correctly in all scenarios (valid moves, rotations, fall prevention, and invalid input handling).

To run all tests:

# From the solution root
dotnet test test/ToyRobot.Tests

💡 Relevant Architectural Information

1. Separation of Concerns (SoC)

The project is divided into clear layers, adhering to the SoC principle:

  • ToyRobot.Domain: Contains only the business rules (Robot, Tabletop, Direction), completely isolated from the user interface.

  • ToyRobot.Commands: Implements the Command Pattern and the factory (CommandParser), translating the input string into a domain action.

  • ToyRobot.App: The entry point (console interface) that initializes the IoC Container and manages input/output (ICommandSource).

2. Tabletop Configuration

The size of the tabletop (default $6 \times 6$) is defined in the configuration file (appsettings.json).

JSON

{
  "TabletopConfig": {
    "Size": 6
  }
}

To change the size (e.g., to $10 \times 10$), simply change the Size value to 10 and restart the application. The Tabletop service consumes this value via Dependency Injection.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published