twisty_puzzles 0.0.1 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -1
- data/README.md +6 -1
- data/ext/twisty_puzzles/native/cube_algorithm.c +267 -0
- data/ext/twisty_puzzles/native/cube_algorithm.h +5 -0
- data/ext/twisty_puzzles/native/cube_average.c +184 -0
- data/ext/twisty_puzzles/native/cube_average.h +5 -0
- data/ext/twisty_puzzles/native/cube_coordinate.c +207 -0
- data/ext/twisty_puzzles/native/cube_coordinate.h +34 -0
- data/ext/twisty_puzzles/native/cube_state.c +264 -0
- data/ext/twisty_puzzles/native/cube_state.h +31 -0
- data/ext/twisty_puzzles/native/extconf.rb +1 -1
- data/ext/twisty_puzzles/native/face_symbols.c +67 -0
- data/ext/twisty_puzzles/native/face_symbols.h +34 -0
- data/ext/twisty_puzzles/native/native.c +28 -0
- data/ext/twisty_puzzles/native/skewb_algorithm.c +331 -0
- data/ext/twisty_puzzles/native/skewb_algorithm.h +5 -0
- data/ext/twisty_puzzles/native/skewb_coordinate.c +237 -0
- data/ext/twisty_puzzles/native/skewb_coordinate.h +36 -0
- data/ext/twisty_puzzles/native/skewb_layer_fingerprint.c +271 -0
- data/ext/twisty_puzzles/native/skewb_layer_fingerprint.h +5 -0
- data/ext/twisty_puzzles/native/skewb_state.c +214 -0
- data/ext/twisty_puzzles/native/skewb_state.h +23 -0
- data/ext/twisty_puzzles/native/utils.c +76 -0
- data/ext/twisty_puzzles/native/utils.h +31 -0
- data/lib/twisty_puzzles.rb +38 -0
- data/lib/twisty_puzzles/abstract_direction.rb +38 -39
- data/lib/twisty_puzzles/abstract_move.rb +1 -2
- 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 +56 -56
- data/lib/twisty_puzzles/cancellation_helper.rb +124 -125
- data/lib/twisty_puzzles/color_scheme.rb +1 -1
- data/lib/twisty_puzzles/commutator.rb +82 -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 +243 -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 +285 -290
- data/lib/twisty_puzzles/cube_move_parser.rb +75 -76
- data/lib/twisty_puzzles/cube_print_helper.rb +133 -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 +76 -75
- data/lib/twisty_puzzles/skewb_direction.rb +14 -15
- data/lib/twisty_puzzles/skewb_move.rb +49 -49
- data/lib/twisty_puzzles/skewb_move_parser.rb +51 -51
- data/lib/twisty_puzzles/skewb_notation.rb +121 -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 +30 -10
@@ -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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bernhard F. Brodowsky
|
@@ -112,18 +112,18 @@ dependencies:
|
|
112
112
|
name: rubocop
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- - "
|
115
|
+
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
117
|
+
version: '1.7'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- - "
|
122
|
+
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
124
|
+
version: '1.7'
|
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
|
- - ">="
|
@@ -176,7 +176,28 @@ files:
|
|
176
176
|
- CODE_OF_CONDUCT.md
|
177
177
|
- LICENSE
|
178
178
|
- README.md
|
179
|
+
- ext/twisty_puzzles/native/cube_algorithm.c
|
180
|
+
- ext/twisty_puzzles/native/cube_algorithm.h
|
181
|
+
- ext/twisty_puzzles/native/cube_average.c
|
182
|
+
- ext/twisty_puzzles/native/cube_average.h
|
183
|
+
- ext/twisty_puzzles/native/cube_coordinate.c
|
184
|
+
- ext/twisty_puzzles/native/cube_coordinate.h
|
185
|
+
- ext/twisty_puzzles/native/cube_state.c
|
186
|
+
- ext/twisty_puzzles/native/cube_state.h
|
179
187
|
- ext/twisty_puzzles/native/extconf.rb
|
188
|
+
- ext/twisty_puzzles/native/face_symbols.c
|
189
|
+
- ext/twisty_puzzles/native/face_symbols.h
|
190
|
+
- ext/twisty_puzzles/native/native.c
|
191
|
+
- ext/twisty_puzzles/native/skewb_algorithm.c
|
192
|
+
- ext/twisty_puzzles/native/skewb_algorithm.h
|
193
|
+
- ext/twisty_puzzles/native/skewb_coordinate.c
|
194
|
+
- ext/twisty_puzzles/native/skewb_coordinate.h
|
195
|
+
- ext/twisty_puzzles/native/skewb_layer_fingerprint.c
|
196
|
+
- ext/twisty_puzzles/native/skewb_layer_fingerprint.h
|
197
|
+
- ext/twisty_puzzles/native/skewb_state.c
|
198
|
+
- ext/twisty_puzzles/native/skewb_state.h
|
199
|
+
- ext/twisty_puzzles/native/utils.c
|
200
|
+
- ext/twisty_puzzles/native/utils.h
|
180
201
|
- lib/twisty_puzzles.rb
|
181
202
|
- lib/twisty_puzzles/abstract_direction.rb
|
182
203
|
- lib/twisty_puzzles/abstract_move.rb
|
@@ -232,15 +253,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
232
253
|
requirements:
|
233
254
|
- - ">="
|
234
255
|
- !ruby/object:Gem::Version
|
235
|
-
version: 2.
|
256
|
+
version: 2.6.0
|
236
257
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
237
258
|
requirements:
|
238
259
|
- - ">="
|
239
260
|
- !ruby/object:Gem::Version
|
240
261
|
version: '0'
|
241
262
|
requirements: []
|
242
|
-
|
243
|
-
rubygems_version: 2.7.6.2
|
263
|
+
rubygems_version: 3.1.2
|
244
264
|
signing_key:
|
245
265
|
specification_version: 4
|
246
266
|
summary: Gem for my cube_trainer rails app. Some things are better left in a separate
|