robojora 0.1.0 → 0.1.1
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 +4 -4
- data/Gemfile.lock +0 -6
- data/README.md +57 -13
- data/lib/robojora/board.rb +2 -7
- data/lib/robojora/border_classifier.rb +4 -6
- data/lib/robojora/robot.rb +10 -2
- data/lib/robojora/rotator.rb +8 -6
- data/lib/robojora/settings.rb +45 -0
- data/lib/robojora/version.rb +1 -1
- data/lib/robojora.rb +2 -1
- data/robojora.gemspec +0 -1
- data/smaller_robot.png +0 -0
- metadata +3 -16
- data/lib/robojora/cardinal_directions.rb +0 -15
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b72ba8db6436c7677b7600cb6fc1fc24d81e75599bbf44524fdcf325e72ee2d5
|
|
4
|
+
data.tar.gz: 833d8299767fbbab25b5fbe62ca0f345ded2da13de99b1fca65692b3b1b6ecfe
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: aa8faecc15c1ae3d63fd2c457ec14d261187681b042b253eb3a4fd7cc10eaa72f9e73853c863a947d574cd15515624f48d125ef304a7126e28c8826377ce92fc
|
|
7
|
+
data.tar.gz: 89760a6fe8ec19fe75ac08ea29eb6669ce3538882556e58d35f0aabb054f8108fa948e283d806990cbae4227922c897fdf87d67213fe10b6c91ed476f8fc1c16
|
data/Gemfile.lock
CHANGED
|
@@ -6,12 +6,7 @@ PATH
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: https://rubygems.org/
|
|
8
8
|
specs:
|
|
9
|
-
coderay (1.1.2)
|
|
10
9
|
diff-lcs (1.3)
|
|
11
|
-
method_source (0.9.2)
|
|
12
|
-
pry (0.12.2)
|
|
13
|
-
coderay (~> 1.1.0)
|
|
14
|
-
method_source (~> 0.9.0)
|
|
15
10
|
rake (10.5.0)
|
|
16
11
|
rspec (3.9.0)
|
|
17
12
|
rspec-core (~> 3.9.0)
|
|
@@ -32,7 +27,6 @@ PLATFORMS
|
|
|
32
27
|
|
|
33
28
|
DEPENDENCIES
|
|
34
29
|
bundler (~> 2.0)
|
|
35
|
-
pry (~> 0.12.2)
|
|
36
30
|
rake (~> 10.0)
|
|
37
31
|
robojora!
|
|
38
32
|
rspec (~> 3.0)
|
data/README.md
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
1
3
|
# Robojora
|
|
4
|
+
[](https://travis-ci.com/enriquesalceda/robojora)
|
|
2
5
|
|
|
3
|
-
|
|
6
|
+
This is Enrique's Jora robot challenge. I have created a gem called `Robojora`
|
|
7
|
+
that contains:
|
|
4
8
|
|
|
5
|
-
|
|
9
|
+
- The logic required by the challenge.
|
|
10
|
+
- Automated testing.
|
|
11
|
+
- CI integration with Travis.
|
|
6
12
|
|
|
7
13
|
## Installation
|
|
8
14
|
|
|
9
|
-
|
|
15
|
+
If you are going to test locally, I recommend you to:
|
|
16
|
+
|
|
17
|
+
```shell
|
|
18
|
+
$ gem install robojora
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Or, if you want to add this to an app:
|
|
10
22
|
|
|
11
23
|
```ruby
|
|
12
24
|
gem 'robojora'
|
|
@@ -14,25 +26,57 @@ gem 'robojora'
|
|
|
14
26
|
|
|
15
27
|
And then execute:
|
|
16
28
|
|
|
17
|
-
|
|
29
|
+
```shell
|
|
30
|
+
$ bundle
|
|
31
|
+
```
|
|
18
32
|
|
|
19
|
-
|
|
33
|
+
## Usage
|
|
20
34
|
|
|
21
|
-
|
|
35
|
+
Let's say you ran `gem install robojora`, now you can:
|
|
22
36
|
|
|
23
|
-
|
|
37
|
+
* Go to pry
|
|
24
38
|
|
|
25
|
-
|
|
39
|
+
```shell
|
|
40
|
+
$ pry
|
|
41
|
+
```
|
|
26
42
|
|
|
27
|
-
|
|
43
|
+
* Require `robojora`
|
|
44
|
+
```shell
|
|
45
|
+
> require 'robojora'
|
|
46
|
+
```
|
|
28
47
|
|
|
29
|
-
|
|
48
|
+
From here you can start testing the code. First of all you have to build a board
|
|
49
|
+
like this:
|
|
30
50
|
|
|
31
|
-
|
|
51
|
+
```ruby
|
|
52
|
+
full_board = Robojora::Board.new.build
|
|
53
|
+
```
|
|
32
54
|
|
|
33
|
-
|
|
55
|
+
Then, create a robot like this:
|
|
34
56
|
|
|
35
|
-
|
|
57
|
+
```ruby
|
|
58
|
+
robot = Robojora::Robot.new('tars')
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Now, tars can start playing a board like this:
|
|
62
|
+
|
|
63
|
+
```ruby
|
|
64
|
+
robot.play_board(full_board)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
From here you can start placing the robot like this:
|
|
68
|
+
|
|
69
|
+
```ruby
|
|
70
|
+
robot.place(3, 3, 'north')
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
And then, you can continue rotating, moving, and reporting the report!
|
|
74
|
+
|
|
75
|
+
```ruby
|
|
76
|
+
robot.left
|
|
77
|
+
robot.move
|
|
78
|
+
robot.report
|
|
79
|
+
```
|
|
36
80
|
|
|
37
81
|
## License
|
|
38
82
|
|
data/lib/robojora/board.rb
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
1
|
module Robojora
|
|
4
2
|
class Board
|
|
5
|
-
MINIMUM_AXIS_VALUE = 0
|
|
6
|
-
MAXIMUM_AXIS_VALUE = 4
|
|
7
|
-
|
|
8
3
|
def initialize
|
|
9
|
-
@minimum_axis_value =
|
|
10
|
-
@maximum_axis_value =
|
|
4
|
+
@minimum_axis_value = Robojora::Settings.minimum_axis_value
|
|
5
|
+
@maximum_axis_value = Robojora::Settings.maximum_axis_value
|
|
11
6
|
end
|
|
12
7
|
|
|
13
8
|
def build
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
module Robojora
|
|
2
2
|
class BorderClassifier
|
|
3
|
-
MINIMUM_AXIS_VALUE = 0
|
|
4
|
-
MAXIMUM_AXIS_VALUE = 4
|
|
5
3
|
|
|
6
4
|
attr_reader :borders, :coordinates
|
|
7
5
|
|
|
@@ -21,19 +19,19 @@ module Robojora
|
|
|
21
19
|
private
|
|
22
20
|
|
|
23
21
|
def assign_to_north_border_if_north_coordinate
|
|
24
|
-
borders <<
|
|
22
|
+
borders << Robojora::Settings.north if coordinates.last == Robojora::Settings.maximum_axis_value
|
|
25
23
|
end
|
|
26
24
|
|
|
27
25
|
def assign_to_west_border_if_west_coordinate
|
|
28
|
-
borders <<
|
|
26
|
+
borders << Robojora::Settings.west if coordinates.first == Robojora::Settings.minimum_axis_value
|
|
29
27
|
end
|
|
30
28
|
|
|
31
29
|
def assign_to_south_border_if_south_coordinate
|
|
32
|
-
borders <<
|
|
30
|
+
borders << Robojora::Settings.south if coordinates.last == Robojora::Settings.minimum_axis_value
|
|
33
31
|
end
|
|
34
32
|
|
|
35
33
|
def assign_to_east_border_if_east_coordinate
|
|
36
|
-
borders <<
|
|
34
|
+
borders << Robojora::Settings.east if coordinates.first == Robojora::Settings.maximum_axis_value
|
|
37
35
|
end
|
|
38
36
|
end
|
|
39
37
|
end
|
data/lib/robojora/robot.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
require 'pry'
|
|
2
1
|
module Robojora
|
|
3
2
|
class Robot
|
|
4
3
|
NOT_IN_BOARD = 'Robot is not on the board'.freeze
|
|
4
|
+
private_constant :NOT_IN_BOARD
|
|
5
5
|
|
|
6
6
|
attr_reader :board, :name
|
|
7
7
|
attr_accessor :facing
|
|
@@ -16,6 +16,9 @@ module Robojora
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def place(x_coordinate, y_coordinate, facing)
|
|
19
|
+
raise ArgumentError, 'x_coordinate and y_coordinate must be integers' unless x_coordinate.is_a?(Integer) && y_coordinate.is_a?(Integer)
|
|
20
|
+
raise CardinalDirectionError, 'facing should be a cardinal point string' unless Robojora::Settings.cardinal_points.include?(facing) || !select_square_by_name.nil?
|
|
21
|
+
|
|
19
22
|
square = select_square_by_coordinates(x_coordinate, y_coordinate)
|
|
20
23
|
robot_removing_and_placing(facing, square) if square
|
|
21
24
|
end
|
|
@@ -33,7 +36,7 @@ module Robojora
|
|
|
33
36
|
end
|
|
34
37
|
|
|
35
38
|
def move
|
|
36
|
-
raise Robojora::RobotNotOnBoardError if
|
|
39
|
+
raise Robojora::RobotNotOnBoardError if not_movable?
|
|
37
40
|
|
|
38
41
|
mover.move
|
|
39
42
|
end
|
|
@@ -50,6 +53,7 @@ module Robojora
|
|
|
50
53
|
remove_robot_from_current_square
|
|
51
54
|
self.facing ||= facing
|
|
52
55
|
square.presence = name
|
|
56
|
+
true
|
|
53
57
|
end
|
|
54
58
|
|
|
55
59
|
private
|
|
@@ -70,5 +74,9 @@ module Robojora
|
|
|
70
74
|
def mover
|
|
71
75
|
Robojora::Movers.const_get(facing.capitalize).new(self)
|
|
72
76
|
end
|
|
77
|
+
|
|
78
|
+
def not_movable?
|
|
79
|
+
select_square_by_name.nil? || select_square_by_name.borders.include?(facing)
|
|
80
|
+
end
|
|
73
81
|
end
|
|
74
82
|
end
|
data/lib/robojora/rotator.rb
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
module Robojora
|
|
2
2
|
class Rotator
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
LEFT = (Robojora::Settings.cardinal_points + [Robojora::Settings.north]).freeze
|
|
4
|
+
RIGHT = LEFT.reverse.freeze
|
|
5
|
+
|
|
6
|
+
private_constant :LEFT, :RIGHT
|
|
5
7
|
|
|
6
8
|
attr_reader :initial_direction
|
|
7
9
|
|
|
@@ -10,21 +12,21 @@ module Robojora
|
|
|
10
12
|
end
|
|
11
13
|
|
|
12
14
|
def left
|
|
13
|
-
|
|
15
|
+
LEFT.fetch(left_desired_cardinal_direction_index)
|
|
14
16
|
end
|
|
15
17
|
|
|
16
18
|
def right
|
|
17
|
-
|
|
19
|
+
RIGHT.fetch(right_desired_cardinal_direction_index)
|
|
18
20
|
end
|
|
19
21
|
|
|
20
22
|
private
|
|
21
23
|
|
|
22
24
|
def left_desired_cardinal_direction_index
|
|
23
|
-
|
|
25
|
+
LEFT.index(initial_direction) + 1
|
|
24
26
|
end
|
|
25
27
|
|
|
26
28
|
def right_desired_cardinal_direction_index
|
|
27
|
-
|
|
29
|
+
RIGHT.index(initial_direction) + 1
|
|
28
30
|
end
|
|
29
31
|
end
|
|
30
32
|
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
module Robojora
|
|
2
|
+
class Settings
|
|
3
|
+
MINIMUM_AXIS_VALUE = 0
|
|
4
|
+
MAXIMUM_AXIS_VALUE = 4
|
|
5
|
+
|
|
6
|
+
NORTH = 'north'.freeze
|
|
7
|
+
WEST = 'west'.freeze
|
|
8
|
+
SOUTH = 'south'.freeze
|
|
9
|
+
EAST = 'east'.freeze
|
|
10
|
+
|
|
11
|
+
CARDINAL_POINTS = [NORTH, WEST, SOUTH, EAST].freeze
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
private_constant :NORTH, :WEST, :SOUTH, :EAST, :CARDINAL_POINTS,
|
|
15
|
+
:MINIMUM_AXIS_VALUE, :MAXIMUM_AXIS_VALUE
|
|
16
|
+
|
|
17
|
+
def self.minimum_axis_value
|
|
18
|
+
MINIMUM_AXIS_VALUE
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def self.maximum_axis_value
|
|
22
|
+
MAXIMUM_AXIS_VALUE
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.cardinal_points
|
|
26
|
+
CARDINAL_POINTS
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.north
|
|
30
|
+
NORTH
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.west
|
|
34
|
+
WEST
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def self.south
|
|
38
|
+
SOUTH
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def self.east
|
|
42
|
+
EAST
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
data/lib/robojora/version.rb
CHANGED
data/lib/robojora.rb
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
require 'robojora/version'
|
|
2
|
+
require 'robojora/settings'
|
|
2
3
|
require 'robojora/board'
|
|
3
4
|
require 'robojora/border_classifier'
|
|
4
5
|
require 'robojora/square'
|
|
5
6
|
require 'robojora/robot'
|
|
6
7
|
require 'robojora/rotator'
|
|
7
|
-
require 'robojora/cardinal_directions'
|
|
8
8
|
require 'robojora/movers/mover'
|
|
9
9
|
require 'robojora/movers/north'
|
|
10
10
|
require 'robojora/movers/south'
|
|
@@ -13,4 +13,5 @@ require 'robojora/movers/east'
|
|
|
13
13
|
|
|
14
14
|
module Robojora
|
|
15
15
|
class RobotNotOnBoardError < StandardError; end
|
|
16
|
+
class CardinalDirectionError < StandardError; end
|
|
16
17
|
end
|
data/robojora.gemspec
CHANGED
data/smaller_robot.png
ADDED
|
Binary file
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: robojora
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Enrique Salceda
|
|
@@ -38,20 +38,6 @@ dependencies:
|
|
|
38
38
|
- - "~>"
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: '10.0'
|
|
41
|
-
- !ruby/object:Gem::Dependency
|
|
42
|
-
name: pry
|
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
|
44
|
-
requirements:
|
|
45
|
-
- - "~>"
|
|
46
|
-
- !ruby/object:Gem::Version
|
|
47
|
-
version: 0.12.2
|
|
48
|
-
type: :development
|
|
49
|
-
prerelease: false
|
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
-
requirements:
|
|
52
|
-
- - "~>"
|
|
53
|
-
- !ruby/object:Gem::Version
|
|
54
|
-
version: 0.12.2
|
|
55
41
|
- !ruby/object:Gem::Dependency
|
|
56
42
|
name: rspec
|
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -85,7 +71,6 @@ files:
|
|
|
85
71
|
- lib/robojora.rb
|
|
86
72
|
- lib/robojora/board.rb
|
|
87
73
|
- lib/robojora/border_classifier.rb
|
|
88
|
-
- lib/robojora/cardinal_directions.rb
|
|
89
74
|
- lib/robojora/movers/east.rb
|
|
90
75
|
- lib/robojora/movers/mover.rb
|
|
91
76
|
- lib/robojora/movers/north.rb
|
|
@@ -93,9 +78,11 @@ files:
|
|
|
93
78
|
- lib/robojora/movers/west.rb
|
|
94
79
|
- lib/robojora/robot.rb
|
|
95
80
|
- lib/robojora/rotator.rb
|
|
81
|
+
- lib/robojora/settings.rb
|
|
96
82
|
- lib/robojora/square.rb
|
|
97
83
|
- lib/robojora/version.rb
|
|
98
84
|
- robojora.gemspec
|
|
85
|
+
- smaller_robot.png
|
|
99
86
|
homepage: https://github.com/enriquesalceda/robojora
|
|
100
87
|
licenses:
|
|
101
88
|
- MIT
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
module Robojora
|
|
2
|
-
class CardinalDirections
|
|
3
|
-
CARDINAL_POINTS = %w[north west south east].freeze
|
|
4
|
-
|
|
5
|
-
def self.all
|
|
6
|
-
CARDINAL_POINTS
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
Robojora::CardinalDirections::CARDINAL_POINTS.each do |cardinal_point|
|
|
10
|
-
define_singleton_method(:"#{cardinal_point}") do
|
|
11
|
-
"#{state.upcase}"
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|