twisty_puzzles 0.0.1 → 0.0.2

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 (37) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -1
  3. data/lib/twisty_puzzles.rb +37 -0
  4. data/lib/twisty_puzzles/abstract_direction.rb +38 -39
  5. data/lib/twisty_puzzles/abstract_move_parser.rb +32 -33
  6. data/lib/twisty_puzzles/algorithm.rb +112 -113
  7. data/lib/twisty_puzzles/algorithm_transformation.rb +19 -21
  8. data/lib/twisty_puzzles/axis_face_and_direction_move.rb +55 -56
  9. data/lib/twisty_puzzles/cancellation_helper.rb +124 -125
  10. data/lib/twisty_puzzles/commutator.rb +79 -80
  11. data/lib/twisty_puzzles/compiled_algorithm.rb +31 -32
  12. data/lib/twisty_puzzles/compiled_cube_algorithm.rb +49 -50
  13. data/lib/twisty_puzzles/compiled_skewb_algorithm.rb +18 -19
  14. data/lib/twisty_puzzles/coordinate.rb +245 -246
  15. data/lib/twisty_puzzles/cube.rb +494 -495
  16. data/lib/twisty_puzzles/cube_constants.rb +40 -41
  17. data/lib/twisty_puzzles/cube_direction.rb +15 -18
  18. data/lib/twisty_puzzles/cube_move.rb +289 -290
  19. data/lib/twisty_puzzles/cube_move_parser.rb +75 -76
  20. data/lib/twisty_puzzles/cube_print_helper.rb +132 -133
  21. data/lib/twisty_puzzles/cube_state.rb +80 -81
  22. data/lib/twisty_puzzles/move_type_creator.rb +17 -18
  23. data/lib/twisty_puzzles/parser.rb +176 -179
  24. data/lib/twisty_puzzles/part_cycle_factory.rb +39 -42
  25. data/lib/twisty_puzzles/puzzle.rb +16 -17
  26. data/lib/twisty_puzzles/reversible_applyable.rb +24 -25
  27. data/lib/twisty_puzzles/rotation.rb +74 -75
  28. data/lib/twisty_puzzles/skewb_direction.rb +14 -15
  29. data/lib/twisty_puzzles/skewb_move.rb +48 -49
  30. data/lib/twisty_puzzles/skewb_move_parser.rb +50 -51
  31. data/lib/twisty_puzzles/skewb_notation.rb +115 -118
  32. data/lib/twisty_puzzles/skewb_state.rb +120 -121
  33. data/lib/twisty_puzzles/state_helper.rb +20 -21
  34. data/lib/twisty_puzzles/sticker_cycle.rb +43 -44
  35. data/lib/twisty_puzzles/utils.rb +3 -0
  36. data/lib/twisty_puzzles/version.rb +3 -1
  37. metadata +3 -3
@@ -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.2'
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.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernhard F. Brodowsky
@@ -123,7 +123,7 @@ dependencies:
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
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
  - - ">="