项目作者: natezhengbne

项目描述 :
Toy Robot
高级语言: Java
项目地址: git://github.com/natezhengbne/toy_robot.git
创建时间: 2020-09-03T07:06:42Z
项目社区:https://github.com/natezhengbne/toy_robot

开源协议:

下载


Robot Challenge

Supported Commands

The robot can read in commands(new features with *) of the following form:

  1. PLACE PLACE 0,0,NORTH,jack
  2. MOVE MOVE jack
  3. LEFT LEFT jack
  4. RIGHT RIGHT jack
  5. REPORT REPORT jack
  6. RESET* RESET
  7. MODE* MODE SINGLE
  8. EXIT* EXIT
  9. EXTEND* EXTEND 10,10
  • PLACE will put the toy robot on the table in position X,Y(The origin (0,0) can be considered to be the SOUTH WEST most corner.) and facing NORTH, SOUTH, EAST or WEST.
  • MOVE will move the toy robot one unit forward in the direction it is currently facing.
  • LEFT and RIGHT will rotate the robot 90 degrees in the specified direction without changing the position of the robot.
  • REPORT will announce the X,Y and orientation of the robot.
  • RESET will remove all toys on the table.
  • MODE 4 modes already supported. After opening the MULTI mode, you can customize the toy name to send the command to the specific toy.
    • SINGLE default
    • MULTI_EAT Support multiple toys(less than the number of squares table) running on one table, it will “eat” previously placed toy in the same direction when it is moved.
    • MULTI_BOUNCE If there is already a toy in the target position, the toy will be pushed forward together in same direction.
    • MULTI_BOUNCE_WHEEL_WAY If there is already a toy in the target position with the same direction, the toy will be pushed forward together in same direction, otherwise, it will stands still.
  • EXIT will shutdown the application.
  • EXTEND will extend the dimensions to X units to y units

If some commands before a place or an invalid command, it should print the following output:

  1. -------- TOY ROBOT STARTED ---------
  2. ttt
  3. Commands: [PLACE, MOVE, LEFT, RIGHT, REPORT, EXIT, RESET, MODE, EXTEND]
  4. hello
  5. Commands: [PLACE, MOVE, LEFT, RIGHT, REPORT, EXIT, RESET, MODE, EXTEND]
  6. MOVE
  7. Place first

Getting started

Structure

  1. toy_robot
  2. ├── module-core -- Service logic layer
  3. ├──├──src -- Implement the ICommand to support more commands
  4. ├──├──test -- Unit test for service here
  5. ├── module-terminal -- Input & Output layer(easily for extend a different Input source, probably some chat bot)
  6. ├──├──src -- Encode and decode the input and output from console
  7. ├──├──test -- Integration test here

Dependencies

Java 1.8

Build

Checkout the source code and run the following command in the /toy_robot directory:
```shell script
./mvnw clean package

  1. ### Usage
  2. ```shell script
  3. java -jar ./module-terminal/target/terminal.jar -Dlog.path=YOUR_LOG_PATH

Docker

```shell script
cd ./module-terminal
docker build -t natezhengbne/toy_robot .
docker run -i natezhengbne/toy_robot

  1. ### Test
  2. Running the test case
  3. ```shell script
  4. ./mvnw test

or with external test files
```shell script
./mvnw test -Dtest.folder=YOUR_LOCAL_TEST_DIRECTORY

  1. example: touch a new file name as robot_test.txt in /home/robot_test

PLACE 0,0,NORTH
LEFT
REPORT
Output: 0,0,WEST
```
The unit test will compare the announced result of REPORT command with the content starts with “Output:”