toy 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog.md +3 -0
- data/Gemfile.lock +24 -21
- data/README.md +1 -1
- data/lib/toy/controller.rb +2 -2
- data/lib/toy/direction.rb +2 -2
- data/lib/toy/robot.rb +6 -6
- data/lib/toy/table.rb +10 -10
- data/lib/toy/unit.rb +4 -4
- data/lib/toy/unit_collection.rb +2 -2
- data/lib/toy/version.rb +1 -1
- data/spec/unit_collection_spec.rb +4 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 289e22b2bbdd20b253693f4ed5470eea12efe773
|
4
|
+
data.tar.gz: fc19d7e85c972aa9ab27c9a33bc682fc5a9c2987
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd198504d55a271bb88753cf7a4e517ede064fa8d4cc504e4263690488ea807bf3d54885d2549cfe23c5cdf5c12e8c23f80c4cad74538519f16de765f71482ae
|
7
|
+
data.tar.gz: d3ac65a077b77eb19263049a7eff9a0d796e785c8e68dcd7f64f6271d421c098e2fab67a053caa4eec1fafc49d5f1436db42d71566c2947e2fc83f39e3652e44
|
data/ChangeLog.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,38 +1,38 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
toy (0.1.
|
4
|
+
toy (0.1.1)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: http://rubygems.org/
|
8
8
|
specs:
|
9
|
-
codeclimate-test-reporter (0.
|
9
|
+
codeclimate-test-reporter (0.6.0)
|
10
10
|
simplecov (>= 0.7.1, < 1.0.0)
|
11
11
|
diff-lcs (1.2.5)
|
12
12
|
docile (1.1.5)
|
13
|
-
json (1.8.
|
14
|
-
|
15
|
-
|
16
|
-
rdoc (4.2.0)
|
13
|
+
json (1.8.3)
|
14
|
+
rake (11.3.0)
|
15
|
+
rdoc (4.2.2)
|
17
16
|
json (~> 1.4)
|
18
|
-
rspec (3.
|
19
|
-
rspec-core (~> 3.
|
20
|
-
rspec-expectations (~> 3.
|
21
|
-
rspec-mocks (~> 3.
|
22
|
-
rspec-core (3.
|
23
|
-
rspec-support (~> 3.
|
24
|
-
rspec-expectations (3.
|
17
|
+
rspec (3.5.0)
|
18
|
+
rspec-core (~> 3.5.0)
|
19
|
+
rspec-expectations (~> 3.5.0)
|
20
|
+
rspec-mocks (~> 3.5.0)
|
21
|
+
rspec-core (3.5.4)
|
22
|
+
rspec-support (~> 3.5.0)
|
23
|
+
rspec-expectations (3.5.0)
|
25
24
|
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
-
rspec-support (~> 3.
|
27
|
-
rspec-mocks (3.
|
28
|
-
|
29
|
-
|
25
|
+
rspec-support (~> 3.5.0)
|
26
|
+
rspec-mocks (3.5.0)
|
27
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
+
rspec-support (~> 3.5.0)
|
29
|
+
rspec-support (3.5.0)
|
30
30
|
rubygems-tasks (0.2.4)
|
31
|
-
simplecov (0.
|
31
|
+
simplecov (0.12.0)
|
32
32
|
docile (~> 1.1.0)
|
33
|
-
|
34
|
-
simplecov-html (~> 0.
|
35
|
-
simplecov-html (0.
|
33
|
+
json (>= 1.8, < 3)
|
34
|
+
simplecov-html (~> 0.10.0)
|
35
|
+
simplecov-html (0.10.0)
|
36
36
|
|
37
37
|
PLATFORMS
|
38
38
|
ruby
|
@@ -44,3 +44,6 @@ DEPENDENCIES
|
|
44
44
|
rspec (~> 3.1)
|
45
45
|
rubygems-tasks (~> 0.2)
|
46
46
|
toy!
|
47
|
+
|
48
|
+
BUNDLED WITH
|
49
|
+
1.12.5
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
[![Test Coverage](https://codeclimate.com/github/rubyengineer/toy/badges/coverage.svg)](https://codeclimate.com/github/rubyengineer/toy)
|
7
7
|
[![Dependency Status](https://gemnasium.com/rubyengineer/toy.svg)](https://gemnasium.com/rubyengineer/toy)
|
8
8
|
|
9
|
-
Simulation of a toy robot moving on a square tabletop. The robot is free to roam around the surface of the table, but must be prevented from falling to destruction. Any movement that would result in the robot falling from the table must be prevented, however further valid movement commands must still be allowed.
|
9
|
+
Simulation of a toy robot moving on a square tabletop. The robot is free to roam around the surface of the table, but must be prevented from falling to destruction. Any movement that would result in the robot falling from the table must be prevented, however further valid movement commands must still be allowed.
|
10
10
|
|
11
11
|
## Install ##
|
12
12
|
```bash
|
data/lib/toy/controller.rb
CHANGED
@@ -7,12 +7,12 @@ module Toy
|
|
7
7
|
attr_reader :robot
|
8
8
|
|
9
9
|
def initialize
|
10
|
-
@robot = Robot.new
|
10
|
+
@robot = Toy::Robot.new
|
11
11
|
end
|
12
12
|
|
13
13
|
def start
|
14
14
|
while command = gets
|
15
|
-
unless COMMANDS.include?(command.gsub(/^[A-Z]+/).first)
|
15
|
+
unless Toy::Controller::COMMANDS.include?(command.gsub(/^[A-Z]+/).first)
|
16
16
|
puts 'Invalid command! Type HELP for list of available commands.' and next
|
17
17
|
end
|
18
18
|
|
data/lib/toy/direction.rb
CHANGED
@@ -21,9 +21,9 @@ module Toy
|
|
21
21
|
private
|
22
22
|
|
23
23
|
def element(direction, index)
|
24
|
-
raise Error::DirectionError unless DIRECTION.include?(direction)
|
24
|
+
raise Toy::Direction::Error::DirectionError unless Toy::Direction::DIRECTION.include?(direction)
|
25
25
|
|
26
|
-
DIRECTION[(DIRECTION.index(direction) + index) % DIRECTION.size]
|
26
|
+
Toy::Direction::DIRECTION[(Toy::Direction::DIRECTION.index(direction) + index) % Toy::Direction::DIRECTION.size]
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
data/lib/toy/robot.rb
CHANGED
@@ -4,14 +4,14 @@ module Toy
|
|
4
4
|
class Robot
|
5
5
|
attr_reader :table, :facing
|
6
6
|
|
7
|
-
def initialize(table=Table.new, direction=Direction)
|
7
|
+
def initialize(table=Toy::Table.new, direction=Toy::Direction)
|
8
8
|
@table = table
|
9
9
|
@direction = direction
|
10
10
|
@facing = nil
|
11
11
|
end
|
12
12
|
|
13
13
|
def place(x, y, facing)
|
14
|
-
raise
|
14
|
+
raise Toy::Direction::Error::DirectionError unless Toy::Direction::DIRECTION.include?(facing)
|
15
15
|
|
16
16
|
@table.hold!(x, y, self)
|
17
17
|
@facing = facing
|
@@ -22,25 +22,25 @@ module Toy
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def position
|
25
|
-
raise Error::PlacementError unless placed?
|
25
|
+
raise Toy::Robot::Error::PlacementError unless placed?
|
26
26
|
|
27
27
|
[current_unit.x, current_unit.y, @facing]
|
28
28
|
end
|
29
29
|
|
30
30
|
def move!
|
31
|
-
raise Error::PlacementError unless placed?
|
31
|
+
raise Toy::Robot::Error::PlacementError unless placed?
|
32
32
|
|
33
33
|
place(target.x, target.y, @facing) if target && target.available?
|
34
34
|
end
|
35
35
|
|
36
36
|
def turn_left!
|
37
|
-
raise Error::PlacementError unless placed?
|
37
|
+
raise Toy::Robot::Error::PlacementError unless placed?
|
38
38
|
|
39
39
|
@facing = @direction.rotate_left(@facing)
|
40
40
|
end
|
41
41
|
|
42
42
|
def turn_right!
|
43
|
-
raise Error::PlacementError unless placed?
|
43
|
+
raise Toy::Robot::Error::PlacementError unless placed?
|
44
44
|
|
45
45
|
@facing = @direction.rotate_right(@facing)
|
46
46
|
end
|
data/lib/toy/table.rb
CHANGED
@@ -5,19 +5,19 @@ module Toy
|
|
5
5
|
X_SIZE = 5
|
6
6
|
Y_SIZE = 5
|
7
7
|
|
8
|
-
#
|
9
|
-
#
|
8
|
+
# X starts from west
|
9
|
+
# Y starts from south
|
10
10
|
|
11
11
|
attr_reader :unit_collection
|
12
12
|
|
13
|
-
def initialize(unit=Unit)
|
13
|
+
def initialize(unit=Toy::Unit)
|
14
14
|
@unit = unit
|
15
15
|
@unit_collection = generate_collection!
|
16
16
|
end
|
17
17
|
|
18
18
|
def hold!(x, y, object)
|
19
|
-
raise
|
20
|
-
raise
|
19
|
+
raise Toy::Unit::Error::CoordinateError unless x.is_a?(Fixnum)
|
20
|
+
raise Toy::Unit::Error::CoordinateError unless y.is_a?(Fixnum)
|
21
21
|
|
22
22
|
target_unit = @unit_collection.find_by_coordinates(x, y)
|
23
23
|
|
@@ -25,17 +25,17 @@ module Toy
|
|
25
25
|
@unit_collection.find_by_object(object) && @unit_collection.find_by_object(object).release!
|
26
26
|
target_unit.hold!(object)
|
27
27
|
else
|
28
|
-
raise Error::TableError
|
28
|
+
raise Toy::Table::Error::TableError
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
private
|
33
33
|
|
34
34
|
def generate_collection!
|
35
|
-
UnitCollection.new.tap do |uc|
|
36
|
-
X_SIZE.times do |x|
|
37
|
-
Y_SIZE.times do |y|
|
38
|
-
uc.add(@unit.new(
|
35
|
+
Toy::UnitCollection.new.tap do |uc|
|
36
|
+
Toy::Table::X_SIZE.times do |x|
|
37
|
+
Toy::Table::Y_SIZE.times do |y|
|
38
|
+
uc.add(@unit.new(x, y, table=self))
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
data/lib/toy/unit.rb
CHANGED
@@ -4,10 +4,10 @@ module Toy
|
|
4
4
|
class Unit
|
5
5
|
attr_reader :table, :x, :y, :object
|
6
6
|
|
7
|
-
def initialize(table=Table.new
|
8
|
-
raise Error::CoordinateError unless x.is_a?(Fixnum)
|
9
|
-
raise Error::CoordinateError unless y.is_a?(Fixnum)
|
10
|
-
raise Error::TableError unless table.is_a?(Table)
|
7
|
+
def initialize(x, y, table=Toy::Table.new)
|
8
|
+
raise Toy::Unit::Error::CoordinateError unless x.is_a?(Fixnum)
|
9
|
+
raise Toy::Unit::Error::CoordinateError unless y.is_a?(Fixnum)
|
10
|
+
raise Toy::Unit::Error::TableError unless table.is_a?(Table)
|
11
11
|
|
12
12
|
@table = table
|
13
13
|
@x = x
|
data/lib/toy/unit_collection.rb
CHANGED
@@ -10,7 +10,7 @@ module Toy
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def add(unit)
|
13
|
-
raise Error::UnitError unless unit.is_a?(Unit)
|
13
|
+
raise Toy::UnitCollection::Error::UnitError unless unit.is_a?(Unit)
|
14
14
|
|
15
15
|
@all << unit
|
16
16
|
end
|
@@ -40,7 +40,7 @@ module Toy
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def find_by_direction_of(x, y, direction)
|
43
|
-
raise Error::DirectionError unless
|
43
|
+
raise Toy::UnitCollection::Error::DirectionError unless Toy::Direction::DIRECTION.include?(direction)
|
44
44
|
|
45
45
|
send("find_#{direction}_of", x, y)
|
46
46
|
end
|
data/lib/toy/version.rb
CHANGED
@@ -5,10 +5,10 @@ require 'spec_helper'
|
|
5
5
|
describe Toy::UnitCollection do
|
6
6
|
let(:unit_collection) { Toy::UnitCollection.new }
|
7
7
|
let(:table1) { Toy::Table.new }
|
8
|
-
let!(:unit1) { Toy::Unit.new(
|
9
|
-
let!(:unit2) { Toy::Unit.new(
|
10
|
-
let!(:unit3) { Toy::Unit.new(
|
11
|
-
let!(:unit4) { Toy::Unit.new(
|
8
|
+
let!(:unit1) { Toy::Unit.new(0, 0, table=table1) }
|
9
|
+
let!(:unit2) { Toy::Unit.new(0, 1, table=table1) }
|
10
|
+
let!(:unit3) { Toy::Unit.new(1, 1, table=table1) }
|
11
|
+
let!(:unit4) { Toy::Unit.new(2, 1, table=table1) }
|
12
12
|
|
13
13
|
context 'when valid arguments' do
|
14
14
|
describe '#add' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: toy
|
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
|
- Ninoslav Milenovic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rdoc
|
@@ -121,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
121
|
version: '0'
|
122
122
|
requirements: []
|
123
123
|
rubyforge_project:
|
124
|
-
rubygems_version: 2.
|
124
|
+
rubygems_version: 2.5.1
|
125
125
|
signing_key:
|
126
126
|
specification_version: 4
|
127
127
|
summary: Summary
|