A C# console application that simulates a robot navigating within a grid-based room. The robot can move forward and turn left or right based on user commands.
The Robot Game application allows users to:
- Define a room's dimensions
- Place a robot at a specific position and orientation
- Issue movement commands to the robot
- Track the robot's position and orientation
- Detect when the robot attempts to leave the room boundaries
- .NET 8.0 SDK
- IDE that supports C# (Visual Studio 2022, VS Code with C# extension, etc.)
- Clone the repository
- Navigate to the project directory
cd RobotGame
- Build the application
dotnet build
- Run the application
dotnet run --project RobotGame
The project includes unit tests using xUnit and FluentAssertions. To run the tests:
dotnet test
RobotGame/
├── RobotGame/
│ ├── Controllers/
│ ├── Enums/
│ ├── Models/
│ └── UI/
│
└── RobotGame.Tests/
RoomGrid: Defines the dimensions of the roomRobot: Represents the robot with its position and orientationPosition: Represents a coordinate (X, Y) on the gridCommandResult: Contains the result of executing commands (robot position and status)
Direction: Represents cardinal directions (North, East, South, West)
GameController: Handles the robot's movement logic and tracks its position
ConsoleUI: Manages user input and outputGridRenderer: Renders the room grid with the robot's position in ASCII
- Interactive console interface
- Visual representation of the robot's position using ASCII characters
- Validation of user inputs
- Detection when robot leaves room boundaries
- Detailed error messages
- Set up the room by entering its width and height (e.g.,
5 5) - Place the robot by providing its X position, Y position, and direction (e.g.,
1 2 N) - Control the robot with the following commands:
L: Turn leftR: Turn rightF: Move forward
- Enter a sequence of commands without spaces (e.g.,
LFRFRFLF) - The game continues until the robot tries to move outside the room boundaries
Input:
5 5
1 2 N
RFRFFRFRF
Output:
Report: 1 3 N
Input:
5 5
0 0 E
RFLFFLRF
Output:
Report: 3 1 E