lemmibot 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -2
- data/README.md +50 -18
- data/lib/lemmibot.rb +1 -1
- data/lib/lemmibot/bot.rb +7 -11
- data/lib/lemmibot/command_interface.rb +10 -7
- data/lib/lemmibot/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9b547cbeee34311afbfa2a4d807fab0917075e9
|
4
|
+
data.tar.gz: 2e6f30d57bfbcb0652a438338ea0ce5db36d3813
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34bf061fa9bee2db80a1892d6aecf14cb05de6c408a68e242dbda10e1e729ba6ad7a6ff350f38e2dffb20f805abbc3b03bea278f683be3fd1dfddb1e9d042f3c
|
7
|
+
data.tar.gz: 3ef074417f45aa1f561d6826d6ddd1d24ce2e10ac9b5038585c66433d0c2593f0cf7b31c7b3372f05f274bf653581f982a4b16b27136ab7b5b142a6547971dd6
|
data/.rubocop.yml
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# Exclude spec files from some Rubocop metric
|
1
2
|
Metrics/BlockLength:
|
2
3
|
Exclude:
|
3
4
|
- 'spec/**/*.rb'
|
@@ -5,9 +6,9 @@ Metrics/LineLength:
|
|
5
6
|
Exclude:
|
6
7
|
- 'spec/**/*.rb'
|
7
8
|
- 'lemmibot.gemspec'
|
8
|
-
#
|
9
|
+
# Allow prefixing writer method names with set_
|
9
10
|
Style/AccessorMethodName:
|
10
11
|
Enabled: false
|
11
|
-
#
|
12
|
+
# Allow silently suppressing exceptions
|
12
13
|
Lint/HandleExceptions:
|
13
14
|
Enabled: false
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/lemmibot.svg)](https://badge.fury.io/rb/lemmibot)
|
3
3
|
[![Build Status](https://travis-ci.org/ineffyble/lemmibot.svg)](https://travis-ci.org/ineffyble/lemmibot)
|
4
4
|
|
5
|
-
A toy robot with better self-preservation instincts than a
|
5
|
+
A toy robot with better self-preservation instincts than a lemming.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -17,6 +17,8 @@ and should run on any system running `ruby >= 2.0.0`.
|
|
17
17
|
|
18
18
|
## Usage
|
19
19
|
|
20
|
+
### Interactive
|
21
|
+
|
20
22
|
Once installed, start an interactive bot interface:
|
21
23
|
|
22
24
|
$ lemmibot
|
@@ -25,19 +27,21 @@ Congratulations! You've now created your very own Lemmibot.
|
|
25
27
|
|
26
28
|
The bot will accept the following commands:
|
27
29
|
|
28
|
-
* `PLACE X,Y,F` (e.g. `PLACE 2,1,NORTH`) -
|
29
|
-
*
|
30
|
-
*
|
31
|
-
*
|
32
|
-
* `
|
33
|
-
|
34
|
-
|
30
|
+
* `PLACE X,Y,F` (e.g. `PLACE 2,1,NORTH`) - Place the bot at the specified coordinates on the tabletop, facing the specified position.
|
31
|
+
* The tabletop is a size of 5 units by 5 units. Coordinates are zero-indexed. Valid X and Y coordinates are 0-4.
|
32
|
+
* Lemmibot can face the following directions: *north, south, east, west*.
|
33
|
+
* **The bot must be placed before it will accept any other commands.**
|
34
|
+
* `MOVE` - Move the bot one unit in the currently facing direction.
|
35
|
+
* `LEFT` - Rotate the bot 90 degrees left, changing the direction the bot is facing in.
|
36
|
+
* `RIGHT` - Rotate the bot 90 degrees right, changing the direction the bot is facing in.
|
37
|
+
* `REPORT` - Print a report of the bot's current position and direction, in the format `0,1,NORTH`.
|
35
38
|
|
36
|
-
Any
|
39
|
+
Any unrecognised or malformed commands will be silently ignored.
|
37
40
|
|
41
|
+
**Lemmibot is programmed with self-preservation routines.**
|
38
42
|
Any commands that would result in this bot's untimely demise
|
39
|
-
(e.
|
40
|
-
will be silently ignored.
|
43
|
+
(i.e. attempting to place the bot at coordinates that are not on the tabletop,
|
44
|
+
or commanding the bot to move off the table) will be silently ignored.
|
41
45
|
|
42
46
|
### Using a command script
|
43
47
|
|
@@ -45,25 +49,53 @@ Lemmibot can fed a list of commands from a file:
|
|
45
49
|
|
46
50
|
$ lemmibot < examples/basic_move
|
47
51
|
|
48
|
-
The following scripts may be found in the `examples` directory
|
52
|
+
The following scripts may be found in the `examples` directory. All examples end with a single `REPORT` command.
|
49
53
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
+
| File name | Description | Output |
|
55
|
+
| ------------------- | ------------------------------------------------------- | ----------- |
|
56
|
+
| `basic_move` | Demonstrates moving Lemmibot one unit. | `0,1,NORTH` |
|
57
|
+
| `basic_rotate` | Demonstrates rotating Lemmibot 90 degrees left. | `0,0,WEST` |
|
58
|
+
| `move_and_rotate` | Demonstrates moving and rotating Lemmibot. | `3,3,NORTH` |
|
59
|
+
| `self_preservation` | Demonstrates that Lemmibot will not jump off the table. | `2,4,EAST` |
|
54
60
|
|
55
61
|
## Development
|
56
62
|
|
63
|
+
### Tools
|
64
|
+
|
57
65
|
Lemmibot uses `rake`, `rspec`, `aruba`, and `rubocop` for development and testing.
|
58
66
|
|
59
|
-
|
67
|
+
### Set up
|
68
|
+
|
69
|
+
Clone the repository from GitHub:
|
70
|
+
|
71
|
+
$ git clone https://github.com/ineffyble/lemmibot.git
|
72
|
+
|
73
|
+
Then use the setup script at to install development dependencies.
|
74
|
+
|
75
|
+
$ cd lemmibot && ./bin/setup
|
76
|
+
|
60
77
|
|
61
|
-
|
78
|
+
### Running Lemmibot locally
|
79
|
+
|
80
|
+
To run the interactive Lemmibot interface from local source:
|
81
|
+
|
82
|
+
$ bundle exec ./exe/lemmibot
|
83
|
+
|
84
|
+
You may pipe in example scripts from the `examples/` directory, as per the Usage section of this README.
|
85
|
+
|
86
|
+
### Testing
|
87
|
+
|
88
|
+
Once you have some working code changes, run the RSpec test suite and Rubocop style checker:
|
89
|
+
|
90
|
+
$ bundle exec rake
|
62
91
|
|
63
92
|
## Contributing
|
64
93
|
|
65
94
|
Bug reports and pull requests are welcome on GitHub at https://github.com/ineffyble/lemmibot.
|
66
95
|
|
96
|
+
> "Don't *git push* me 'cause I'm close to the edge (of the tabletop)"
|
97
|
+
> ~ Lemmibot, 2017
|
98
|
+
|
67
99
|
## License
|
68
100
|
|
69
101
|
Lemmibot is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/lib/lemmibot.rb
CHANGED
data/lib/lemmibot/bot.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Lemmibot
|
2
|
-
# A simulated toy robot on a tabletop
|
2
|
+
# A simulated toy robot, which can be placed on a tabletop and given commands
|
3
3
|
class Bot
|
4
4
|
def initialize
|
5
5
|
@pos_x = 0
|
@@ -10,22 +10,18 @@ module Lemmibot
|
|
10
10
|
|
11
11
|
def turn(relative_direction)
|
12
12
|
# Rotate the bot 90 degrees to face another direction
|
13
|
-
# TODO: Find a nicer way to find the new direction
|
14
13
|
return false unless @placed
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
next_direction_index = 0 if next_direction_index > DIRECTIONS.count - 1
|
22
|
-
new_direction = DIRECTIONS[next_direction_index]
|
14
|
+
case relative_direction
|
15
|
+
when :left then change = -1
|
16
|
+
when :right then change = 1
|
17
|
+
end
|
18
|
+
current_direction_index = DIRECTIONS.index(@direction)
|
19
|
+
new_direction = DIRECTIONS.rotate(current_direction_index + change).first
|
23
20
|
set_direction(new_direction)
|
24
21
|
end
|
25
22
|
|
26
23
|
def move
|
27
24
|
# Move the bot one unit in the direction it is facing
|
28
|
-
# TODO: Find a more elegant solution for this
|
29
25
|
return false unless @placed
|
30
26
|
case @direction
|
31
27
|
when :north then return change_position(:y, 1)
|
@@ -1,11 +1,13 @@
|
|
1
1
|
module Lemmibot
|
2
|
-
# An interface for issuing commands to a Lemmibot
|
2
|
+
# An interface for issuing commands to a Lemmibot
|
3
|
+
# via interactive command-line or piped in scripts
|
3
4
|
class CommandInterface
|
4
5
|
def initialize
|
5
6
|
@bot = Lemmibot::Bot.new
|
6
7
|
end
|
7
8
|
|
8
9
|
def start
|
10
|
+
# Start a session, receiving and processing commands from standard input
|
9
11
|
puts 'Lemmibot is awaiting your commands'
|
10
12
|
loop do
|
11
13
|
command = gets
|
@@ -13,7 +15,7 @@ module Lemmibot
|
|
13
15
|
begin
|
14
16
|
process_command(command.chomp)
|
15
17
|
rescue
|
16
|
-
# Malformed and failed commands should be ignored
|
18
|
+
# Malformed and failed commands should be ignored, so take no action
|
17
19
|
end
|
18
20
|
end
|
19
21
|
end
|
@@ -23,12 +25,13 @@ module Lemmibot
|
|
23
25
|
def process_command(command)
|
24
26
|
# Process a command string
|
25
27
|
case command.upcase
|
26
|
-
when
|
27
|
-
when
|
28
|
-
when
|
29
|
-
when
|
30
|
-
when
|
28
|
+
when /^PLACE / then place(command)
|
29
|
+
when 'MOVE' then @bot.move
|
30
|
+
when 'LEFT' then @bot.turn(:left)
|
31
|
+
when 'RIGHT' then @bot.turn(:right)
|
32
|
+
when 'REPORT' then report
|
31
33
|
end
|
34
|
+
# All other commands will be silently ignored
|
32
35
|
end
|
33
36
|
|
34
37
|
def place_arguments(command)
|
data/lib/lemmibot/version.rb
CHANGED