twisty_puzzles 0.0.2 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -1
  3. data/README.md +6 -1
  4. data/ext/twisty_puzzles/native/cube_algorithm.c +267 -0
  5. data/ext/twisty_puzzles/native/cube_algorithm.h +5 -0
  6. data/ext/twisty_puzzles/native/cube_average.c +184 -0
  7. data/ext/twisty_puzzles/native/cube_average.h +5 -0
  8. data/ext/twisty_puzzles/native/cube_coordinate.c +207 -0
  9. data/ext/twisty_puzzles/native/cube_coordinate.h +34 -0
  10. data/ext/twisty_puzzles/native/cube_state.c +264 -0
  11. data/ext/twisty_puzzles/native/cube_state.h +31 -0
  12. data/ext/twisty_puzzles/native/extconf.rb +1 -1
  13. data/ext/twisty_puzzles/native/face_symbols.c +67 -0
  14. data/ext/twisty_puzzles/native/face_symbols.h +34 -0
  15. data/ext/twisty_puzzles/native/native.c +28 -0
  16. data/ext/twisty_puzzles/native/skewb_algorithm.c +331 -0
  17. data/ext/twisty_puzzles/native/skewb_algorithm.h +5 -0
  18. data/ext/twisty_puzzles/native/skewb_coordinate.c +237 -0
  19. data/ext/twisty_puzzles/native/skewb_coordinate.h +36 -0
  20. data/ext/twisty_puzzles/native/skewb_layer_fingerprint.c +271 -0
  21. data/ext/twisty_puzzles/native/skewb_layer_fingerprint.h +5 -0
  22. data/ext/twisty_puzzles/native/skewb_state.c +214 -0
  23. data/ext/twisty_puzzles/native/skewb_state.h +23 -0
  24. data/ext/twisty_puzzles/native/utils.c +76 -0
  25. data/ext/twisty_puzzles/native/utils.h +28 -0
  26. data/lib/twisty_puzzles.rb +1 -0
  27. data/lib/twisty_puzzles/abstract_move.rb +1 -2
  28. data/lib/twisty_puzzles/abstract_move_parser.rb +1 -1
  29. data/lib/twisty_puzzles/algorithm.rb +1 -1
  30. data/lib/twisty_puzzles/axis_face_and_direction_move.rb +1 -0
  31. data/lib/twisty_puzzles/cancellation_helper.rb +1 -1
  32. data/lib/twisty_puzzles/color_scheme.rb +1 -1
  33. data/lib/twisty_puzzles/commutator.rb +3 -0
  34. data/lib/twisty_puzzles/compiled_algorithm.rb +4 -4
  35. data/lib/twisty_puzzles/coordinate.rb +4 -6
  36. data/lib/twisty_puzzles/cube.rb +3 -3
  37. data/lib/twisty_puzzles/cube_move.rb +0 -4
  38. data/lib/twisty_puzzles/cube_move_parser.rb +23 -23
  39. data/lib/twisty_puzzles/cube_print_helper.rb +4 -3
  40. data/lib/twisty_puzzles/parser.rb +3 -3
  41. data/lib/twisty_puzzles/rotation.rb +2 -0
  42. data/lib/twisty_puzzles/skewb_move.rb +1 -0
  43. data/lib/twisty_puzzles/skewb_move_parser.rb +1 -0
  44. data/lib/twisty_puzzles/skewb_notation.rb +7 -1
  45. data/lib/twisty_puzzles/version.rb +1 -1
  46. metadata +32 -12
@@ -90,7 +90,7 @@ module TwistyPuzzles
90
90
  base_coordinate = Coordinate.from_indices(
91
91
  part.solved_face, cube_size, *part.base_index_on_face(cube_size, incarnation_index)
92
92
  )
93
- other_face_symbols = part.corresponding_part.face_symbols[1..-1]
93
+ other_face_symbols = part.corresponding_part.face_symbols[1..]
94
94
  match_coordinate_internal(base_coordinate, other_face_symbols)
95
95
  end
96
96
 
@@ -99,7 +99,7 @@ module TwistyPuzzles
99
99
  def self.solved_positions(part, cube_size, incarnation_index)
100
100
  solved_coordinate = solved_position(part, cube_size, incarnation_index)
101
101
  other_coordinates =
102
- part.face_symbols[1..-1].map.with_index do |f, i|
102
+ part.face_symbols[1..].map.with_index do |f, i|
103
103
  face = Face.for_face_symbol(f)
104
104
  # The reverse is important for edge like parts. We are not in the same position as usual
105
105
  # solved pieces would be.
@@ -109,7 +109,7 @@ module TwistyPuzzles
109
109
  base_coordinate = Coordinate.from_indices(face, cube_size, *base_indices)
