twisty_puzzles 0.0.29 → 0.0.33

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4a36579770d4f4a738e61f718667325433469a295d7f131f7fa3b3ea770f7917
4
- data.tar.gz: fc9f222127a4ab7f3af88cd6fd41b5ca18005e02e531eaba4be3fbbaa5030fde
3
+ metadata.gz: c7f97b7d7ae5e18648c974e310b3be824bcf266da8900bbf074ccb31d8a8868a
4
+ data.tar.gz: cd7012646185d4a85afca5b5919c5a42b90cfb27189cc9691de14b8d5dcaedc8
5
5
  SHA512:
6
- metadata.gz: 8bfe24af1bbc9d601ef76c7838167c126a223248a87086bc516d78adcee3ab82f64545a173b3e9774bab5b40a4fce6498a21b659d4b92f45654802e251ec97d2
7
- data.tar.gz: e8e21f651133dc55e41d099ea3c9f484ff0ad49a7d9375ce7aef27ae3eb143fa70dc24c47788bf43463bc25063ce6aa9cbe0e35a0cb94c1e5260d1dc7a257f54
6
+ metadata.gz: f46a05e2f8795ddd034867219c20b344eab78c864a71a0be29bf1dd69b4412337e9a28951f8042eb5d648c490118328e0b0b542714d4fa6011335cf147456d33
7
+ data.tar.gz: f356c2e2568a73b18c64a01c00067f334eef196ff1215de4465539a02c44523ef02a95d9e2fc03a007ccc1c3c396682e4c773745dbb5aa5951215756c8106600
@@ -74,7 +74,7 @@ module TwistyPuzzles
74
74
 
75
75
  def self.exists_on_cube_size?(cube_size)
76
76
  cube_size >= min_cube_size && cube_size <= max_cube_size &&
77
- (cube_size % 2 == 0 ? self.exists_on_even_cube_sizes? : self.exists_on_odd_cube_sizes?)
77
+ (cube_size.even? ? exists_on_even_cube_sizes? : exists_on_odd_cube_sizes?)
78
78
  end
79
79
 
80
80
  def num_incarnations(_cube_size)
@@ -122,7 +122,7 @@ module TwistyPuzzles
122
122
  end
123
123
 
124
124
  def inspect
125
- "#{self.class}(#{@face_symbols.map(&:to_s).join(', ')})"
125
+ @inspect ||= "#{self.class.name.split('::').last}(#{@face_symbols.map(&:to_s).join(', ')})"
126
126
  end
127
127
 
128
128
  def to_s
@@ -390,7 +390,8 @@ module TwistyPuzzles
390
390
  attr_reader :corresponding_part
391
391
 
392
392
  def inspect
393
- "#{self.class}(#{face_symbol}, #{@corresponding_part.inspect})"
393
+ @inspect ||=
394
+ "#{self.class.name.split('::').last}(#{face_symbol}, #{@corresponding_part.inspect})"
394
395
  end
395
396
 
396
397
  def rotate_by(_number)
@@ -17,10 +17,11 @@ module TwistyPuzzles
17
17
 
18
18
  RAW_DATA_RESERVED = [' ', '(', ')'].freeze
19
19
 
20
- def initialize(parts, twist=0)
20
+ def initialize(parts, twist = 0)
21
21
  raise ArgumentError if parts.empty?
22
22
  raise TypeError unless twist.is_a?(Integer)
23
23
  raise ArgumentError if twist.negative?
24
+ raise ArgumentError if twist >= parts.first.rotations.length
24
25
 
25
26
  check_types(parts, Part)
26
27
  check_type_consistency(parts)
@@ -32,13 +33,18 @@ module TwistyPuzzles
32
33
  attr_reader :parts, :twist
33
34
 
34
35
  def eql?(other)
35
- self.class.equal?(other.class) && @parts == other.parts
36
+ self.class.equal?(other.class) && @parts == other.parts && @twist == other.twist
36
37
  end
37
38
 
38
39
  alias == eql?
39
40
 
41
+ def inspect
42
+ @inspect ||=
43
+ "#{self.class.name.split('::').last}(#{@parts.map(&:inspect).join(', ')}#{twist_suffix})"
44
+ end
45
+
40
46
  def hash
41
- @hash ||= ([self.class] + @parts).hash
47
+ @hash ||= [self.class, @parts, @twist].hash
42
48
  end
43
49
 
44
50
  def part_type
