lemmibot 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d125d14ad12b0139f69af46b5051534ab07d8395
4
- data.tar.gz: cd9242fa6928f0db371708a91aa157b8e2ba3ea9
3
+ metadata.gz: d9b547cbeee34311afbfa2a4d807fab0917075e9
4
+ data.tar.gz: 2e6f30d57bfbcb0652a438338ea0ce5db36d3813
5
5
  SHA512:
6
- metadata.gz: 88f65fc237a1b5bc6daf3ba49a6b482b8da998beca9af597467d7db745521646498cbc049ecf0a1ebd7f9e33c146eb77ed2c5ad1b01d5bab2634aff4239db464
7
- data.tar.gz: 5abc057800f629faa4870d9b88ab96a078a70247bf64f7528b41893f90957a3a9a7d757fbe6babd25324d87433a7e38d40e4a00b54682badfa5b694852cdd3da
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
- # Do not prefix writer method names with set_
9
+ # Allow prefixing writer method names with set_
9
10
  Style/AccessorMethodName:
10
11
  Enabled: false
11
- # Do not suppress exceptions
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 real lemming.
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`) - Places the bot at the specified coordinates on the table top, facing the specified position.
29
- * `MOVE` - Moves the bot one unit in the currently facing direction.
30
- * `LEFT` - Rotates the bot 90 degrees left, changing the faced direction but not moving the bot.
31
- * `RIGHT` - Rotates the bot 90 degrees right, changing the faced direction but not moving the bot.
32
- * `REPORT` - Outputs a report of the bot's current position and direction, in the format `0,1,NORTH`.
33
-
34
- The bot must be placed before it will accept any other commands.
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 erroneous commands (including unrecognised commands and malformed commands) will be silently ignored.
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.g. placing it off the edge of the table, or attempting to move the bot off the edge of the table)
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
- * `basic_move` - Demonstrates moving Lemmibot one unit and reporting. The output should be `0,1,NORTH`.
51
- * `basic_rotate` - Demonstrates rotating Lemmibot 90 degrees left and reporting. The output should be `0,0,WEST`.
52
- * `move_and_rotate` - Demonstrates moving and rotating Lemmibot, then reporting. The output should be `3,3,NORTH`.
53
- * `self_preservation` - Demonstrates that Lemmibot will not jump off the table. The output should be `2,4,EAST`.
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
- After cloning the repository, you may use the setup script at `./bin/setup` to install development dependencies.
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
- To run the RSpec test suite and Rubocop style checker against Lemmibot, run `bundle exec rake`.
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
@@ -2,6 +2,6 @@ require 'lemmibot/version'
2
2
  require 'lemmibot/bot'
3
3
  require 'lemmibot/command_interface'
4
4
 
5
- # A toy robot simulator
5
+ # A toy robot with better self-preservation instincts than a lemming
6
6
  module Lemmibot
7
7
  end
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
- change = if relative_direction == :left
16
- -1
17
- else
18
- 1
19
- end
20
- next_direction_index = DIRECTIONS.index(@direction) + change
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 via CLI/STDIN
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 /PLACE/ then place(command)
27
- when /MOVE/ then @bot.move
28
- when /LEFT/ then @bot.turn(:left)
29
- when /RIGHT/ then @bot.turn(:right)
30
- when /REPORT/ then report
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)
@@ -1,3 +1,3 @@
1
1
  module Lemmibot
2
- VERSION = '0.2.1'.freeze
2
+ VERSION = '0.2.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lemmibot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Effy Elden