scrambler 0.0.3 → 0.0.4
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/lib/scrambler.rb +1 -1
- data/lib/scrambler/cube.rb +54 -0
- data/lib/scrambler/version.rb +1 -1
- data/spec/scrambler/five_by_five_spec.rb +20 -0
- data/spec/scrambler/four_by_four_spec.rb +20 -0
- data/spec/scrambler/seven_by_seven_spec.rb +19 -0
- data/spec/scrambler/six_by_six_spec.rb +19 -0
- data/spec/scrambler/three_by_three_spec.rb +1 -1
- data/spec/scrambler/two_by_two_spec.rb +19 -0
- metadata +8 -3
- data/lib/scrambler/three_by_three.rb +0 -13
data/lib/scrambler.rb
CHANGED
@@ -0,0 +1,54 @@
|
|
1
|
+
module Scrambler
|
2
|
+
class Cube
|
3
|
+
def scramble(turns, length)
|
4
|
+
variants = ['', "'", '2']
|
5
|
+
axis = rand turns.size
|
6
|
+
(1..length).map do
|
7
|
+
axis = (axis + rand(turns.size - 1) + 1) % turns.size
|
8
|
+
turns[axis].sample + variants.sample
|
9
|
+
end.join(' ')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class TwoByTwo < Cube
|
14
|
+
def scramble(length = 20)
|
15
|
+
turns = [%w{R L}, %w{F B}, %w{D U}]
|
16
|
+
super turns, length
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class ThreeByThree < Cube
|
21
|
+
def scramble(length = 25)
|
22
|
+
turns = [%w{R L}, %w{F B}, %w{D U}]
|
23
|
+
super turns, length
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class FourByFour < Cube
|
28
|
+
def scramble(length = 40)
|
29
|
+
turns = [%w{R L Rw Lw}, %w{F B Fw Bw}, %w{D U Dw Uw}]
|
30
|
+
super turns, length
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class FiveByFive < Cube
|
35
|
+
def scramble(length = 60)
|
36
|
+
turns = [%w{R L Rw Lw}, %w{F B Fw Bw}, %w{D U Dw Uw}]
|
37
|
+
super turns, length
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class SixBySix < Cube
|
42
|
+
def scramble(length = 80)
|
43
|
+
turns = [%w(R L 2R 2L 3R 3L), %w(F B 2F 2B 3F 3B), %w(D U 2D 2U 3D 3U)]
|
44
|
+
super turns, length
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class SevenBySeven < Cube
|
49
|
+
def scramble(length = 100)
|
50
|
+
turns = [%w(R L 2R 2L 3R 3L), %w(F B 2F 2B 3F 3B), %w(D U 2D 2U 3D 3U)]
|
51
|
+
super turns, length
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/scrambler/version.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Scrambler::FiveByFive do
|
4
|
+
let(:valid_turns) { %w(L L' L2 R R' R2 U U' U2 D D' D2 B B' B2 F F' F2
|
5
|
+
Lw Lw' Lw2 Rw Rw' Rw2 Uw Uw' Uw2 Dw Dw' Dw2 Bw Bw' Bw2 Fw Fw' Fw2) }
|
6
|
+
|
7
|
+
it "should default to a 60 move scramble" do
|
8
|
+
subject.scramble.split(" ").should have(60).elements
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should return a 10 move scramble" do
|
12
|
+
subject.scramble(10).split(" ").should have(10).elements
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should contain only valid turns" do
|
16
|
+
subject.scramble.split(" ").each do |turn|
|
17
|
+
valid_turns.should include(turn)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Scrambler::FourByFour do
|
4
|
+
let(:valid_turns) { %w(L L' L2 R R' R2 U U' U2 D D' D2 B B' B2 F F' F2
|
5
|
+
Lw Lw' Lw2 Rw Rw' Rw2 Uw Uw' Uw2 Dw Dw' Dw2 Bw Bw' Bw2 Fw Fw' Fw2) }
|
6
|
+
|
7
|
+
it "should default to a 40 move scramble" do
|
8
|
+
subject.scramble.split(" ").should have(40).elements
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should return a 10 move scramble" do
|
12
|
+
subject.scramble(10).split(" ").should have(10).elements
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should contain only valid turns" do
|
16
|
+
subject.scramble.split(" ").each do |turn|
|
17
|
+
valid_turns.should include(turn)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Scrambler::SevenBySeven do
|
4
|
+
let(:valid_turns) { ["", "2", "3"].product(%w(R L U D F B)).map { |l, t| l + t }.product(["", "'", "2"]).map{ |t, m| t + m } }
|
5
|
+
|
6
|
+
it "should default to a 100 move scramble" do
|
7
|
+
subject.scramble.split(" ").should have(100).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
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Scrambler::SixBySix do
|
4
|
+
let(:valid_turns) { ["", "2", "3"].product(%w(R L U D F B)).map { |l, t| l + t }.product(["", "'", "2"]).map{ |t, m| t + m } }
|
5
|
+
|
6
|
+
it "should default to a 80 move scramble" do
|
7
|
+
subject.scramble.split(" ").should have(80).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
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Scrambler::TwoByTwo 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 20 move scramble" do
|
7
|
+
subject.scramble.split(" ").should have(20).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
|
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.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Tim Habermaas
|
@@ -23,7 +23,7 @@ dependencies:
|
|
23
23
|
version: 2.6.0
|
24
24
|
type: :development
|
25
25
|
version_requirements: *id001
|
26
|
-
description:
|
26
|
+
description: Scrambler provides scrambles for all WCA puzzles
|
27
27
|
email: t.habermaas@gmail.com
|
28
28
|
executables: []
|
29
29
|
|
@@ -32,12 +32,17 @@ extensions: []
|
|
32
32
|
extra_rdoc_files: []
|
33
33
|
|
34
34
|
files:
|
35
|
+
- lib/scrambler/cube.rb
|
35
36
|
- lib/scrambler/pyraminx.rb
|
36
|
-
- lib/scrambler/three_by_three.rb
|
37
37
|
- lib/scrambler/version.rb
|
38
38
|
- lib/scrambler.rb
|
39
|
+
- spec/scrambler/five_by_five_spec.rb
|
40
|
+
- spec/scrambler/four_by_four_spec.rb
|
39
41
|
- spec/scrambler/pyraminx_spec.rb
|
42
|
+
- spec/scrambler/seven_by_seven_spec.rb
|
43
|
+
- spec/scrambler/six_by_six_spec.rb
|
40
44
|
- spec/scrambler/three_by_three_spec.rb
|
45
|
+
- spec/scrambler/two_by_two_spec.rb
|
41
46
|
- spec/spec_helper.rb
|
42
47
|
- Gemfile
|
43
48
|
homepage: https://github.com/timhabermaas/scrambler
|
@@ -1,13 +0,0 @@
|
|
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
|