wonderland 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +2 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/Guardfile +29 -0
- data/LICENSE.txt +22 -0
- data/README.md +34 -0
- data/Rakefile +10 -0
- data/Thorfile +39 -0
- data/VERSION +1 -0
- data/etc/gotham_board.yml +71 -0
- data/lib/gotham_board.rb +9 -0
- data/lib/wonderland.rb +3 -0
- data/lib/wonderland/active_space.rb +30 -0
- data/lib/wonderland/board.rb +42 -0
- data/lib/wonderland/grid.rb +27 -0
- data/lib/wonderland/space.rb +22 -0
- data/spec/gotham_board_spec.rb +17 -0
- data/spec/spec_helper.rb +91 -0
- data/spec/wonderland/active_space_spec.rb +108 -0
- data/spec/wonderland/board_spec.rb +56 -0
- data/spec/wonderland/grid_spec.rb +37 -0
- data/spec/wonderland/space_spec.rb +28 -0
- data/wonderland.gemspec +33 -0
- metadata +250 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cfb59e7e67d031ba97a51e6074d1718de1f049ca
|
4
|
+
data.tar.gz: 16d9a788f5f4a1c83280c24913e265c4e9d82ed4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ba6584db20c0c487c475f9ecf6075acb50001165ecb312f791fc780a727bde00f393a15b9e701a307ae25a2042d85c42e53dc65f07dee9d1261c3d2ef83d23d3
|
7
|
+
data.tar.gz: 5d88aaef91344c71bd81066f2ac889f9e1bf0da17be066564111890a71d3e6f1c0e70c3fe0a7d9091f4fd8bdb4e0cbe658d1530abc64593c5f16c1fd9e1d091e
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
## Uncomment and set this to only include directories you want to watch
|
5
|
+
# directories %(app lib config test spec feature)
|
6
|
+
|
7
|
+
## Uncomment to clear the screen before every task
|
8
|
+
# clearing :on
|
9
|
+
|
10
|
+
guard :bundler do
|
11
|
+
watch('Gemfile')
|
12
|
+
# Uncomment next line if your Gemfile contains the `gemspec' command.
|
13
|
+
# watch(/^.+\.gemspec/)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
17
|
+
# rspec may be run, below are examples of the most common uses.
|
18
|
+
# * bundler: 'bundle exec rspec'
|
19
|
+
# * bundler binstubs: 'bin/rspec'
|
20
|
+
# * spring: 'bin/rsspec' (This will use spring if running and you have
|
21
|
+
# installed the spring binstubs per the docs)
|
22
|
+
# * zeus: 'zeus rspec' (requires the server to be started separetly)
|
23
|
+
# * 'just' rspec: 'rspec'
|
24
|
+
guard :rspec, cmd: 'bundle exec rspec' do
|
25
|
+
watch(%r{^spec/.+_spec\.rb$})
|
26
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
27
|
+
watch('spec/spec_helper.rb') { "spec" }
|
28
|
+
end
|
29
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Scott M Parrish
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Wonderland
|
2
|
+
[![Build Status](https://travis-ci.org/anithri/wonderland.svg?branch=master)](https://travis-ci.org/anithri/wonderland)
|
3
|
+
[![PullReview stats](https://www.pullreview.com/github/anithri/wonderland/badges/master.svg?)](https://www.pullreview.com/github/anithri/wonderland/reviews/master)
|
4
|
+
[![Dependency Status](https://gemnasium.com/anithri/wonderland.svg)](https://gemnasium.com/anithri/wonderland)
|
5
|
+
|
6
|
+
A Game Board object and supporting pieces: spaces and grids
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'wonderland'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install wonderland
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
TODO: Write usage instructions here
|
27
|
+
|
28
|
+
## Contributing
|
29
|
+
|
30
|
+
1. Fork it ( https://github.com/[my-github-username]/wonderland/fork )
|
31
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
32
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
33
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
34
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/Thorfile
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'facets/string/pathize'
|
2
|
+
require 'facets/string/camelcase'
|
3
|
+
class MkClass < Thor::Group
|
4
|
+
include Thor::Actions
|
5
|
+
|
6
|
+
# Define arguments and options
|
7
|
+
argument :name
|
8
|
+
|
9
|
+
def self.source_root
|
10
|
+
File.dirname(__FILE__)
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_lib_file
|
14
|
+
file_name = name.pathize
|
15
|
+
parts = name.split('::')
|
16
|
+
create_file "lib/#{file_name}.rb" do
|
17
|
+
out = ''
|
18
|
+
parts.each_with_index do |part, i|
|
19
|
+
keyword = (i == parts.length - 1) ? 'class' : 'module'
|
20
|
+
indent = ' ' * i
|
21
|
+
out += indent + keyword + ' ' + part.camelcase(:upper) + "\n"
|
22
|
+
end
|
23
|
+
parts.length.times do |i|
|
24
|
+
indent = ' ' * (parts.length - i - 1)
|
25
|
+
out += "#{indent}end\n"
|
26
|
+
end
|
27
|
+
out
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def create_spec_file
|
32
|
+
file_name = name.pathize
|
33
|
+
create_file "spec/#{file_name}_spec.rb" do
|
34
|
+
"require 'rspec'\nrequire '#{file_name}'\n\ndescribe #{name} do\n\nend\n"
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,71 @@
|
|
1
|
+
---
|
2
|
+
spaces:
|
3
|
+
- :dockyard
|
4
|
+
- :old_gotham
|
5
|
+
- :wildermann
|
6
|
+
- :grant
|
7
|
+
- :churchfield
|
8
|
+
- :robinson_park
|
9
|
+
- :south_street
|
10
|
+
- :parkside
|
11
|
+
- :goldberg
|
12
|
+
- :tower
|
13
|
+
- :dockside
|
14
|
+
- :old_port
|
15
|
+
connections:
|
16
|
+
:dockyard:
|
17
|
+
- :old_gotham
|
18
|
+
- :wildermann
|
19
|
+
:old_gotham:
|
20
|
+
- :dockyard
|
21
|
+
- :south_street
|
22
|
+
:wildermann:
|
23
|
+
- :dockyard
|
24
|
+
- :south_street
|
25
|
+
- :robinson_park
|
26
|
+
:grant:
|
27
|
+
- :wildermann
|
28
|
+
- :parkside
|
29
|
+
- :dockside
|
30
|
+
- :tower
|
31
|
+
:churchfield:
|
32
|
+
- :dockside
|
33
|
+
- :tower
|
34
|
+
:robinson_park:
|
35
|
+
- :south_street
|
36
|
+
- :wildermann
|
37
|
+
- :parkside
|
38
|
+
:south_street:
|
39
|
+
- :old_gotham
|
40
|
+
- :robinson_park
|
41
|
+
- :parkside
|
42
|
+
- :goldberg
|
43
|
+
:parkside:
|
44
|
+
- :south_street
|
45
|
+
- :robinson_park
|
46
|
+
- :wildermann
|
47
|
+
- :grant
|
48
|
+
- :tower
|
49
|
+
- :goldberg
|
50
|
+
- :old_port
|
51
|
+
:goldberg:
|
52
|
+
- :south_street
|
53
|
+
- :parkside
|
54
|
+
- :tower
|
55
|
+
- :old_port
|
56
|
+
:tower:
|
57
|
+
- :grant
|
58
|
+
- :churchfield
|
59
|
+
- :dockside
|
60
|
+
- :old_port
|
61
|
+
- :goldberg
|
62
|
+
- :parkside
|
63
|
+
:old_port:
|
64
|
+
- :goldberg
|
65
|
+
- :parkside
|
66
|
+
- :tower
|
67
|
+
- :dockside
|
68
|
+
- :old_port
|
69
|
+
:dockside:
|
70
|
+
- :old_port
|
71
|
+
- :tower
|
data/lib/gotham_board.rb
ADDED
data/lib/wonderland.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module Wonderland
|
2
|
+
class ActiveSpace < Space
|
3
|
+
attribute :before_arrival_callbacks, Array[Proc], default: []
|
4
|
+
attribute :after_arrival_callbacks, Array[Proc], default: []
|
5
|
+
attribute :before_departure_callbacks, Array[Proc], default: []
|
6
|
+
attribute :after_departure_callbacks, Array[Proc], default: []
|
7
|
+
attribute :before_turn_callbacks, Array[Proc], default: []
|
8
|
+
attribute :after_turn_callbacks, Array[Proc], default: []
|
9
|
+
|
10
|
+
def remove_piece(obj)
|
11
|
+
before_departure_callbacks.each { |bd| bd.call(self, obj) }
|
12
|
+
r = super(obj)
|
13
|
+
after_departure_callbacks.each { |ad| ad.call(self, obj) }
|
14
|
+
r
|
15
|
+
end
|
16
|
+
|
17
|
+
def add_piece(obj)
|
18
|
+
before_arrival_callbacks.each { |ba| ba.call(self, obj) }
|
19
|
+
r = super(obj)
|
20
|
+
after_arrival_callbacks.each { |aa| aa.call(self, obj) }
|
21
|
+
r
|
22
|
+
end
|
23
|
+
|
24
|
+
def take_turn(turn, &blk)
|
25
|
+
before_turn_callbacks.each { |bt| bt.call(self, turn) }
|
26
|
+
yield(self, turn) if block_given?
|
27
|
+
after_turn_callbacks.each { |at| at.call(self, turn) }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'virtus'
|
2
|
+
|
3
|
+
require 'wonderland/grid'
|
4
|
+
require 'wonderland/space'
|
5
|
+
|
6
|
+
module Wonderland
|
7
|
+
class Board
|
8
|
+
extend Forwardable
|
9
|
+
include Virtus.model
|
10
|
+
|
11
|
+
attribute :spaces, Hash[Symbol => Space], default: {}
|
12
|
+
attribute :connections, Hash
|
13
|
+
attribute :grid, Grid, default: ->(*a) { Grid.new }
|
14
|
+
def_delegators :@grid, :can_move?, :connect
|
15
|
+
|
16
|
+
def initialize(*args)
|
17
|
+
super(*args)
|
18
|
+
init_connections if connections
|
19
|
+
end
|
20
|
+
|
21
|
+
def move_piece(component, from:, to:)
|
22
|
+
return false unless from && from.include?(component)
|
23
|
+
return false unless can_move?(from, to: to)
|
24
|
+
from.remove_piece(component) && to.add_piece(component)
|
25
|
+
end
|
26
|
+
|
27
|
+
def add_space(name, space = Space.new)
|
28
|
+
spaces[name] = space
|
29
|
+
end
|
30
|
+
|
31
|
+
def add_piece(piece, space)
|
32
|
+
spaces[space].add_piece(piece)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
def init_connections
|
37
|
+
connections.each_pair do |from, to_arr|
|
38
|
+
to_arr.each { |to| connect(from, to) }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'virtus'
|
2
|
+
module Wonderland
|
3
|
+
# This is a simple board that allows 1 or 2 way movement between spaces
|
4
|
+
# and assumes each move command will consist of a 1 space move. movement points
|
5
|
+
# expanded grids, hex and square grids, 3d space should be implemented
|
6
|
+
# separately
|
7
|
+
class Grid
|
8
|
+
include Virtus.model
|
9
|
+
|
10
|
+
attribute :neighbors, Hash, default: ->(*a) { Hash.new { |h, k| h[k] = [] } }
|
11
|
+
|
12
|
+
def initialize(*args)
|
13
|
+
super(*args)
|
14
|
+
neighbors.default_proc = ->(h, k) { h[k] = [] }
|
15
|
+
end
|
16
|
+
|
17
|
+
def can_move?(from, to:)
|
18
|
+
neighbors[from].include?(to)
|
19
|
+
end
|
20
|
+
|
21
|
+
def connect(from, to, reverse: true)
|
22
|
+
neighbors[from].push(to)
|
23
|
+
neighbors[to].push(from) if reverse
|
24
|
+
self
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'virtus'
|
2
|
+
|
3
|
+
module Wonderland
|
4
|
+
class Space
|
5
|
+
extend Forwardable
|
6
|
+
include Virtus.model
|
7
|
+
|
8
|
+
attribute :contents, Array, default: []
|
9
|
+
|
10
|
+
def_delegators :@contents, :include?, :delete, :<<, :push
|
11
|
+
|
12
|
+
def remove_piece(obj)
|
13
|
+
delete(obj)
|
14
|
+
end
|
15
|
+
|
16
|
+
def add_piece(obj)
|
17
|
+
contents.push obj
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'gotham_board'
|
3
|
+
describe GothamBoard do
|
4
|
+
let(:file_name) { 'etc/gotham_board.yml' }
|
5
|
+
subject { described_class.load_board(file_name) }
|
6
|
+
|
7
|
+
describe '#load_board(file)' do
|
8
|
+
it { is_expected.to be_a Wonderland::Board }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'contents' do
|
12
|
+
it { expect(subject.spaces.count).to eq 12 }
|
13
|
+
it { expect(subject.can_move?(:tower, to: :old_gotham)).to be_falsey }
|
14
|
+
it { expect(subject.can_move?(:tower, to: :parkside)).to be_truthy }
|
15
|
+
it { expect(subject.grid.neighbors.keys.count).to eq 12 }
|
16
|
+
end
|
17
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
4
|
+
# file to always be loaded, without a need to explicitly require it in any files.
|
5
|
+
#
|
6
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
7
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
8
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
9
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
10
|
+
# a separate helper file that requires the additional dependencies and performs
|
11
|
+
# the additional setup, and require it from the spec files that actually need it.
|
12
|
+
#
|
13
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
14
|
+
# users commonly want.
|
15
|
+
#
|
16
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
17
|
+
RSpec.configure do |config|
|
18
|
+
# rspec-expectations config goes here. You can use an alternate
|
19
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
20
|
+
# assertions if you prefer.
|
21
|
+
config.expect_with :rspec do |expectations|
|
22
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
23
|
+
# and `failure_message` of custom matchers include text for helper methods
|
24
|
+
# defined using `chain`, e.g.:
|
25
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
26
|
+
# # => "be bigger than 2 and smaller than 4"
|
27
|
+
# ...rather than:
|
28
|
+
# # => "be bigger than 2"
|
29
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
30
|
+
end
|
31
|
+
|
32
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
33
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
34
|
+
config.mock_with :rspec do |mocks|
|
35
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
36
|
+
# a real object. This is generally recommended, and will default to
|
37
|
+
# `true` in RSpec 4.
|
38
|
+
mocks.verify_partial_doubles = true
|
39
|
+
end
|
40
|
+
|
41
|
+
config.filter_run :focus
|
42
|
+
config.run_all_when_everything_filtered = true
|
43
|
+
|
44
|
+
|
45
|
+
# The settings below are suggested to provide a good initial experience
|
46
|
+
# with RSpec, but feel free to customize to your heart's content.
|
47
|
+
=begin
|
48
|
+
# These two settings work together to allow you to limit a spec run
|
49
|
+
# to individual examples or groups you care about by tagging them with
|
50
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
51
|
+
# get run.
|
52
|
+
|
53
|
+
# Limits the available syntax to the non-monkey patched syntax that is recommended.
|
54
|
+
# For more details, see:
|
55
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
56
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
57
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
58
|
+
config.disable_monkey_patching!
|
59
|
+
|
60
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
61
|
+
# be too noisy due to issues in dependencies.
|
62
|
+
config.warnings = true
|
63
|
+
|
64
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
65
|
+
# file, and it's useful to allow more verbose output when running an
|
66
|
+
# individual spec file.
|
67
|
+
if config.files_to_run.one?
|
68
|
+
# Use the documentation formatter for detailed output,
|
69
|
+
# unless a formatter has already been configured
|
70
|
+
# (e.g. via a command-line flag).
|
71
|
+
config.default_formatter = 'doc'
|
72
|
+
end
|
73
|
+
|
74
|
+
# Print the 10 slowest examples and example groups at the
|
75
|
+
# end of the spec run, to help surface which specs are running
|
76
|
+
# particularly slow.
|
77
|
+
config.profile_examples = 10
|
78
|
+
|
79
|
+
# Run specs in random order to surface order dependencies. If you find an
|
80
|
+
# order dependency and want to debug it, you can fix the order by providing
|
81
|
+
# the seed, which is printed after each run.
|
82
|
+
# --seed 1234
|
83
|
+
config.order = :random
|
84
|
+
|
85
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
86
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
87
|
+
# test failures related to randomization by passing the same `--seed` value
|
88
|
+
# as the one that triggered the failure.
|
89
|
+
Kernel.srand config.seed
|
90
|
+
=end
|
91
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'wonderland/active_space'
|
3
|
+
|
4
|
+
describe Wonderland::ActiveSpace do
|
5
|
+
subject { described_class.new }
|
6
|
+
it { expect(subject.after_arrival_callbacks).to eq [] }
|
7
|
+
it { expect(subject.before_arrival_callbacks).to eq [] }
|
8
|
+
it { expect(subject.after_departure_callbacks).to eq [] }
|
9
|
+
it { expect(subject.before_departure_callbacks).to eq [] }
|
10
|
+
it { expect(subject.after_turn_callbacks).to eq [] }
|
11
|
+
it { expect(subject.before_turn_callbacks).to eq [] }
|
12
|
+
|
13
|
+
describe 'callbacks' do
|
14
|
+
let(:canary) { double('canary') }
|
15
|
+
let(:parakeet) { double('parakeet') }
|
16
|
+
context 'arrival' do
|
17
|
+
context 'before' do
|
18
|
+
subject { described_class.new before_arrival_callbacks: [canary] }
|
19
|
+
it 'calls callback' do
|
20
|
+
expect(canary).to receive(:call).with(subject, :robin)
|
21
|
+
subject.add_piece(:robin)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
context 'after' do
|
25
|
+
subject { described_class.new after_arrival_callbacks: [parakeet] }
|
26
|
+
it 'calls callback' do
|
27
|
+
expect(parakeet).to receive(:call).with(subject, :robin)
|
28
|
+
subject.add_piece(:robin)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
context 'around' do
|
32
|
+
subject do
|
33
|
+
described_class.new before_arrival_callbacks: [canary],
|
34
|
+
after_arrival_callbacks: [parakeet]
|
35
|
+
end
|
36
|
+
it 'calls callback' do
|
37
|
+
expect(canary).to receive(:call).with(subject, :robin)
|
38
|
+
expect(parakeet).to receive(:call).with(subject, :robin)
|
39
|
+
subject.add_piece(:robin)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'departure' do
|
45
|
+
context 'before' do
|
46
|
+
subject { described_class.new before_departure_callbacks: [canary] }
|
47
|
+
it 'calls callback' do
|
48
|
+
expect(canary).to receive(:call).with(subject, :robin)
|
49
|
+
subject.remove_piece(:robin)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
context 'after' do
|
53
|
+
subject { described_class.new after_departure_callbacks: [parakeet] }
|
54
|
+
it 'calls callback' do
|
55
|
+
expect(parakeet).to receive(:call).with(subject, :robin)
|
56
|
+
subject.remove_piece(:robin)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
context 'around' do
|
60
|
+
subject do
|
61
|
+
described_class.new before_departure_callbacks: [canary],
|
62
|
+
after_departure_callbacks: [parakeet]
|
63
|
+
end
|
64
|
+
it 'calls callback' do
|
65
|
+
expect(canary).to receive(:call).with(subject, :robin)
|
66
|
+
expect(parakeet).to receive(:call).with(subject, :robin)
|
67
|
+
subject.remove_piece(:robin)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'take_turn' do
|
73
|
+
context 'before' do
|
74
|
+
subject { described_class.new before_turn_callbacks: [canary] }
|
75
|
+
it 'calls callback' do
|
76
|
+
expect(canary).to receive(:call).with(subject, :robin)
|
77
|
+
subject.take_turn(:robin)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
context 'after' do
|
81
|
+
subject { described_class.new after_turn_callbacks: [parakeet] }
|
82
|
+
it 'calls callback' do
|
83
|
+
expect(parakeet).to receive(:call).with(subject, :robin)
|
84
|
+
subject.take_turn(:robin)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
context 'around' do
|
88
|
+
subject do
|
89
|
+
described_class.new before_turn_callbacks: [canary],
|
90
|
+
after_turn_callbacks: [parakeet]
|
91
|
+
end
|
92
|
+
it 'calls callback' do
|
93
|
+
expect(canary).to receive(:call).with(subject, :robin)
|
94
|
+
expect(parakeet).to receive(:call).with(subject, :robin)
|
95
|
+
subject.take_turn(:robin)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
context 'yield' do
|
99
|
+
subject { described_class.new }
|
100
|
+
it 'calls callback' do
|
101
|
+
expect(canary).to receive(:call).with(subject, :robin)
|
102
|
+
|
103
|
+
subject.take_turn(:robin) { |space, turn| canary.call(space, turn) }
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'wonderland/board'
|
3
|
+
require 'wonderland/grid'
|
4
|
+
require 'wonderland/space'
|
5
|
+
|
6
|
+
describe Wonderland::Board do
|
7
|
+
subject { described_class.new }
|
8
|
+
it { expect(subject).to be_a described_class }
|
9
|
+
it { expect(subject.spaces).to eq({}) }
|
10
|
+
it { expect(subject.grid).to be_a Wonderland::Grid }
|
11
|
+
|
12
|
+
describe '.can_move?(from, to:)' do
|
13
|
+
let(:spaces) { [:nightwing, :robin] }
|
14
|
+
subject do
|
15
|
+
s = described_class.new(spaces: spaces)
|
16
|
+
s.grid.connect(:robin, :nightwing)
|
17
|
+
s.grid.connect(:nightwing, :batman)
|
18
|
+
s
|
19
|
+
end
|
20
|
+
|
21
|
+
it { expect(subject.can_move?(:robin, to: :batman)).to be_falsey }
|
22
|
+
it { expect(subject.can_move?(:robin, to: :nightwing)).to be_truthy }
|
23
|
+
it { expect(subject.can_move?(:nightwing, to: :batman)).to be_truthy }
|
24
|
+
|
25
|
+
context 'when passed nonexistant values' do
|
26
|
+
subject { described_class.new }
|
27
|
+
it { expect(subject.can_move?(:nightwing, to: :batman)).to be_falsey }
|
28
|
+
it { expect(subject.can_move?(:batgirl, to: :nightwing)).to be_falsey }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '.move_piece(component, from:, to:, &blk)' do
|
33
|
+
let(:source) { Wonderland::Space.new(contents: [:batman, :robin]) }
|
34
|
+
let(:target) { Wonderland::Space.new }
|
35
|
+
let(:other) { Wonderland::Space.new }
|
36
|
+
let(:spaces) { [source, target] }
|
37
|
+
|
38
|
+
subject do
|
39
|
+
s = described_class.new(spaces: spaces)
|
40
|
+
s.connect source, target
|
41
|
+
s
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should move piece from one space to another' do
|
45
|
+
subject.move_piece(:batman, from: source, to: target)
|
46
|
+
expect(source.contents).to eq [:robin]
|
47
|
+
expect(target.contents).to eq [:batman]
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'when passed bad values returns false' do
|
51
|
+
it { expect(subject.move_piece(:batgirl, from: source, to: target)).to be_falsey }
|
52
|
+
it { expect(subject.move_piece(:robin, from: other, to: target)).to be_falsey }
|
53
|
+
it { expect(subject.move_piece(:robin, from: source, to: nil)).to be_falsey }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'wonderland/grid'
|
3
|
+
|
4
|
+
describe Wonderland::Grid do
|
5
|
+
subject { described_class.new }
|
6
|
+
it { is_expected.to be_a described_class }
|
7
|
+
|
8
|
+
it { expect(subject).to have_attributes(neighbors: {}) }
|
9
|
+
|
10
|
+
describe '.connect(from, to, reverse: true)' do
|
11
|
+
subject do
|
12
|
+
s = described_class.new
|
13
|
+
s.connect(:robin, :batman)
|
14
|
+
s.connect(:batman, :batgirl)
|
15
|
+
s
|
16
|
+
end
|
17
|
+
|
18
|
+
it { expect(subject.neighbors).to eq({ robin: [:batman], batman: [:robin, :batgirl], batgirl: [:batman] }) }
|
19
|
+
it { expect(subject.can_move?(:robin, to: :batman)).to be_truthy }
|
20
|
+
it { expect(subject.can_move?(:batman, to: :robin)).to be_truthy }
|
21
|
+
it { expect(subject.can_move?(:batman, to: :batgirl)).to be_truthy }
|
22
|
+
it { expect(subject.can_move?(:batgirl, to: :batman)).to be_truthy }
|
23
|
+
it { expect(subject.can_move?(:robin, to: :batgirl)).to be_falsey }
|
24
|
+
|
25
|
+
context 'when reverse is false' do
|
26
|
+
subject do
|
27
|
+
s = described_class.new
|
28
|
+
s.connect(:robin, :batman, reverse: false)
|
29
|
+
s
|
30
|
+
end
|
31
|
+
|
32
|
+
it { expect(subject.neighbors).to eq({ robin: [:batman] }) }
|
33
|
+
it { expect(subject.can_move?(:robin, to: :batman)).to be_truthy }
|
34
|
+
it { expect(subject.can_move?(:batman, to: :robin)).to be_falsey }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'wonderland/space'
|
3
|
+
|
4
|
+
describe Wonderland::Space do
|
5
|
+
let(:contents) { [:batman, :robin] }
|
6
|
+
subject { described_class.new }
|
7
|
+
it { expect(subject.contents).to eq [] }
|
8
|
+
|
9
|
+
describe 'include?' do
|
10
|
+
subject { described_class.new(contents: contents) }
|
11
|
+
it { expect(subject.include?(:batman)).to be_truthy }
|
12
|
+
it { expect(subject.include?(:robin)).to be_truthy }
|
13
|
+
it { expect(subject.include?(:batgirl)).to be_falsey }
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '.remove_piece(obj)' do
|
17
|
+
subject { described_class.new(contents: contents) }
|
18
|
+
it { expect(subject.remove_piece(:batgirl)).to be_falsey }
|
19
|
+
it { expect(subject.remove_piece(:robin)).to eq :robin }
|
20
|
+
it { subject.remove_piece(:batman); expect(subject.contents).to eq [:robin] }
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '.add_piece(obj)' do
|
24
|
+
subject { described_class.new(contents: contents) }
|
25
|
+
it { subject.add_piece(:batgirl); expect(subject.contents).to eq [:batman, :robin, :batgirl] }
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
data/wonderland.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "wonderland"
|
7
|
+
spec.version = File.read('VERSION')
|
8
|
+
spec.authors = ["Scott M Parrish"]
|
9
|
+
spec.email = ["anithri@gmail.com"]
|
10
|
+
spec.summary = %q{Board Game Component - game maps and boards}
|
11
|
+
spec.description = %q{library to define board game maps with}
|
12
|
+
spec.homepage = "https://github.com/anithri/wonderland"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_runtime_dependency 'virtus', '~> 1.0.3'
|
21
|
+
spec.add_runtime_dependency 'facets', '~> 2.9.3'
|
22
|
+
spec.add_runtime_dependency 'PriorityQueue', '~> 0.1.2'
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.7.6'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.3.2'
|
26
|
+
spec.add_development_dependency 'thor', '~> 0.19.1'
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.1.0'
|
28
|
+
spec.add_development_dependency 'guard-rspec', '~> 4.3.1'
|
29
|
+
spec.add_development_dependency 'guard-bundler', '~> 2.0.0'
|
30
|
+
spec.add_development_dependency 'version', '~> 1.0.0'
|
31
|
+
spec.add_development_dependency 'fuubar', '~> 2.0.0'
|
32
|
+
spec.add_development_dependency 'pry'
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,250 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wonderland
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Scott M Parrish
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: virtus
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.0.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.0.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: facets
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.9.3
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.9.3
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: PriorityQueue
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.1.2
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.1.2
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.7.6
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.7.6
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 10.3.2
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 10.3.2
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: thor
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.19.1
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.19.1
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 3.1.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 3.1.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: guard-rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 4.3.1
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 4.3.1
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: guard-bundler
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 2.0.0
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 2.0.0
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: version
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 1.0.0
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 1.0.0
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: fuubar
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 2.0.0
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 2.0.0
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: pry
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
description: library to define board game maps with
|
182
|
+
email:
|
183
|
+
- anithri@gmail.com
|
184
|
+
executables: []
|
185
|
+
extensions: []
|
186
|
+
extra_rdoc_files: []
|
187
|
+
files:
|
188
|
+
- ".gitignore"
|
189
|
+
- ".idea/.name"
|
190
|
+
- ".idea/.rakeTasks"
|
191
|
+
- ".idea/encodings.xml"
|
192
|
+
- ".idea/misc.xml"
|
193
|
+
- ".idea/modules.xml"
|
194
|
+
- ".idea/scopes/scope_settings.xml"
|
195
|
+
- ".idea/vcs.xml"
|
196
|
+
- ".idea/wonderland.iml"
|
197
|
+
- ".rspec"
|
198
|
+
- ".travis.yml"
|
199
|
+
- Gemfile
|
200
|
+
- Guardfile
|
201
|
+
- LICENSE.txt
|
202
|
+
- README.md
|
203
|
+
- Rakefile
|
204
|
+
- Thorfile
|
205
|
+
- VERSION
|
206
|
+
- etc/gotham_board.yml
|
207
|
+
- lib/gotham_board.rb
|
208
|
+
- lib/wonderland.rb
|
209
|
+
- lib/wonderland/active_space.rb
|
210
|
+
- lib/wonderland/board.rb
|
211
|
+
- lib/wonderland/grid.rb
|
212
|
+
- lib/wonderland/space.rb
|
213
|
+
- spec/gotham_board_spec.rb
|
214
|
+
- spec/spec_helper.rb
|
215
|
+
- spec/wonderland/active_space_spec.rb
|
216
|
+
- spec/wonderland/board_spec.rb
|
217
|
+
- spec/wonderland/grid_spec.rb
|
218
|
+
- spec/wonderland/space_spec.rb
|
219
|
+
- wonderland.gemspec
|
220
|
+
homepage: https://github.com/anithri/wonderland
|
221
|
+
licenses:
|
222
|
+
- MIT
|
223
|
+
metadata: {}
|
224
|
+
post_install_message:
|
225
|
+
rdoc_options: []
|
226
|
+
require_paths:
|
227
|
+
- lib
|
228
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
229
|
+
requirements:
|
230
|
+
- - ">="
|
231
|
+
- !ruby/object:Gem::Version
|
232
|
+
version: '0'
|
233
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
234
|
+
requirements:
|
235
|
+
- - ">="
|
236
|
+
- !ruby/object:Gem::Version
|
237
|
+
version: '0'
|
238
|
+
requirements: []
|
239
|
+
rubyforge_project:
|
240
|
+
rubygems_version: 2.4.2
|
241
|
+
signing_key:
|
242
|
+
specification_version: 4
|
243
|
+
summary: Board Game Component - game maps and boards
|
244
|
+
test_files:
|
245
|
+
- spec/gotham_board_spec.rb
|
246
|
+
- spec/spec_helper.rb
|
247
|
+
- spec/wonderland/active_space_spec.rb
|
248
|
+
- spec/wonderland/board_spec.rb
|
249
|
+
- spec/wonderland/grid_spec.rb
|
250
|
+
- spec/wonderland/space_spec.rb
|