twisty_puzzles 0.0.5 → 0.0.10
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/README.md +6 -1
- data/ext/twisty_puzzles/native/cube_algorithm.c +10 -18
- data/ext/twisty_puzzles/native/cube_average.c +2 -2
- data/ext/twisty_puzzles/native/cube_coordinate.c +16 -15
- data/ext/twisty_puzzles/native/cube_coordinate.h +7 -7
- data/ext/twisty_puzzles/native/cube_state.c +23 -33
- data/ext/twisty_puzzles/native/cube_state.h +2 -2
- data/ext/twisty_puzzles/native/face_symbols.h +2 -2
- data/ext/twisty_puzzles/native/skewb_algorithm.c +3 -12
- data/ext/twisty_puzzles/native/skewb_coordinate.c +0 -11
- data/ext/twisty_puzzles/native/skewb_layer_fingerprint.c +3 -2
- data/ext/twisty_puzzles/native/skewb_state.c +0 -2
- data/ext/twisty_puzzles/native/utils.c +7 -1
- data/ext/twisty_puzzles/native/utils.h +2 -3
- data/lib/twisty_puzzles/abstract_move.rb +5 -2
- data/lib/twisty_puzzles/abstract_move_parser.rb +3 -3
- data/lib/twisty_puzzles/algorithm.rb +1 -1
- data/lib/twisty_puzzles/algorithm_transformation.rb +27 -19
- data/lib/twisty_puzzles/axis_face_and_direction_move.rb +4 -1
- data/lib/twisty_puzzles/cancellation_helper.rb +1 -1
- data/lib/twisty_puzzles/color_scheme.rb +8 -6
- data/lib/twisty_puzzles/commutator.rb +7 -0
- data/lib/twisty_puzzles/compiled_algorithm.rb +4 -4
- data/lib/twisty_puzzles/coordinate.rb +4 -6
- data/lib/twisty_puzzles/cube.rb +19 -23
- data/lib/twisty_puzzles/cube_move.rb +0 -4
- data/lib/twisty_puzzles/cube_move_parser.rb +23 -23
- data/lib/twisty_puzzles/cube_print_helper.rb +4 -3
- data/lib/twisty_puzzles/cube_state.rb +10 -0
- data/lib/twisty_puzzles/parser.rb +3 -3
- data/lib/twisty_puzzles/rotation.rb +8 -4
- data/lib/twisty_puzzles/skewb_move.rb +1 -0
- data/lib/twisty_puzzles/skewb_move_parser.rb +1 -0
- data/lib/twisty_puzzles/skewb_notation.rb +7 -1
- data/lib/twisty_puzzles/skewb_state.rb +6 -4
- data/lib/twisty_puzzles/version.rb +1 -1
- metadata +11 -12
@@ -139,8 +139,6 @@ module TwistyPuzzles
|
|
139
139
|
end
|
140
140
|
end
|
141
141
|
|
142
|
-
# rubocop:disable Metrics/PerceivedComplexity
|
143
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
144
142
|
def prepend_fat_move(other, cube_size)
|
145
143
|
if same_fat_block?(other)
|
146
144
|
merge_with_same_fat_block(other)
|
@@ -156,8 +154,6 @@ module TwistyPuzzles
|
|
156
154
|
Algorithm.move(other.inner_fat_mslice_move(cube_size))
|
157
155
|
end
|
158
156
|
end
|
159
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
160
|
-
# rubocop:enable Metrics/PerceivedComplexity
|
161
157
|
|
162
158
|
def prepend_slice_move(other, cube_size)
|
163
159
|
return unless same_axis?(other)
|
@@ -14,29 +14,29 @@ module TwistyPuzzles
|
|
14
14
|
class CubeMoveParser < AbstractMoveParser
|
15
15
|
REGEXP =
|
16
16
|
begin
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
17
|
+
axes_part = "(?<axis_name>[#{AbstractMove::AXES.join}])"
|
18
|
+
face_names = CubeConstants::FACE_NAMES.join
|
19
|
+
fat_move_part =
|
20
|
+
"(?<width>\\d*)(?<fat_face_name>[#{face_names}])w"
|
21
|
+
normal_move_part = "(?<face_name>[#{face_names}])"
|
22
|
+
downcased_face_names = face_names.downcase
|
23
|
+
maybe_fat_maybe_slice_move_part =
|
24
|
+
"(?<maybe_fat_face_maybe_slice_name>[#{downcased_face_names}])"
|
25
|
+
slice_move_part =
|
26
|
+
"(?<slice_index>\\d+)(?<slice_name>[#{downcased_face_names}])"
|
27
|
+
mslice_move_part =
|
28
|
+
"(?<mslice_name>[#{AbstractMove::SLICE_FACES.keys.join}])"
|
29
|
+
move_part = "(?:#{axes_part}|" \
|
30
|
+
"#{fat_move_part}|" \
|
31
|
+
"#{normal_move_part}|" \
|
32
|
+
"#{maybe_fat_maybe_slice_move_part}|" \
|
33
|
+
"#{slice_move_part}|#{mslice_move_part})"
|
34
|
+
direction_names =
|
35
|
+
AbstractDirection::POSSIBLE_DIRECTION_NAMES.flatten
|
36
|
+
direction_names.sort_by! { |e| -e.length }
|
37
|
+
direction_part = "(?<direction>#{direction_names.join('|')})"
|
38
|
+
Regexp.new("#{move_part}#{direction_part}")
|
39
|
+
end
|
40
40
|
|
41
41
|
MOVE_TYPE_CREATORS = [
|
42
42
|
MoveTypeCreator.new(%i[axis_face direction], Rotation),
|
@@ -41,9 +41,10 @@ module TwistyPuzzles
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def maybe_reverse(reverse_mode, stuff)
|
44
|
-
|
44
|
+
case reverse_mode
|
45
|
+
when :reverse
|
45
46
|
stuff.reverse
|
46
|
-
|
47
|
+
when :keep
|
47
48
|
stuff
|
48
49
|
else
|
49
50
|
raise
|
@@ -102,7 +103,7 @@ module TwistyPuzzles
|
|
102
103
|
face_symbol_info = FACE_SYMBOL_INFOS[face_symbol]
|
103
104
|
stickers = cube_state.sticker_array(face)
|
104
105
|
center_color = color_character(stickers[0], color_mode)
|
105
|
-
corner_colors = stickers[1
|
106
|
+
corner_colors = stickers[1..].map { |c| color_character(c, color_mode) }
|
106
107
|
permuted_corner_colors =
|
107
108
|
apply_permutation(corner_colors, face_symbol_info.skewb_corner_permutation)
|
108
109
|
raise unless corner_colors.length == 4
|
@@ -75,6 +75,16 @@ module TwistyPuzzles
|
|
75
75
|
|
76
76
|
alias == eql?
|
77
77
|
|
78
|
+
def rotation_algorithms
|
79
|
+
Rotation::ALL_ROTATIONS.combination(2).reject do |r0, r1|
|
80
|
+
r0.inverse == r1
|
81
|
+
end.map { |rs| Algorithm.new(rs) } # rubocop:disable Style/MultilineBlockChain
|
82
|
+
end
|
83
|
+
|
84
|
+
def equal_modulo_rotations?(other)
|
85
|
+
rotation_algorithms.any? { |r| r.apply_temporarily_to(self) { |state| state == other } }
|
86
|
+
end
|
87
|
+
|
78
88
|
def hash
|
79
89
|
@hash ||= [self.class, @native].hash
|
80
90
|
end
|
@@ -185,14 +185,14 @@ module TwistyPuzzles # rubocop:disable Style/Documentation
|
|
185
185
|
end
|
186
186
|
end
|
187
187
|
|
188
|
-
def parse_commutator(alg_string, complete_parse
|
188
|
+
def parse_commutator(alg_string, complete_parse: true)
|
189
189
|
parser = Parser.new(alg_string, CubeMoveParser::INSTANCE)
|
190
190
|
commutator = parser.parse_commutator
|
191
191
|
parser.check_eos('commutator') if complete_parse
|
192
192
|
commutator
|
193
193
|
end
|
194
194
|
|
195
|
-
def parse_cube_algorithm(alg_string, complete_parse
|
195
|
+
def parse_cube_algorithm(alg_string, complete_parse: true)
|
196
196
|
parser = Parser.new(alg_string, CubeMoveParser::INSTANCE)
|
197
197
|
algorithm = parser.parse_algorithm
|
198
198
|
parser.check_eos('algorithm') if complete_parse
|
@@ -206,7 +206,7 @@ module TwistyPuzzles # rubocop:disable Style/Documentation
|
|
206
206
|
alias parse_algorithm parse_cube_algorithm
|
207
207
|
alias parse_move parse_cube_move
|
208
208
|
|
209
|
-
def parse_skewb_algorithm(alg_string, notation, complete_parse
|
209
|
+
def parse_skewb_algorithm(alg_string, notation, complete_parse: true)
|
210
210
|
parser = Parser.new(alg_string, SkewbMoveParser.new(notation))
|
211
211
|
algorithm = parser.parse_algorithm
|
212
212
|
parser.check_eos('algorithm') if complete_parse
|
@@ -35,10 +35,12 @@ module TwistyPuzzles
|
|
35
35
|
|
36
36
|
direction = translated_direction(skewb_direction)
|
37
37
|
|
38
|
-
Algorithm.new(
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
Algorithm.new(
|
39
|
+
[
|
40
|
+
Rotation.new(corner.faces[skewb_direction.value], direction),
|
41
|
+
Rotation.new(corner.faces[0], direction)
|
42
|
+
]
|
43
|
+
)
|
42
44
|
end
|
43
45
|
|
44
46
|
def to_s
|
@@ -62,6 +64,7 @@ module TwistyPuzzles
|
|
62
64
|
[self, alternative].include?(other)
|
63
65
|
end
|
64
66
|
|
67
|
+
# rubocop:disable Metrics/AbcSize
|
65
68
|
def prepend_rotation(other, _cube_size)
|
66
69
|
if same_axis?(other)
|
67
70
|
direction = translated_direction(other.axis_face)
|
@@ -74,6 +77,7 @@ module TwistyPuzzles
|
|
74
77
|
Algorithm.move(Rotation.new(remaining_face, CubeDirection::DOUBLE))
|
75
78
|
end
|
76
79
|
end
|
80
|
+
# rubocop:enable Metrics/AbcSize
|
77
81
|
|
78
82
|
def prepend_fat_m_slice_move(_other, _cube_size)
|
79
83
|
nil
|
@@ -12,6 +12,7 @@ module TwistyPuzzles
|
|
12
12
|
raise TypeError unless axis_corner.is_a?(Corner)
|
13
13
|
raise TypeError unless direction.is_a?(SkewbDirection)
|
14
14
|
|
15
|
+
super()
|
15
16
|
@axis_corner = axis_corner.rotate_face_up(axis_corner.faces.min_by(&:piece_index))
|
16
17
|
@direction = direction
|
17
18
|
end
|
@@ -10,9 +10,11 @@ module TwistyPuzzles
|
|
10
10
|
# Class that represents one notation for Skewb moves, e.g. Sarahs notation or fixed
|
11
11
|
# corner notation.
|
12
12
|
class SkewbNotation
|
13
|
+
# rubocop:disable Metrics/AbcSize
|
13
14
|
def initialize(name, move_corner_pairs)
|
14
15
|
raise TypeError unless name.is_a?(String)
|
15
16
|
|
17
|
+
super()
|
16
18
|
check_move_corner_pairs(move_corner_pairs)
|
17
19
|
@name = name
|
18
20
|
@move_to_corner = move_corner_pairs.to_h.freeze
|
@@ -26,7 +28,9 @@ module TwistyPuzzles
|
|
26
28
|
end.freeze
|
27
29
|
freeze
|
28
30
|
end
|
31
|
+
# rubocop:enable Metrics/AbcSize
|
29
32
|
|
33
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
30
34
|
def check_move_corner_pairs(move_corner_pairs)
|
31
35
|
move_corner_pairs.each do |m|
|
32
36
|
raise ArgumentError unless m.length == 2
|
@@ -37,6 +41,7 @@ module TwistyPuzzles
|
|
37
41
|
|
38
42
|
check_corner_coverage(move_corner_pairs.map(&:last))
|
39
43
|
end
|
44
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
40
45
|
|
41
46
|
def check_corner_coverage(corners)
|
42
47
|
corner_closure = corners + corners.map(&:diagonal_opposite)
|
@@ -49,6 +54,7 @@ module TwistyPuzzles
|
|
49
54
|
end
|
50
55
|
|
51
56
|
attr_reader :name, :move_strings, :non_zero_moves
|
57
|
+
|
52
58
|
private_class_method :new
|
53
59
|
|
54
60
|
def self.fixed_corner
|
@@ -103,7 +109,7 @@ module TwistyPuzzles
|
|
103
109
|
move_to_string(m, reversed_rotations)
|
104
110
|
end.join(' ')
|
105
111
|
new_tail_rotations = reversed_rotations.reverse! +
|
106
|
-
algorithm.moves[algorithm.length - num_tail_rotations
|
112
|
+
algorithm.moves[algorithm.length - num_tail_rotations..]
|
107
113
|
cancelled_rotations = Algorithm.new(new_tail_rotations).cancelled(3)
|
108
114
|
cancelled_rotations.empty? ? alg_string : "#{alg_string} #{cancelled_rotations}"
|
109
115
|
end
|
@@ -26,10 +26,12 @@ module TwistyPuzzles
|
|
26
26
|
next unless c2.face_symbols.include?(c1_rot.face_symbols.first)
|
27
27
|
|
28
28
|
c2_rot = c2.rotate_face_symbol_up(c1_rot.face_symbols.first)
|
29
|
-
check_parts.push(
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
check_parts.push(
|
30
|
+
[
|
31
|
+
SkewbCoordinate.for_corner(c1_rot),
|
32
|
+
SkewbCoordinate.for_corner(c2_rot)
|
33
|
+
]
|
34
|
+
)
|
33
35
|
end
|
34
36
|
matching_corners.push(check_parts)
|
35
37
|
end
|
metadata
CHANGED
@@ -1,11 +1,11 @@
|
|
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.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bernhard F. Brodowsky
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2020-04-21 00:00:00.000000000 Z
|
@@ -112,16 +112,16 @@ 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
126
|
name: rubocop-performance
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -164,7 +164,7 @@ dependencies:
|
|
164
164
|
- - ">="
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
|
-
description:
|
167
|
+
description:
|
168
168
|
email: bernhard.brodowsky@gmail.com
|
169
169
|
executables: []
|
170
170
|
extensions:
|
@@ -245,7 +245,7 @@ metadata:
|
|
245
245
|
homepage_uri: https://github.com/Lykos/twisty_puzzles
|
246
246
|
source_code_uri: https://github.com/Lykos/twisty_puzzles
|
247
247
|
changelog_uri: https://github.com/Lykos/twisty_puzzles/blob/master/CHANGELOG.md
|
248
|
-
post_install_message:
|
248
|
+
post_install_message:
|
249
249
|
rdoc_options: []
|
250
250
|
require_paths:
|
251
251
|
- lib
|
@@ -253,16 +253,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
253
253
|
requirements:
|
254
254
|
- - ">="
|
255
255
|
- !ruby/object:Gem::Version
|
256
|
-
version:
|
256
|
+
version: 3.0.0
|
257
257
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
258
258
|
requirements:
|
259
259
|
- - ">="
|
260
260
|
- !ruby/object:Gem::Version
|
261
261
|
version: '0'
|
262
262
|
requirements: []
|
263
|
-
|
264
|
-
|
265
|
-
signing_key:
|
263
|
+
rubygems_version: 3.2.3
|
264
|
+
signing_key:
|
266
265
|
specification_version: 4
|
267
266
|
summary: Gem for my cube_trainer rails app. Some things are better left in a separate
|
268
267
|
gem with no rails, e.g. native extensions. The main purpose is to support my Rails
|