swissper 0.1.0 → 0.2.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/.gitignore +2 -0
- data/README.md +24 -0
- data/lib/swissper/bye.rb +4 -0
- data/lib/swissper/version.rb +1 -1
- data/lib/swissper.rb +9 -2
- data/swissper-0.1.0.gem +0 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 472c0070be8d6f75e08bdacb6b93886408bda5fd
|
4
|
+
data.tar.gz: be5dd1b4d7c781faa1ba395b35a65b5d982e0e05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de53e20408c56dbe56d59e2d1b8a450bd76c0815f02d141869b705ded29f5f58fa26a8d80b3cc2e341debeeaebac730b2c455aab7fda1323794acb4931ddf564
|
7
|
+
data.tar.gz: 52424d4134fdeaa160d7797cbde272b7033ed2bb9461206d1c525573069534af0459b2ccb896b40b9e45669d3b95557a090bc3f0eebc2ab7792a78595ec0fef3
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -19,6 +19,7 @@ Or install it yourself as:
|
|
19
19
|
$ gem install swissper
|
20
20
|
|
21
21
|
## Usage
|
22
|
+
|
22
23
|
Use `Swissper.pair(players, options)` where `players` is an array of objects, and `options` is an optional hash of options.
|
23
24
|
|
24
25
|
The `player` objects you pass can be any type of object you like, so long as there are no duplicates. There is a simple `Swissper::Player` class available for ease of use.
|
@@ -92,6 +93,29 @@ Swissper.pair(players, exclude_key: :previous_opponents)
|
|
92
93
|
# Player objects should respond to `previous_opponents`
|
93
94
|
```
|
94
95
|
|
96
|
+
## Byes
|
97
|
+
|
98
|
+
If your array of players contains an odd number, one player will be paired with the `Swissper::Bye` class.
|
99
|
+
|
100
|
+
You can prevent players from receiving byes (e.g. if they've already received one) by passing `Swissper::Bye` in the `exclude` parameter of any player.
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
snap = Swissper::Player.new
|
104
|
+
crackle = Swissper::Player.new
|
105
|
+
pop = Swissper::Player.new
|
106
|
+
|
107
|
+
snap.exclude = [Swissper::Bye]
|
108
|
+
crackle.exclude = [Swissper::Bye]
|
109
|
+
|
110
|
+
Swissper.pair([snap, crackle, pop])
|
111
|
+
# [
|
112
|
+
# [Swissper::Bye, #<Swissper::Player:0x007fb2f99cb838 @delta=0, @exclude=[]>],
|
113
|
+
# [#<Swissper::Player:0x007fb2f9accac0 @delta=0, @exclude=[Swissper::Bye]>, #<Swissper::Player:0x007fb2f91a8f98 @delta=0, @exclude=[Swissper::Bye]>]
|
114
|
+
# ]
|
115
|
+
```
|
116
|
+
|
117
|
+
Please don't manually pass in `Swissper::Bye` in your array of players, passing in an odd-length array is the correct way to use byes.
|
118
|
+
|
95
119
|
## Development
|
96
120
|
|
97
121
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/swissper/bye.rb
ADDED
data/lib/swissper/version.rb
CHANGED
data/lib/swissper.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'swissper/version'
|
2
2
|
require 'swissper/player'
|
3
|
+
require 'swissper/bye'
|
3
4
|
require 'graph_matching'
|
4
5
|
|
5
6
|
module Swissper
|
@@ -14,7 +15,7 @@ module Swissper
|
|
14
15
|
end
|
15
16
|
|
16
17
|
def pair(player_data)
|
17
|
-
@
|
18
|
+
@player_data = player_data
|
18
19
|
graph.maximum_weighted_matching(true).edges.map do |pairing|
|
19
20
|
[players[pairing[0]], players[pairing[1]]]
|
20
21
|
end
|
@@ -22,7 +23,7 @@ module Swissper
|
|
22
23
|
|
23
24
|
private
|
24
25
|
|
25
|
-
attr_reader :delta_key, :exclude_key
|
26
|
+
attr_reader :delta_key, :exclude_key
|
26
27
|
|
27
28
|
def graph
|
28
29
|
edges = [].tap do |e|
|
@@ -58,5 +59,11 @@ module Swissper
|
|
58
59
|
|
59
60
|
[]
|
60
61
|
end
|
62
|
+
|
63
|
+
def players
|
64
|
+
@players ||= @player_data.clone.tap do |data|
|
65
|
+
data << Swissper::Bye unless data.length.even?
|
66
|
+
end.shuffle
|
67
|
+
end
|
61
68
|
end
|
62
69
|
end
|
data/swissper-0.1.0.gem
ADDED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swissper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John O'Brien
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graph_matching
|
@@ -97,8 +97,10 @@ files:
|
|
97
97
|
- bin/console
|
98
98
|
- bin/setup
|
99
99
|
- lib/swissper.rb
|
100
|
+
- lib/swissper/bye.rb
|
100
101
|
- lib/swissper/player.rb
|
101
102
|
- lib/swissper/version.rb
|
103
|
+
- swissper-0.1.0.gem
|
102
104
|
- swissper.gemspec
|
103
105
|
homepage: https://github.com/muyjohno/swissper
|
104
106
|
licenses:
|
@@ -120,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
122
|
version: '0'
|
121
123
|
requirements: []
|
122
124
|
rubyforge_project:
|
123
|
-
rubygems_version: 2.
|
125
|
+
rubygems_version: 2.6.10
|
124
126
|
signing_key:
|
125
127
|
specification_version: 4
|
126
128
|
summary: A Ruby gem for pairing Swiss tournaments
|