twisty_puzzles 0.0.1 → 0.0.6

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.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +21 -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 +31 -0
  26. data/lib/twisty_puzzles.rb +38 -0
  27. data/lib/twisty_puzzles/abstract_direction.rb +38 -39
  28. data/lib/twisty_puzzles/abstract_move.rb +1 -2
  29. data/lib/twisty_puzzles/abstract_move_parser.rb +32 -33
  30. data/lib/twisty_puzzles/algorithm.rb +112 -113
  31. data/lib/twisty_puzzles/algorithm_transformation.rb +19 -21
  32. data/lib/twisty_puzzles/axis_face_and_direction_move.rb +56 -56
  33. data/lib/twisty_puzzles/cancellation_helper.rb +124 -125
  34. data/lib/twisty_puzzles/color_scheme.rb +1 -1
  35. data/lib/twisty_puzzles/commutator.rb +82 -80
  36. data/lib/twisty_puzzles/compiled_algorithm.rb +31 -32
  37. data/lib/twisty_puzzles/compiled_cube_algorithm.rb +49 -50
  38. data/lib/twisty_puzzles/compiled_skewb_algorithm.rb +18 -19
  39. data/lib/twisty_puzzles/coordinate.rb +243 -246
  40. data/lib/twisty_puzzles/cube.rb +494 -495
  41. data/lib/twisty_puzzles/cube_constants.rb +40 -41
  42. data/lib/twisty_puzzles/cube_direction.rb +15 -18
  43. data/lib/twisty_puzzles/cube_move.rb +285 -290
  44. data/lib/twisty_puzzles/cube_move_parser.rb +75 -76
  45. data/lib/twisty_puzzles/cube_print_helper.rb +133 -133
  46. data/lib/twisty_puzzles/cube_state.rb +80 -81
  47. data/lib/twisty_puzzles/move_type_creator.rb +17 -18
  48. data/lib/twisty_puzzles/parser.rb +176 -179
  49. data/lib/twisty_puzzles/part_cycle_factory.rb +39 -42
  50. data/lib/twisty_puzzles/puzzle.rb +16 -17
  51. data/lib/twisty_puzzles/reversible_applyable.rb +24 -25
  52. data/lib/twisty_puzzles/rotation.rb +76 -75
  53. data/lib/twisty_puzzles/skewb_direction.rb +14 -15
  54. data/lib/twisty_puzzles/skewb_move.rb +49 -49
  55. data/lib/twisty_puzzles/skewb_move_parser.rb +51 -51
  56. data/lib/twisty_puzzles/skewb_notation.rb +121 -118
  57. data/lib/twisty_puzzles/skewb_state.rb +120 -121
  58. data/lib/twisty_puzzles/state_helper.rb +20 -21
  59. data/lib/twisty_puzzles/sticker_cycle.rb +43 -44
  60. data/lib/twisty_puzzles/utils.rb +3 -0
  61. data/lib/twisty_puzzles/version.rb +3 -1
  62. metadata +30 -10
@@ -3,30 +3,29 @@
3
3
  require 'twisty_puzzles/abstract_direction'
4
4
 
5
5
  module TwistyPuzzles
6
-
7
- # Common utilities for different puzzle states.
8
- # TODO: Remove
9
- module StateHelper
10
- def apply_sticker_cycle(cycle)
11
- last_sticker = self[cycle[-1]]
12
- (cycle.length - 1).downto(1) do |i|
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
- def apply_4sticker_cycle(cycle, direction)
19
- raise ArgumentError unless cycle.length == 4
20
- raise TypeError unless direction.is_a?(AbstractDirection)
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
- if direction.double_move?
23
- apply_sticker_cycle([cycle[0], cycle[2]])
24
- apply_sticker_cycle([cycle[1], cycle[3]])
25
- else
26
- # Note that we cannot do reverse! because the values are cached.
27
- actual_cycle = direction.value == 3 ? cycle.reverse : cycle
28
- apply_sticker_cycle(actual_cycle)
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
- # A sticker cycle that can be applied to a cube state.
11
- class StickerCycle
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
- attr_reader :cube_size, :sticker_cycle
13
+ def initialize(cube_size, sticker_cycle)
14
+ @cube_size = cube_size
15
+ @sticker_cycle = sticker_cycle
16
+ end
20
17
 
21
- def apply_to(cube_state)
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
- cube_state.apply_sticker_cycle(@sticker_cycle) if @sticker_cycle.length >= 2
26
- end
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
- def inverse
29
- StickerCycle.new(@cube_size, @sticker_cycle.reverse)
30
- end
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
- # A set of disjoint sticker cycles that can be applied to a cube state together
34
- class StickerCycles
35
- include ReversibleApplyable
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
- def initialize(cube_size, sticker_cycles)
38
- affected_set = Set[]
39
- sticker_cycles.each do |c|
40
- raise TypeError unless c.is_a?(StickerCycle)
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
- c.sticker_cycle.each do |s|
43
- raise ArgumentError unless affected_set.add?(s)
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
- attr_reader :cube_size, :sticker_cycles
49
+ attr_reader :cube_size, :sticker_cycles
51
50
 
52
- def apply_to(cube_state)
53
- raise TypeError unless cube_state.is_a?(CubeState)
54
- raise ArgumentError unless cube_state.n == @cube_size
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
- @sticker_cycles.each { |c| c.apply_to(cube_state) }
57
- end
55
+ @sticker_cycles.each { |c| c.apply_to(cube_state) }
56
+ end
58
57
 
59
- def +(other)
60
- raise TypeError unless other.is_a?(StickerCycles)
61
- raise ArgumentError unless @cube_size == other.cube_size
58
+ def +(other)
59
+ raise TypeError unless other.is_a?(StickerCycles)
60
+ raise ArgumentError unless @cube_size == other.cube_size
62
61
 
63
- StickerCycles.new(@cube_size, @sticker_cycles + other.sticker_cycles)
64
- end
62
+ StickerCycles.new(@cube_size, @sticker_cycles + other.sticker_cycles)
63
+ end
65
64
 
66
- def inverse
67
- StickerCycles.new(@cube_size, @sticker_cycles.map(&:inverse))
68
- end
65
+ def inverse
66
+ StickerCycles.new(@cube_size, @sticker_cycles.map(&:inverse))
69
67
  end
68
+ end
70
69
  end
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'twisty_puzzles/utils/array_helper'
4
+ require 'twisty_puzzles/utils/string_helper'
5
+
3
6
  module CubeTrainer
4
7
  # Module that contains various utils that aren't very specific to twisty puzzles.
5
8
  module Utils
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module TwistyPuzzles
2
- VERSION = '0.0.1'
4
+ VERSION = '0.0.6'
3
5
  end
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.1
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: '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
- name: rubocop-rake
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-performance
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.3.0
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
- rubyforge_project:
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