twisty_puzzles 0.0.1 → 0.0.2
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/CHANGELOG.md +9 -1
- data/lib/twisty_puzzles.rb +37 -0
- data/lib/twisty_puzzles/abstract_direction.rb +38 -39
- data/lib/twisty_puzzles/abstract_move_parser.rb +32 -33
- data/lib/twisty_puzzles/algorithm.rb +112 -113
- data/lib/twisty_puzzles/algorithm_transformation.rb +19 -21
- data/lib/twisty_puzzles/axis_face_and_direction_move.rb +55 -56
- data/lib/twisty_puzzles/cancellation_helper.rb +124 -125
- data/lib/twisty_puzzles/commutator.rb +79 -80
- data/lib/twisty_puzzles/compiled_algorithm.rb +31 -32
- data/lib/twisty_puzzles/compiled_cube_algorithm.rb +49 -50
- data/lib/twisty_puzzles/compiled_skewb_algorithm.rb +18 -19
- data/lib/twisty_puzzles/coordinate.rb +245 -246
- data/lib/twisty_puzzles/cube.rb +494 -495
- data/lib/twisty_puzzles/cube_constants.rb +40 -41
- data/lib/twisty_puzzles/cube_direction.rb +15 -18
- data/lib/twisty_puzzles/cube_move.rb +289 -290
- data/lib/twisty_puzzles/cube_move_parser.rb +75 -76
- data/lib/twisty_puzzles/cube_print_helper.rb +132 -133
- data/lib/twisty_puzzles/cube_state.rb +80 -81
- data/lib/twisty_puzzles/move_type_creator.rb +17 -18
- data/lib/twisty_puzzles/parser.rb +176 -179
- data/lib/twisty_puzzles/part_cycle_factory.rb +39 -42
- data/lib/twisty_puzzles/puzzle.rb +16 -17
- data/lib/twisty_puzzles/reversible_applyable.rb +24 -25
- data/lib/twisty_puzzles/rotation.rb +74 -75
- data/lib/twisty_puzzles/skewb_direction.rb +14 -15
- data/lib/twisty_puzzles/skewb_move.rb +48 -49
- data/lib/twisty_puzzles/skewb_move_parser.rb +50 -51
- data/lib/twisty_puzzles/skewb_notation.rb +115 -118
- data/lib/twisty_puzzles/skewb_state.rb +120 -121
- data/lib/twisty_puzzles/state_helper.rb +20 -21
- data/lib/twisty_puzzles/sticker_cycle.rb +43 -44
- data/lib/twisty_puzzles/utils.rb +3 -0
- data/lib/twisty_puzzles/version.rb +3 -1
- metadata +3 -3
@@ -3,30 +3,29 @@
|
|
3
3
|
require 'twisty_puzzles/abstract_direction'
|
4
4
|
|
5
5
|
module TwistyPuzzles
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
self[cycle[i]] = self[cycle[i - 1]]
|
14
|
-
end
|
15
|
-
self[cycle[0]] = last_sticker
|
6
|
+
# Common utilities for different puzzle states.
|
7
|
+
# TODO: Remove
|
8
|
+
module StateHelper
|
9
|
+
def apply_sticker_cycle(cycle)
|
10
|
+
last_sticker = self[cycle[-1]]
|
11
|
+
(cycle.length - 1).downto(1) do |i|
|
12
|
+
self[cycle[i]] = self[cycle[i - 1]]
|
16
13
|
end
|
14
|
+
self[cycle[0]] = last_sticker
|
15
|
+
end
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
def apply_4sticker_cycle(cycle, direction)
|
18
|
+
raise ArgumentError unless cycle.length == 4
|
19
|
+
raise TypeError unless direction.is_a?(AbstractDirection)
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
21
|
+
if direction.double_move?
|
22
|
+
apply_sticker_cycle([cycle[0], cycle[2]])
|
23
|
+
apply_sticker_cycle([cycle[1], cycle[3]])
|
24
|
+
else
|
25
|
+
# Note that we cannot do reverse! because the values are cached.
|
26
|
+
actual_cycle = direction.value == 3 ? cycle.reverse : cycle
|
27
|
+
apply_sticker_cycle(actual_cycle)
|
30
28
|
end
|
31
29
|
end
|
30
|
+
end
|
32
31
|
end
|
@@ -6,65 +6,64 @@ require 'twisty_puzzles/cube_state'
|
|
6
6
|
require 'twisty_puzzles/reversible_applyable'
|
7
7
|
|
8
8
|
module TwistyPuzzles
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
include ReversibleApplyable
|
13
|
-
|
14
|
-
def initialize(cube_size, sticker_cycle)
|
15
|
-
@cube_size = cube_size
|
16
|
-
@sticker_cycle = sticker_cycle
|
17
|
-
end
|
9
|
+
# A sticker cycle that can be applied to a cube state.
|
10
|
+
class StickerCycle
|
11
|
+
include ReversibleApplyable
|
18
12
|
|
19
|
-
|
13
|
+
def initialize(cube_size, sticker_cycle)
|
14
|
+
@cube_size = cube_size
|
15
|
+
@sticker_cycle = sticker_cycle
|
16
|
+
end
|
20
17
|
|
21
|
-
|
22
|
-
raise TypeError unless cube_state.is_a?(CubeState)
|
23
|
-
raise ArgumentError unless cube_state.n == @cube_size
|
18
|
+
attr_reader :cube_size, :sticker_cycle
|
24
19
|
|
25
|
-
|
26
|
-
|
20
|
+
def apply_to(cube_state)
|
21
|
+
raise TypeError unless cube_state.is_a?(CubeState)
|
22
|
+
raise ArgumentError unless cube_state.n == @cube_size
|
27
23
|
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
cube_state.apply_sticker_cycle(@sticker_cycle) if @sticker_cycle.length >= 2
|
25
|
+
end
|
26
|
+
|
27
|
+
def inverse
|
28
|
+
StickerCycle.new(@cube_size, @sticker_cycle.reverse)
|
31
29
|
end
|
30
|
+
end
|
32
31
|
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
# A set of disjoint sticker cycles that can be applied to a cube state together
|
33
|
+
class StickerCycles
|
34
|
+
include ReversibleApplyable
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
def initialize(cube_size, sticker_cycles)
|
37
|
+
affected_set = Set[]
|
38
|
+
sticker_cycles.each do |c|
|
39
|
+
raise TypeError unless c.is_a?(StickerCycle)
|
41
40
|
|
42
|
-
|
43
|
-
|
44
|
-
end
|
41
|
+
c.sticker_cycle.each do |s|
|
42
|
+
raise ArgumentError unless affected_set.add?(s)
|
45
43
|
end
|
46
|
-
@cube_size = cube_size
|
47
|
-
@sticker_cycles = sticker_cycles
|
48
44
|
end
|
45
|
+
@cube_size = cube_size
|
46
|
+
@sticker_cycles = sticker_cycles
|
47
|
+
end
|
49
48
|
|
50
|
-
|
49
|
+
attr_reader :cube_size, :sticker_cycles
|
51
50
|
|
52
|
-
|
53
|
-
|
54
|
-
|
51
|
+
def apply_to(cube_state)
|
52
|
+
raise TypeError unless cube_state.is_a?(CubeState)
|
53
|
+
raise ArgumentError unless cube_state.n == @cube_size
|
55
54
|
|
56
|
-
|
57
|
-
|
55
|
+
@sticker_cycles.each { |c| c.apply_to(cube_state) }
|
56
|
+
end
|
58
57
|
|
59
|
-
|
60
|
-
|
61
|
-
|
58
|
+
def +(other)
|
59
|
+
raise TypeError unless other.is_a?(StickerCycles)
|
60
|
+
raise ArgumentError unless @cube_size == other.cube_size
|
62
61
|
|
63
|
-
|
64
|
-
|
62
|
+
StickerCycles.new(@cube_size, @sticker_cycles + other.sticker_cycles)
|
63
|
+
end
|
65
64
|
|
66
|
-
|
67
|
-
|
68
|
-
end
|
65
|
+
def inverse
|
66
|
+
StickerCycles.new(@cube_size, @sticker_cycles.map(&:inverse))
|
69
67
|
end
|
68
|
+
end
|
70
69
|
end
|
data/lib/twisty_puzzles/utils.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twisty_puzzles
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bernhard F. Brodowsky
|
@@ -123,7 +123,7 @@ dependencies:
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
|
-
name: rubocop-
|
126
|
+
name: rubocop-performance
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - ">="
|
@@ -137,7 +137,7 @@ dependencies:
|
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
|
-
name: rubocop-
|
140
|
+
name: rubocop-rake
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
143
|
- - ">="
|