@@ -46,15 +52,16 @@ module TwistyPuzzles
46
52
  end
47
53
 
48
54
  def contains_any_part?(parts)
49
- !(@parts & parts).empty?
55
+ parts.any? { |p| contains?(p) }
50
56
  end
51
57
 
52
58
  def to_s
53
- @parts.join(' ')
59
+ @to_s ||= @parts.join(' ')
54
60
  end
55
61
 
56
62
  def to_raw_data
57
- "#{simple_class_name(part_type)}(#{self})"
63
+ @to_raw_data ||=
64
+ "#{simple_class_name(part_type)}(#{self}#{twist_suffix})"
58
65
  end
59
66
 
60
67
  def length
@@ -70,7 +77,7 @@ module TwistyPuzzles
70
77
  end
71
78
 
72
79
  def <=>(other)
73
- @parts <=> other.parts
80
+ [part_type, @parts, @twist] <=> [other.part_type, other.parts, other.twist]
74
81
  end
75
82
 
76
83
  def canonicalize
@@ -94,7 +101,7 @@ module TwistyPuzzles
94
101
 
95
102
  index = @parts.find_index { |p| p.turned_equals?(part) }
96
103
  map_rotate_by_number = @parts[index].rotations.index(part)
97
- rotate_by(@parts.length - index).map_rotate_by(map_rotate_by_number)
104
+ rotate_by(index).map_rotate_by(map_rotate_by_number)
98
105
  end
99
106
 
100
107
  def equivalent?(other)
@@ -102,14 +109,22 @@ module TwistyPuzzles
102
109
  end
103
110
 
104
111
  def inverse
105
- self.class.new([@parts[0]] + @parts[1..].reverse)
112
+ inverse_twist = @twist.zero? ? @twist : parts.first.rotations.length - @twist
113
+ self.class.new([@parts[0]] + @parts[1..].reverse, inverse_twist)
106
114
  end
107
115
 
108
116
  def self.from_raw_data(data)
109
- raw_part_type, raw_parts = data.match(/(.*)\((.*)\)/).captures
117
+ raw_part_type, raw_parts, raw_twist = data.match(/^(.*)\((.*?)(?:, (.+))?\)$/).captures
110
118
  part_type = PART_TYPES.find { |p| simple_class_name(p) == raw_part_type }
119
+ twist = raw_twist ? Integer(raw_twist) : 0
111
120
  parts = raw_parts.split.map { |r| part_type.parse(r) }
112
- new(parts)
121
+ new(parts, twist)
122
+ end
123
+
124
+ private
125
+
126
+ def twist_suffix
127
+ @twist.positive? ? ", #{@twist}" : ''
113
128
  end
114
129
 
115
130
  def check_type_consistency(parts)
@@ -7,6 +7,7 @@ require 'twisty_puzzles/reversible_applyable'
7
7
 
8
8
  module TwistyPuzzles
9
9
  # A sticker cycle that can be applied to a cube state.
10
+ # TODO: Deprecate
10
11
  class StickerCycle
11
12
  include ReversibleApplyable
12
13
 
@@ -55,6 +56,7 @@ module TwistyPuzzles
55
56
  end
56
57
 
57
58
  # A set of disjoint sticker cycles that can be applied to a cube state together
59
+ # TODO: Deprecate
58
60
  class StickerCycles
59
61
  include ReversibleApplyable
60
62
 
@@ -64,7 +66,10 @@ module TwistyPuzzles
64
66
  raise TypeError unless c.is_a?(StickerCycle)
65
67
 
66
68
  c.native.coordinates.each do |s|
67
- raise ArgumentError unless affected_set.add?(s)
69
+ unless affected_set.add?(s)
70
+ raise ArgumentError,
71
+ 'There is an intersection between part cycles'
72
+ end
68
73
  end
69
74
  end
70
75
  @cube_size = cube_size
@@ -6,6 +6,7 @@ require 'twisty_puzzles/cube'
6
6
 
7
7
  module TwistyPuzzles
8
8
  # Factory for sticker cycles given part cycles.
9
+ # TODO: Deprecate
9
10
  class StickerCycleFactory
10
11
  include Utils::ArrayHelper
11
12
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TwistyPuzzles
4
- VERSION = '0.0.29'
4
+ VERSION = '0.0.33'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twisty_puzzles
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.29
4
+ version: 0.0.33
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernhard F. Brodowsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-20 00:00:00.000000000 Z
11
+ date: 2021-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize