twisty_puzzles 0.0.14 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/twisty_puzzles/algorithm.rb +5 -2
- data/lib/twisty_puzzles/commutator.rb +15 -0
- data/lib/twisty_puzzles/parser.rb +23 -9
- data/lib/twisty_puzzles/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5631e9c30819f3520d04ed81aa9b1ceebbee7a3da5c3b51bf2a81947f8fb3a1
|
4
|
+
data.tar.gz: fc4769b6c1ebab5d14cb64ddb3e39356a408750d1d0c7954d4929156296b9f9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c941aaef4dbf2bc8d580d712d669042061c20670aadcf2ee353f353eae4eb31713de9d4791f6d8126e4427ef9e7125562e26b53c85f0a92e09bfe120e8f24f04
|
7
|
+
data.tar.gz: 5e943e567b069fd2b2e21c77fdc7a48ad3e81fb365832439cd1f402da838b5771bc7af4b2293bf635fa1b6de158ddfbea78f9981e690ce3e72a6149c6b042bd2
|
@@ -133,9 +133,12 @@ module TwistyPuzzles
|
|
133
133
|
|
134
134
|
def *(other)
|
135
135
|
raise TypeError unless other.is_a?(Integer)
|
136
|
-
raise ArgumentError if other.negative?
|
137
136
|
|
138
|
-
|
137
|
+
if other.negative?
|
138
|
+
inverse * -other
|
139
|
+
else
|
140
|
+
self.class.new(@moves * other)
|
141
|
+
end
|
139
142
|
end
|
140
143
|
|
141
144
|
def compiled_for_skewb
|
@@ -83,6 +83,21 @@ module TwistyPuzzles
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
+
# Slash commutator of the form A B A2 B' A.
|
87
|
+
class SlashCommutator < PureCommutator
|
88
|
+
def inverse
|
89
|
+
SlashCommutator.new(first_part.inverse, second_part)
|
90
|
+
end
|
91
|
+
|
92
|
+
def to_s
|
93
|
+
"[#{@first_part}/#{@second_part}]"
|
94
|
+
end
|
95
|
+
|
96
|
+
def algorithm
|
97
|
+
first_part + second_part + (first_part * 2) + second_part.inverse + first_part
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
86
101
|
# Setup commutator of the form A B A'.
|
87
102
|
class SetupCommutator < Commutator
|
88
103
|
def initialize(setup, inner_commutator)
|
@@ -16,6 +16,12 @@ module TwistyPuzzles # rubocop:disable Style/Documentation
|
|
16
16
|
OPENING_PAREN = '('
|
17
17
|
CLOSING_BRACKET = ']'
|
18
18
|
CLOSING_PAREN = ')'
|
19
|
+
SLASH = '/'
|
20
|
+
COMMA = ','
|
21
|
+
SETUP_SEPARATORS = %w[; :].freeze
|
22
|
+
PURE_SEPARATORS = [SLASH, COMMA].freeze
|
23
|
+
SEPARATORS = (SETUP_SEPARATORS + PURE_SEPARATORS).freeze
|
24
|
+
|
19
25
|
TIMES = '*'
|
20
26
|
|
21
27
|
def initialize(alg_string, move_parser)
|
@@ -156,11 +162,11 @@ module TwistyPuzzles # rubocop:disable Style/Documentation
|
|
156
162
|
parse_open_bracket
|
157
163
|
first_part = parse_nonempty_moves_with_triggers
|
158
164
|
skip_spaces
|
159
|
-
parse_pure_separator
|
165
|
+
separator = parse_pure_separator
|
160
166
|
second_part = parse_nonempty_moves_with_triggers
|
161
167
|
skip_spaces
|
162
168
|
parse_close_bracket
|
163
|
-
|
169
|
+
pseudo_pure_commutator(separator, first_part, second_part)
|
164
170
|
end
|
165
171
|
|
166
172
|
def parse_pure_commutator_no_brackets
|
@@ -172,14 +178,16 @@ module TwistyPuzzles # rubocop:disable Style/Documentation
|
|
172
178
|
|
173
179
|
first_part = first_part_or_algorithm
|
174
180
|
complain('move') if first_part.empty?
|
175
|
-
parse_pure_separator
|
181
|
+
separator = parse_pure_separator
|
176
182
|
second_part = parse_nonempty_moves_with_triggers
|
177
183
|
skip_spaces
|
178
|
-
|
184
|
+
pseudo_pure_commutator(separator, first_part, second_part)
|
179
185
|
end
|
180
186
|
|
181
187
|
def parse_pure_separator
|
182
|
-
|
188
|
+
separator = @scanner.getch
|
189
|
+
complain('middle of pure commutator') unless PURE_SEPARATORS.include?(separator)
|
190
|
+
separator
|
183
191
|
end
|
184
192
|
|
185
193
|
def parse_commutator_internal_after_separator(setup_or_first_part, separator)
|
@@ -188,15 +196,21 @@ module TwistyPuzzles # rubocop:disable Style/Documentation
|
|
188
196
|
SetupCommutator.new(setup_or_first_part, inner_commutator)
|
189
197
|
elsif PURE_SEPARATORS.include?(separator)
|
190
198
|
second_part = parse_nonempty_moves_with_triggers
|
191
|
-
|
199
|
+
pseudo_pure_commutator(separator, setup_or_first_part, second_part)
|
192
200
|
else
|
193
201
|
complain('end of setup or middle of pure commutator') unless @scanner.eos?
|
194
202
|
end
|
195
203
|
end
|
196
204
|
|
197
|
-
|
198
|
-
|
199
|
-
|
205
|
+
def pseudo_pure_commutator(separator, first_part, second_part)
|
206
|
+
if separator == COMMA
|
207
|
+
PureCommutator.new(first_part, second_part)
|
208
|
+
elsif separator == SLASH
|
209
|
+
SlashCommutator.new(first_part, second_part)
|
210
|
+
else
|
211
|
+
complain('middle of pure commutator') unless PURE_SEPARATORS.include?(separator)
|
212
|
+
end
|
213
|
+
end
|
200
214
|
|
201
215
|
def parse_separator
|
202
216
|
separator = @scanner.getch
|