scrambler 0.0.2 → 0.0.3
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.
- data/Gemfile +3 -0
- data/lib/scrambler/pyraminx.rb +22 -0
- data/lib/scrambler/three_by_three.rb +13 -0
- data/lib/scrambler/version.rb +3 -0
- data/spec/scrambler/pyraminx_spec.rb +22 -0
- data/spec/scrambler/three_by_three_spec.rb +19 -0
- data/spec/spec_helper.rb +4 -0
- metadata +8 -1
data/Gemfile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Scrambler
|
2
|
+
class Pyraminx
|
3
|
+
def scramble(length = 25)
|
4
|
+
turns = %w(U L R B)
|
5
|
+
variants = ['', "'"]
|
6
|
+
|
7
|
+
tip_turns = turns.map &:downcase
|
8
|
+
tip_length = rand(3) + 1
|
9
|
+
scramble = (1..tip_length).map do
|
10
|
+
tip_turns.delete(tip_turns.sample) + variants.sample
|
11
|
+
end
|
12
|
+
|
13
|
+
axis = rand turns.size
|
14
|
+
scramble += ((tip_length + 1)..length).map do
|
15
|
+
axis = (axis + rand(turns.size - 1) + 1) % turns.size
|
16
|
+
turns[axis] + variants.sample
|
17
|
+
end
|
18
|
+
|
19
|
+
scramble.join(" ")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Scrambler
|
2
|
+
class ThreeByThree
|
3
|
+
def scramble(length = 25)
|
4
|
+
turns = [%w{R L}, %w{F B}, %w{D U}]
|
5
|
+
variants = ['', "'", '2']
|
6
|
+
axis = rand turns.size
|
7
|
+
(1..length).map do
|
8
|
+
axis = (axis + rand(turns.size - 1) + 1) % turns.size
|
9
|
+
turns[axis].sample + variants.sample
|
10
|
+
end.join(' ')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Scrambler::Pyraminx do
|
4
|
+
let(:valid_tip_turns) { %w(l l' r r' u u' b b') }
|
5
|
+
let(:valid_turns) { %w(l l' r r' u u' b b' L L' R R' U U' B B') }
|
6
|
+
|
7
|
+
it "should contain only valid turns" do
|
8
|
+
subject.scramble.split(" ").each do |turn|
|
9
|
+
valid_turns.should include(turn)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should not return the same results every time" do
|
14
|
+
subject.scramble.should_not == subject.scramble
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should return a 10 move scramble" do
|
18
|
+
5.times do
|
19
|
+
subject.scramble(10).split(" ").should have(10).elements
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Scrambler::ThreeByThree, "scrambling length" do
|
4
|
+
let(:valid_turns) { %w(L L' L2 R R' R2 U U' U2 B B' B2 F F' F2 D D' D2) }
|
5
|
+
|
6
|
+
it "should default to a 25 move scramble" do
|
7
|
+
subject.scramble.split(" ").should have(25).elements
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should return a 10 move scramble" do
|
11
|
+
subject.scramble(10).split(" ").should have(10).elements
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should contain only valid turns" do
|
15
|
+
subject.scramble.split(" ").each do |turn|
|
16
|
+
valid_turns.should include(turn)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: scrambler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Tim Habermaas
|
@@ -32,7 +32,14 @@ extensions: []
|
|
32
32
|
extra_rdoc_files: []
|
33
33
|
|
34
34
|
files:
|
35
|
+
- lib/scrambler/pyraminx.rb
|
36
|
+
- lib/scrambler/three_by_three.rb
|
37
|
+
- lib/scrambler/version.rb
|
35
38
|
- lib/scrambler.rb
|
39
|
+
- spec/scrambler/pyraminx_spec.rb
|
40
|
+
- spec/scrambler/three_by_three_spec.rb
|
41
|
+
- spec/spec_helper.rb
|
42
|
+
- Gemfile
|
36
43
|
homepage: https://github.com/timhabermaas/scrambler
|
37
44
|
licenses: []
|
38
45
|
|