twisty_puzzles 0.0.32 → 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7f97b7d7ae5e18648c974e310b3be824bcf266da8900bbf074ccb31d8a8868a
|
4
|
+
data.tar.gz: cd7012646185d4a85afca5b5919c5a42b90cfb27189cc9691de14b8d5dcaedc8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f46a05e2f8795ddd034867219c20b344eab78c864a71a0be29bf1dd69b4412337e9a28951f8042eb5d648c490118328e0b0b542714d4fa6011335cf147456d33
|
7
|
+
data.tar.gz: f356c2e2568a73b18c64a01c00067f334eef196ff1215de4465539a02c44523ef02a95d9e2fc03a007ccc1c3c396682e4c773745dbb5aa5951215756c8106600
|
data/lib/twisty_puzzles/cube.rb
CHANGED
@@ -390,7 +390,8 @@ module TwistyPuzzles
|
|
390
390
|
attr_reader :corresponding_part
|
391
391
|
|
392
392
|
def inspect
|
393
|
-
|
393
|
+
@inspect ||=
|
394
|
+
"#{self.class.name.split('::').last}(#{face_symbol}, #{@corresponding_part.inspect})"
|
394
395
|
end
|
395
396
|
|
396
397
|
def rotate_by(_number)
|
@@ -21,6 +21,7 @@ module TwistyPuzzles
|
|
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,17 +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
|
|
40
41
|
def inspect
|
41
|
-
@inspect ||=
|
42
|
+
@inspect ||=
|
43
|
+
"#{self.class.name.split('::').last}(#{@parts.map(&:inspect).join(', ')}#{twist_suffix})"
|
42
44
|
end
|
43
45
|
|
44
46
|
def hash
|
45
|
-
@hash ||=
|
47
|
+
@hash ||= [self.class, @parts, @twist].hash
|
46
48
|
end
|
47
49
|
|
48
50
|
def part_type
|
@@ -50,15 +52,16 @@ module TwistyPuzzles
|
|
50
52
|
end
|
51
53
|
|
52
54
|
def contains_any_part?(parts)
|
53
|
-
|
55
|
+
parts.any? { |p| contains?(p) }
|
54
56
|
end
|
55
57
|
|
56
58
|
def to_s
|
57
|
-
@parts.join(' ')
|
59
|
+
@to_s ||= @parts.join(' ')
|
58
60
|
end
|
59
61
|
|
60
62
|
def to_raw_data
|
61
|
-
|
63
|
+
@to_raw_data ||=
|
64
|
+
"#{simple_class_name(part_type)}(#{self}#{twist_suffix})"
|
62
65
|
end
|
63
66
|
|
64
67
|
def length
|
@@ -74,7 +77,7 @@ module TwistyPuzzles
|
|
74
77
|
end
|
75
78
|
|
76
79
|
def <=>(other)
|
77
|
-
@parts <=> other.parts
|
80
|
+
[part_type, @parts, @twist] <=> [other.part_type, other.parts, other.twist]
|
78
81
|
end
|
79
82
|
|
80
83
|
def canonicalize
|
@@ -106,14 +109,22 @@ module TwistyPuzzles
|
|
106
109
|
end
|
107
110
|
|
108
111
|
def inverse
|
109
|
-
|
112
|
+
inverse_twist = @twist.zero? ? @twist : parts.first.rotations.length - @twist
|
113
|
+
self.class.new([@parts[0]] + @parts[1..].reverse, inverse_twist)
|
110
114
|
end
|
111
115
|
|
112
116
|
def self.from_raw_data(data)
|
113
|
-
raw_part_type, raw_parts = data.match(
|
117
|
+
raw_part_type, raw_parts, raw_twist = data.match(/^(.*)\((.*?)(?:, (.+))?\)$/).captures
|
114
118
|
part_type = PART_TYPES.find { |p| simple_class_name(p) == raw_part_type }
|
119
|
+
twist = raw_twist ? Integer(raw_twist) : 0
|
115
120
|
parts = raw_parts.split.map { |r| part_type.parse(r) }
|
116
|
-
new(parts)
|
121
|
+
new(parts, twist)
|
122
|
+
end
|
123
|
+
|
124
|
+
private
|
125
|
+
|
126
|
+
def twist_suffix
|
127
|
+
@twist.positive? ? ", #{@twist}" : ''
|
117
128
|
end
|
118
129
|
|
119
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
|
-
|
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
|
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.
|
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-
|
11
|
+
date: 2021-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|