robot_rea 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +1 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +37 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +2 -0
- data/bin/console +0 -0
- data/bin/robot +5 -0
- data/bin/robot.exe +6 -0
- data/bin/setup +8 -0
- data/config.yaml +4 -0
- data/lib/robot.rb +14 -0
- data/lib/robot/command_proxy.rb +52 -0
- data/lib/robot/commands.rb +10 -0
- data/lib/robot/commands/base.rb +13 -0
- data/lib/robot/commands/factory.rb +16 -0
- data/lib/robot/commands/left.rb +13 -0
- data/lib/robot/commands/move.rb +20 -0
- data/lib/robot/commands/no_op.rb +17 -0
- data/lib/robot/commands/place.rb +26 -0
- data/lib/robot/commands/place_command_parser.rb +9 -0
- data/lib/robot/commands/report.rb +16 -0
- data/lib/robot/commands/right.rb +15 -0
- data/lib/robot/directions.rb +10 -0
- data/lib/robot/game.rb +24 -0
- data/lib/robot/point.rb +44 -0
- data/lib/robot/position.rb +66 -0
- data/lib/robot/table.rb +46 -0
- data/lib/robot/version.rb +3 -0
- data/robot.gemspec +34 -0
- metadata +137 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cce95d6985de86d54196c23696060da2a089fdd251c3d48368be695c7f22c494
|
4
|
+
data.tar.gz: 19e0d3f20d223884e0ec59860ee1a735a7f57181de20afee9759af0318638683
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 70faa108dac6ed5ff1d7ac2146af47f2da3f17326c5b10c5b4b8cf9db96038241719b0af53b0663775293d9d937ca42196573001c4fe1da9711959cd3d65b501
|
7
|
+
data.tar.gz: c7d23f3794b00b7e7a422fd114b3568cc7e28b353256ce328658748d5d536490f1566739f1b6c4fa7324b76f1287948ffff14fe36c44d508d650d5644178bff1
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at ahmad@himama.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
robot (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
byebug (11.1.3)
|
10
|
+
diff-lcs (1.4.4)
|
11
|
+
rake (10.5.0)
|
12
|
+
rspec (3.9.0)
|
13
|
+
rspec-core (~> 3.9.0)
|
14
|
+
rspec-expectations (~> 3.9.0)
|
15
|
+
rspec-mocks (~> 3.9.0)
|
16
|
+
rspec-core (3.9.2)
|
17
|
+
rspec-support (~> 3.9.3)
|
18
|
+
rspec-expectations (3.9.2)
|
19
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
20
|
+
rspec-support (~> 3.9.0)
|
21
|
+
rspec-mocks (3.9.1)
|
22
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
23
|
+
rspec-support (~> 3.9.0)
|
24
|
+
rspec-support (3.9.3)
|
25
|
+
|
26
|
+
PLATFORMS
|
27
|
+
ruby
|
28
|
+
|
29
|
+
DEPENDENCIES
|
30
|
+
bundler (~> 2.0)
|
31
|
+
byebug
|
32
|
+
rake (~> 10.0)
|
33
|
+
robot!
|
34
|
+
rspec
|
35
|
+
|
36
|
+
BUNDLED WITH
|
37
|
+
2.0.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Ahmad Al-kheat
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Robot
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/robot`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'robot'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install robot
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/robot. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
|
+
|
41
|
+
## Code of Conduct
|
42
|
+
|
43
|
+
Everyone interacting in the Robot project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/robot/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
File without changes
|
data/bin/robot
ADDED
data/bin/robot.exe
ADDED
data/bin/setup
ADDED
data/config.yaml
ADDED
data/lib/robot.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "robot/version"
|
2
|
+
require 'robot/point'
|
3
|
+
require 'robot/position'
|
4
|
+
require 'robot/directions'
|
5
|
+
require 'robot/commands'
|
6
|
+
require 'robot/command_proxy'
|
7
|
+
require 'robot/table'
|
8
|
+
require 'robot/game'
|
9
|
+
|
10
|
+
module Robot
|
11
|
+
def self.run
|
12
|
+
Game.()
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# This class implements the proxy design pattern. It sits between the client and the commands,
|
2
|
+
# and only invokes the command if it passes validation.
|
3
|
+
module Robot
|
4
|
+
class CommandProxy
|
5
|
+
|
6
|
+
attr_reader :command_string, :position, :min_point, :max_point
|
7
|
+
|
8
|
+
def initialize(command_string:, position: nil)
|
9
|
+
@command_string = command_string
|
10
|
+
@position = position
|
11
|
+
end
|
12
|
+
|
13
|
+
def call
|
14
|
+
return if not_placed_yet? && !place_command?
|
15
|
+
return position if would_fall?
|
16
|
+
|
17
|
+
execute
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def execute
|
23
|
+
if place_command?
|
24
|
+
command_class.build_from_string_command(command_string)
|
25
|
+
else
|
26
|
+
command_class.(position)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def command_class
|
31
|
+
Robot::Commands::Factory.build(command_string)
|
32
|
+
end
|
33
|
+
|
34
|
+
def would_fall?
|
35
|
+
return unless [Robot::Commands::Move, Robot::Commands::Place].include?(command_class)
|
36
|
+
new_position = execute
|
37
|
+
new_position.point > table.max_point || new_position.point < table.min_point
|
38
|
+
end
|
39
|
+
|
40
|
+
def table
|
41
|
+
@table ||= Robot::Table.new
|
42
|
+
end
|
43
|
+
|
44
|
+
def not_placed_yet?
|
45
|
+
position.nil?
|
46
|
+
end
|
47
|
+
|
48
|
+
def place_command?
|
49
|
+
command_class == Robot::Commands::Place
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'robot/commands/place_command_parser'
|
2
|
+
require 'robot/commands/base'
|
3
|
+
require 'robot/commands/no_op'
|
4
|
+
require 'robot/commands/move'
|
5
|
+
require 'robot/commands/left'
|
6
|
+
require 'robot/commands/right'
|
7
|
+
require 'robot/commands/place'
|
8
|
+
require 'robot/commands/report'
|
9
|
+
require 'robot/commands/factory'
|
10
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Robot
|
2
|
+
module Commands
|
3
|
+
class Base
|
4
|
+
def self.matches(command)
|
5
|
+
raise NotImplementedError, "#{self.class} has not implemented method '#{__method__}'"
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.call
|
9
|
+
raise NotImplementedError, "#{self.class} has not implemented method '#{__method__}'"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# Factory class that takes a command input and returns the command object that can handle it,
|
2
|
+
# this is used instead of if/else or case/when for each command.
|
3
|
+
# If the command entered does not match any known command, the NoOp Command will be returned.
|
4
|
+
|
5
|
+
module Robot
|
6
|
+
module Commands
|
7
|
+
COMMANDS = [Left, Right, Move, Place, Report, NoOp]
|
8
|
+
|
9
|
+
class Factory
|
10
|
+
def self.build(command)
|
11
|
+
command_klass = COMMANDS.detect { |klass| klass.matches?(command) }
|
12
|
+
command_klass
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Robot
|
2
|
+
module Commands
|
3
|
+
class Move < Base
|
4
|
+
MOVE = 'MOVE'.freeze
|
5
|
+
|
6
|
+
def self.matches?(command)
|
7
|
+
command == MOVE
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.call(position)
|
11
|
+
{
|
12
|
+
Robot::Directions::NORTH => position.north,
|
13
|
+
Robot::Directions::SOUTH => position.south,
|
14
|
+
Robot::Directions::EAST => position.east,
|
15
|
+
Robot::Directions::WEST => position.west,
|
16
|
+
}.fetch(position.direction)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# A no operation command that's returned to avoid nil exceptions when the command the user
|
2
|
+
# enters is invalid. The idea is based on the null pointer design pattern
|
3
|
+
|
4
|
+
module Robot
|
5
|
+
module Commands
|
6
|
+
class NoOp < Base
|
7
|
+
|
8
|
+
def self.matches?(command)
|
9
|
+
true
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.call(position)
|
13
|
+
position
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Robot
|
2
|
+
module Commands
|
3
|
+
class Place < Base
|
4
|
+
extend PlaceCommandParser
|
5
|
+
|
6
|
+
REGEX = /^\A(PLACE) \d,\d,(NORTH|EAST|WEST|SOUTH)\z/
|
7
|
+
|
8
|
+
|
9
|
+
def self.matches?(command)
|
10
|
+
command =~ REGEX
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.call(x:, y:, f:)
|
14
|
+
Robot::Position.new(point: Point.new(x: x, y: y), direction: f)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.build_from_string_command(command)
|
18
|
+
x, y, f = parse(command)
|
19
|
+
x = x.to_i
|
20
|
+
y = y.to_i
|
21
|
+
f = f.to_sym
|
22
|
+
call(x: x, y: y, f: f)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/robot/game.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module Robot
|
2
|
+
class Game
|
3
|
+
attr_reader :input
|
4
|
+
def initialize(input: $stdin)
|
5
|
+
@input = input
|
6
|
+
end
|
7
|
+
|
8
|
+
def simulate
|
9
|
+
while command = input.gets
|
10
|
+
command = command.chomp
|
11
|
+
|
12
|
+
@position = Robot::CommandProxy.new(command_string: command, position: @position).call
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.call(input: $stdin)
|
17
|
+
game = new(input: input)
|
18
|
+
game.simulate
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
data/lib/robot/point.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Point value object
|
2
|
+
|
3
|
+
module Robot
|
4
|
+
class Point
|
5
|
+
attr_reader :x, :y
|
6
|
+
|
7
|
+
def initialize(x:, y:)
|
8
|
+
@x = x
|
9
|
+
@y = y
|
10
|
+
end
|
11
|
+
|
12
|
+
def north
|
13
|
+
Point.new(x: x, y: y + 1)
|
14
|
+
end
|
15
|
+
|
16
|
+
def south
|
17
|
+
Point.new(x: x, y: y - 1)
|
18
|
+
end
|
19
|
+
|
20
|
+
def east
|
21
|
+
Point.new(x: x + 1, y: y)
|
22
|
+
end
|
23
|
+
|
24
|
+
def west
|
25
|
+
Point.new(x: x - 1, y: y)
|
26
|
+
end
|
27
|
+
|
28
|
+
def ==(point)
|
29
|
+
x == point.x && y == point.y
|
30
|
+
end
|
31
|
+
|
32
|
+
def >(point)
|
33
|
+
x > point.x || y > point.y
|
34
|
+
end
|
35
|
+
|
36
|
+
def <(point)
|
37
|
+
x < point.x || y < point.y
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_s
|
41
|
+
"#{x}, #{y}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# Position value object
|
2
|
+
|
3
|
+
module Robot
|
4
|
+
class Position
|
5
|
+
attr_reader :point, :direction
|
6
|
+
|
7
|
+
def initialize(point: Point.new(x: 0, y: 0), direction: Robot::Directions::NORTH)
|
8
|
+
@point = point
|
9
|
+
@direction = direction
|
10
|
+
end
|
11
|
+
|
12
|
+
def north
|
13
|
+
Position.new(point: point.north, direction: direction)
|
14
|
+
end
|
15
|
+
|
16
|
+
def south
|
17
|
+
Position.new(point: point.south, direction: direction)
|
18
|
+
end
|
19
|
+
|
20
|
+
def east
|
21
|
+
Position.new(point: point.east, direction: direction)
|
22
|
+
end
|
23
|
+
|
24
|
+
def west
|
25
|
+
Position.new(point: point.west, direction: direction)
|
26
|
+
end
|
27
|
+
|
28
|
+
def left
|
29
|
+
Position.new(point: point, direction: lefts[direction] )
|
30
|
+
end
|
31
|
+
|
32
|
+
def right
|
33
|
+
Position.new(point: point, direction: rights[direction] )
|
34
|
+
end
|
35
|
+
|
36
|
+
def ==(position)
|
37
|
+
point == position.point && direction == position.direction
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_s
|
41
|
+
"#{point}, #{direction}"
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def lefts
|
47
|
+
{
|
48
|
+
Robot::Directions::EAST => Robot::Directions::NORTH,
|
49
|
+
Robot::Directions::NORTH => Robot::Directions::WEST,
|
50
|
+
Robot::Directions::WEST => Robot::Directions::SOUTH,
|
51
|
+
Robot::Directions::SOUTH => Robot::Directions::EAST,
|
52
|
+
}.freeze
|
53
|
+
end
|
54
|
+
|
55
|
+
def rights
|
56
|
+
{
|
57
|
+
Robot::Directions::EAST => Robot::Directions::SOUTH,
|
58
|
+
Robot::Directions::SOUTH => Robot::Directions::WEST,
|
59
|
+
Robot::Directions::WEST => Robot::Directions::NORTH,
|
60
|
+
Robot::Directions::NORTH => Robot::Directions::EAST,
|
61
|
+
}.freeze
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
|
data/lib/robot/table.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Robot
|
4
|
+
class Table
|
5
|
+
attr_reader :min_point, :max_point
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@min_point = set_min_point
|
9
|
+
@max_point = set_max_point
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def set_min_point
|
15
|
+
Point.new(x: minimum_x, y: minimum_y)
|
16
|
+
end
|
17
|
+
|
18
|
+
def set_max_point
|
19
|
+
Point.new(x: maximum_x, y: maximum_y)
|
20
|
+
end
|
21
|
+
|
22
|
+
def config_file
|
23
|
+
YAML.load_file(File.join(root, 'config.yaml'))
|
24
|
+
end
|
25
|
+
|
26
|
+
def root
|
27
|
+
File.expand_path('../../../', __FILE__)
|
28
|
+
end
|
29
|
+
|
30
|
+
def minimum_x
|
31
|
+
config_file["min_x"]
|
32
|
+
end
|
33
|
+
|
34
|
+
def minimum_y
|
35
|
+
config_file["min_y"]
|
36
|
+
end
|
37
|
+
|
38
|
+
def maximum_x
|
39
|
+
config_file["max_x"]
|
40
|
+
end
|
41
|
+
|
42
|
+
def maximum_y
|
43
|
+
config_file["max_y"]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/robot.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "robot/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "robot_rea"
|
7
|
+
spec.version = Robot::VERSION
|
8
|
+
spec.authors = ["Anonymous"]
|
9
|
+
spec.email = ["a@a.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{robot simulation}
|
12
|
+
spec.description = %q{robot simulation}
|
13
|
+
spec.homepage = "http://rubygems.org/gems/robot_rea"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = "http://test.com"
|
18
|
+
spec.metadata["changelog_uri"] = "http://test.com"
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.executables = ['robot']
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
+
spec.add_development_dependency "rspec"
|
32
|
+
spec.add_development_dependency "byebug"
|
33
|
+
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: robot_rea
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Anonymous
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-08-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: robot simulation
|
70
|
+
email:
|
71
|
+
- a@a.com
|
72
|
+
executables:
|
73
|
+
- robot
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- CODE_OF_CONDUCT.md
|
80
|
+
- Gemfile
|
81
|
+
- Gemfile.lock
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- bin/console
|
86
|
+
- bin/robot
|
87
|
+
- bin/robot.exe
|
88
|
+
- bin/setup
|
89
|
+
- config.yaml
|
90
|
+
- lib/robot.rb
|
91
|
+
- lib/robot/command_proxy.rb
|
92
|
+
- lib/robot/commands.rb
|
93
|
+
- lib/robot/commands/base.rb
|
94
|
+
- lib/robot/commands/factory.rb
|
95
|
+
- lib/robot/commands/left.rb
|
96
|
+
- lib/robot/commands/move.rb
|
97
|
+
- lib/robot/commands/no_op.rb
|
98
|
+
- lib/robot/commands/place.rb
|
99
|
+
- lib/robot/commands/place_command_parser.rb
|
100
|
+
- lib/robot/commands/report.rb
|
101
|
+
- lib/robot/commands/right.rb
|
102
|
+
- lib/robot/directions.rb
|
103
|
+
- lib/robot/game.rb
|
104
|
+
- lib/robot/point.rb
|
105
|
+
- lib/robot/position.rb
|
106
|
+
- lib/robot/table.rb
|
107
|
+
- lib/robot/version.rb
|
108
|
+
- robot-0.1.0.gem
|
109
|
+
- robot-0.1.1.gem
|
110
|
+
- robot.gemspec
|
111
|
+
homepage: http://rubygems.org/gems/robot_rea
|
112
|
+
licenses:
|
113
|
+
- MIT
|
114
|
+
metadata:
|
115
|
+
homepage_uri: http://rubygems.org/gems/robot_rea
|
116
|
+
source_code_uri: http://test.com
|
117
|
+
changelog_uri: http://test.com
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirements: []
|
133
|
+
rubygems_version: 3.0.3
|
134
|
+
signing_key:
|
135
|
+
specification_version: 4
|
136
|
+
summary: robot simulation
|
137
|
+
test_files: []
|