110
110
  other_face_symbols = [part.face_symbols[0]] +
111
111
  part.corresponding_part.face_symbols[1...i + 1] +
112
- part.corresponding_part.face_symbols[i + 2..-1]
112
+ part.corresponding_part.face_symbols[i + 2..]
113
113
  match_coordinate_internal(base_coordinate, other_face_symbols)
114
114
  end
115
115
  [solved_coordinate] + other_coordinates
@@ -276,7 +276,7 @@ module TwistyPuzzles
276
276
  @native = native
277
277
  end
278
278
 
279
- attr_reader :native
279
+ attr_reader :native, :coordinate
280
280
 
281
281
  private_class_method :new
282
282
 
@@ -311,7 +311,5 @@ module TwistyPuzzles
311
311
  def face
312
312
  @face ||= Face.for_face_symbol(@native.face)
313
313
  end
314
-
315
- attr_reader :coordinate
316
314
  end
317
315
  end
@@ -97,7 +97,7 @@ module TwistyPuzzles
97
97
  end
98
98
 
99
99
  def inspect
100
- self.class.to_s + '(' + @face_symbols.map(&:to_s).join(', ') + ')'
100
+ "#{self.class}(#{@face_symbols.map(&:to_s).join(', ')})"
101
101
  end
102
102
 
103
103
  def to_s
@@ -365,7 +365,7 @@ module TwistyPuzzles
365
365
  attr_reader :corresponding_part
366
366
 
367
367
  def inspect
368
- self.class.to_s + '(' + face_symbol.to_s + ', ' + @corresponding_part.inspect + ')'
368
+ "#{self.class}(#{face_symbol}, #{@corresponding_part.inspect})"
369
369
  end
370
370
 
371
371
  def rotate_by(_number)
@@ -532,7 +532,7 @@ module TwistyPuzzles
532
532
 
533
533
  def self.create_for_face_symbols(face_symbols)
534
534
  piece_candidates =
535
- face_symbols[1..-1].permutation.map do |cs|
535
+ face_symbols[1..].permutation.map do |cs|
536
536
  new([face_symbols[0]] + cs)
537
537
  end
538
538
  find_only(piece_candidates, &:valid?)
@@ -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
- 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
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
- if reverse_mode == :reverse
44
+ case reverse_mode
45
+ when :reverse
45
46
  stuff.reverse
46
- elsif reverse_mode == :keep
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..-1].map { |c| color_character(c, color_mode) }
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
@@ -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 = true)
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 = true)
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 = true)
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
@@ -62,6 +62,7 @@ module TwistyPuzzles
62
62
  [self, alternative].include?(other)
63
63
  end
64
64
 
65
+ # rubocop:disable Metrics/AbcSize
65
66
  def prepend_rotation(other, _cube_size)
66
67
  if same_axis?(other)
67
68
  direction = translated_direction(other.axis_face)
@@ -74,6 +75,7 @@ module TwistyPuzzles
74
75
  Algorithm.move(Rotation.new(remaining_face, CubeDirection::DOUBLE))
75
76
  end
76
77
  end
78
+ # rubocop:enable Metrics/AbcSize
77
79
 
78
80
  def prepend_fat_m_slice_move(_other, _cube_size)
79
81
  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
@@ -18,6 +18,7 @@ module TwistyPuzzles
18
18
  def initialize(notation)
19
19
  raise TypeError unless notation.is_a?(SkewbNotation)
20
20
 
21
+ super()
21
22
  @notation = notation
22
23
  end
23
24
 
@@ -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..-1]
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TwistyPuzzles
4
- VERSION = '0.0.2'
4
+ VERSION = '0.0.7'
5
5
  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.2
4
+ version: 0.0.7
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: '0'
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: '0'
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:
@@ -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
@@ -224,7 +245,7 @@ metadata:
224
245
  homepage_uri: https://github.com/Lykos/twisty_puzzles
225
246
  source_code_uri: https://github.com/Lykos/twisty_puzzles
226
247
  changelog_uri: https://github.com/Lykos/twisty_puzzles/blob/master/CHANGELOG.md
227
- post_install_message:
248
+ post_install_message:
228
249
  rdoc_options: []
229
250
  require_paths:
230
251
  - lib
@@ -232,16 +253,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
232
253
  requirements:
233
254
  - - ">="
234
255
  - !ruby/object:Gem::Version
235
- version: 2.3.0
256
+ version: 3.0.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
- rubyforge_project:
243
- rubygems_version: 2.7.6.2
244
- signing_key:
263
+ rubygems_version: 3.2.3
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
247
267
  gem with no rails, e.g. native extensions. The main purpose is to support my Rails