robotoy 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/commands.txt +2 -1
- data/lib/robotoy/command_parser.rb +3 -3
- data/lib/robotoy/errors.rb +29 -5
- data/lib/robotoy/game.rb +10 -19
- data/lib/robotoy/services/move.rb +11 -12
- data/lib/robotoy/services/report.rb +13 -4
- data/lib/robotoy/version.rb +1 -1
- 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: c60b7489b010f57365859629723e0019d4dbe738
|
4
|
+
data.tar.gz: d862f6f91f4585c58e669de14da32777c58b781f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5529734b3e6eae9cd87bdc74459fc1b701cc7d8253c9ce28aad941f68729468760debf157228f7438ae0952a349a670f14587d2cd2129999a973abc20a6a548
|
7
|
+
data.tar.gz: 048de6b5917fe2958ea34bc42673472a204c67ec41167131580f6cd6a356c3ad829172780ae4d45091f3fae0454ca5f96703e8d2931110463032a513926b6891
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
[![Build Status](https://travis-ci.org/hosseintoussi/robotoy.svg?branch=master)](https://travis-ci.org/hosseintoussi/robotoy)
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/robotoy.svg)](https://badge.fury.io/rb/robotoy)
|
3
|
+
[![Code Climate](https://codeclimate.com/github/hosseintoussi/robotoy/badges/gpa.svg)](https://codeclimate.com/github/hosseintoussi/robotoy)
|
4
|
+
[![Test Coverage](https://codeclimate.com/github/hosseintoussi/robotoy/badges/coverage.svg)](https://codeclimate.com/github/hosseintoussi/robotoy/coverage)
|
3
5
|
# Robotoy
|
4
6
|
- The application is a simulation of a toy robot moving on a square tabletop, of dimensions 5 units x 5 units.
|
5
7
|
- There are no other obstructions on the table surface.
|
data/commands.txt
CHANGED
@@ -12,8 +12,8 @@ module Robotoy
|
|
12
12
|
puts command
|
13
13
|
set_params(command)
|
14
14
|
@game.perform(@method, @args)
|
15
|
-
rescue
|
16
|
-
puts
|
15
|
+
rescue Errors => e
|
16
|
+
puts e.message
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -23,7 +23,7 @@ module Robotoy
|
|
23
23
|
def set_params(command)
|
24
24
|
splitted = command.split(/\s+/)
|
25
25
|
@method = splitted[0].strip
|
26
|
-
@args = splitted[1].split(',').map(&:strip)
|
26
|
+
@args = splitted[1] ? splitted[1].split(',').map(&:strip) : []
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
data/lib/robotoy/errors.rb
CHANGED
@@ -1,7 +1,31 @@
|
|
1
1
|
module Robotoy
|
2
|
-
class Errors < StandardError
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
class Errors < StandardError
|
3
|
+
def message
|
4
|
+
"hmm.. Not sure what happened there!"
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
class NotValidOrientationError < Errors
|
9
|
+
def message
|
10
|
+
"It looks like your Robot did not know there's such oriencation!"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class NotValidMoveError < Errors
|
15
|
+
def message
|
16
|
+
"It wasn't a valid move, unfortunately!"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class NotPlacedError < Errors
|
21
|
+
def message
|
22
|
+
"Your Robot is not placed yet!"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class NotValidMethodError < Errors
|
27
|
+
def message
|
28
|
+
"I don't understand what you want me to do! :("
|
29
|
+
end
|
30
|
+
end
|
7
31
|
end
|
data/lib/robotoy/game.rb
CHANGED
@@ -11,40 +11,31 @@ module Robotoy
|
|
11
11
|
|
12
12
|
def perform(method, *args)
|
13
13
|
send(method.downcase, *args.flatten)
|
14
|
-
@action.perform
|
15
|
-
rescue NotValidMoveError
|
16
|
-
puts "Not a valid place unfortunately"
|
17
|
-
rescue NotValidOrientationError
|
18
|
-
puts "Not a valid orientation unfortunately"
|
19
|
-
rescue NotPlacedError
|
20
|
-
puts "Not placed yet"
|
21
|
-
rescue NotValidMethodError
|
22
|
-
puts "Not a valid method"
|
23
14
|
end
|
24
15
|
|
25
16
|
private
|
26
17
|
|
27
18
|
def place(x, y, orient)
|
28
|
-
@
|
19
|
+
@place.new(robot: @robot, table: @table, x: x, y: y, orient: orient).perform
|
29
20
|
end
|
30
21
|
|
31
|
-
def move(
|
32
|
-
@
|
22
|
+
def move(range = 1)
|
23
|
+
@move.new(robot: @robot, table: @table, range: range).perform
|
33
24
|
end
|
34
25
|
|
35
|
-
def left
|
36
|
-
@
|
26
|
+
def left
|
27
|
+
@orientation.new(robot: @robot, side: :left).perform
|
37
28
|
end
|
38
29
|
|
39
|
-
def right
|
40
|
-
@
|
30
|
+
def right
|
31
|
+
@orientation.new(robot: @robot, side: :right).perform
|
41
32
|
end
|
42
33
|
|
43
|
-
def report(
|
44
|
-
@
|
34
|
+
def report(type = :console)
|
35
|
+
@report.new(robot: @robot, type: type).perform
|
45
36
|
end
|
46
37
|
|
47
|
-
def method_missing(
|
38
|
+
def method_missing(_name, *_args)
|
48
39
|
raise Robotoy::NotValidMethodError
|
49
40
|
end
|
50
41
|
end
|
@@ -1,11 +1,10 @@
|
|
1
1
|
module Robotoy
|
2
2
|
module Services
|
3
3
|
class Move
|
4
|
-
def initialize(robot:, table:,
|
4
|
+
def initialize(robot:, table:, range:)
|
5
5
|
@robot = robot
|
6
6
|
@table = table
|
7
|
-
@
|
8
|
-
@y_range = y_range
|
7
|
+
@range = range.to_i
|
9
8
|
end
|
10
9
|
|
11
10
|
def perform
|
@@ -16,26 +15,26 @@ module Robotoy
|
|
16
15
|
private
|
17
16
|
|
18
17
|
def north
|
19
|
-
@table.validate_next_position(y: @robot.y + @
|
20
|
-
@robot.y += @
|
18
|
+
@table.validate_next_position(y: @robot.y + @range)
|
19
|
+
@robot.y += @range
|
21
20
|
end
|
22
21
|
|
23
22
|
def south
|
24
|
-
@table.validate_next_position(y: @robot.y - @
|
25
|
-
@robot.y -= @
|
23
|
+
@table.validate_next_position(y: @robot.y - @range)
|
24
|
+
@robot.y -= @range
|
26
25
|
end
|
27
26
|
|
28
27
|
def east
|
29
|
-
@table.validate_next_position(x: @robot.x + @
|
30
|
-
@robot.x += @
|
28
|
+
@table.validate_next_position(x: @robot.x + @range)
|
29
|
+
@robot.x += @range
|
31
30
|
end
|
32
31
|
|
33
32
|
def west
|
34
|
-
@table.validate_next_position(x: @robot.x - @
|
35
|
-
@robot.x -= @
|
33
|
+
@table.validate_next_position(x: @robot.x - @range)
|
34
|
+
@robot.x -= @range
|
36
35
|
end
|
37
36
|
|
38
|
-
def method_missing(
|
37
|
+
def method_missing(_name, *_args)
|
39
38
|
raise Robotoy::NotValidMethodError
|
40
39
|
end
|
41
40
|
end
|
@@ -1,19 +1,28 @@
|
|
1
1
|
module Robotoy
|
2
2
|
module Services
|
3
3
|
class Report
|
4
|
-
def initialize(robot:)
|
4
|
+
def initialize(robot:, type:)
|
5
5
|
@robot = robot
|
6
|
+
@type = type
|
6
7
|
end
|
7
8
|
|
8
|
-
def perform
|
9
|
+
def perform
|
9
10
|
@robot.validate_if_placed
|
10
|
-
send(type)
|
11
|
+
send(@type)
|
11
12
|
end
|
12
13
|
|
13
14
|
private
|
14
15
|
|
16
|
+
def console
|
17
|
+
puts "Output: #{string}"
|
18
|
+
end
|
19
|
+
|
15
20
|
def string
|
16
|
-
|
21
|
+
"#{@robot.x},#{@robot.y},#{@robot.orientation.upcase}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def method_missing(_name, *_args)
|
25
|
+
raise Robotoy::NotValidMethodError
|
17
26
|
end
|
18
27
|
end
|
19
28
|
end
|
data/lib/robotoy/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: robotoy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hosseintoussi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
118
|
version: '0'
|
119
119
|
requirements: []
|
120
120
|
rubyforge_project:
|
121
|
-
rubygems_version: 2.
|
121
|
+
rubygems_version: 2.4.8
|
122
122
|
signing_key:
|
123
123
|
specification_version: 4
|
124
124
|
summary: Toy Robot Ruby
|