twisty_puzzles 0.0.19 → 0.0.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/twisty_puzzles/color_scheme.rb +0 -1
- data/lib/twisty_puzzles/cube.rb +4 -0
- data/lib/twisty_puzzles/part_cycle.rb +100 -0
- data/lib/twisty_puzzles/{part_cycle_factory.rb → sticker_cycle_factory.rb} +2 -1
- data/lib/twisty_puzzles/version.rb +1 -1
- data/lib/twisty_puzzles.rb +2 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38464f2fe484f8bf9336b02fd487750afd507060ad308f43fc7f6f77d4fdd009
|
4
|
+
data.tar.gz: 7934ea73bdbc8aa54bbc342693ab2118ca927f5ac5f4e4af2e63d0f1669c7eda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84c639c1b0d861543494f12256212a17d758e37fc2ef4099dd894a50d545c566d5c172ee839bcbb25ad1d5a76911003e93c4aaf7f1180ca4d61497ecd546c46e
|
7
|
+
data.tar.gz: 21eccbfb1040243dddaf036fa43d2b8ef54a020a23df3470dc7c18bc7ee44f404fe8df633293c80445d377db13e62d12b60305184a5b985b0e691b17d0f6da05
|
data/lib/twisty_puzzles/cube.rb
CHANGED
@@ -0,0 +1,100 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'twisty_puzzles/utils/array_helper'
|
4
|
+
require 'twisty_puzzles/sticker_cycle_factory'
|
5
|
+
require 'twisty_puzzles/cube'
|
6
|
+
|
7
|
+
module TwistyPuzzles
|
8
|
+
# A cycle of parts of the cube, e.g. a corner 3 cycle.
|
9
|
+
# Note that this is abstract and contains no information on the cube size.
|
10
|
+
# E.g. for wings on a 7x7, it's not clear whether inner or outer wings are used.
|
11
|
+
# Check StickerCycleFactory for making it concrete and applyable.
|
12
|
+
class PartCycle
|
13
|
+
include Utils::ArrayHelper
|
14
|
+
|
15
|
+
RAW_DATA_RESERVED = [' ', '(', ')'].freeze
|
16
|
+
|
17
|
+
def initialize(parts)
|
18
|
+
raise ArgumentError if parts.empty?
|
19
|
+
|
20
|
+
check_types(parts, Part)
|
21
|
+
check_type_consistency(parts)
|
22
|
+
|
23
|
+
@parts = parts
|
24
|
+
end
|
25
|
+
|
26
|
+
attr_reader :parts
|
27
|
+
|
28
|
+
def eql?(other)
|
29
|
+
self.class.equal?(other.class) && @parts == other.parts
|
30
|
+
end
|
31
|
+
|
32
|
+
alias == eql?
|
33
|
+
|
34
|
+
def hash
|
35
|
+
@hash ||= ([self.class] + @parts).hash
|
36
|
+
end
|
37
|
+
|
38
|
+
def part_type
|
39
|
+
@parts.first.class
|
40
|
+
end
|
41
|
+
|
42
|
+
def contains_any_part?(parts)
|
43
|
+
!(@parts & parts).empty?
|
44
|
+
end
|
45
|
+
|
46
|
+
def to_s
|
47
|
+
@parts.join(' ')
|
48
|
+
end
|
49
|
+
|
50
|
+
def to_raw_data
|
51
|
+
"#{part_type}(#{self})"
|
52
|
+
end
|
53
|
+
|
54
|
+
def length
|
55
|
+
@parts.length
|
56
|
+
end
|
57
|
+
|
58
|
+
def rotate_by(number)
|
59
|
+
self.class.new(@parts.rotate(number))
|
60
|
+
end
|
61
|
+
|
62
|
+
def map_rotate_by(number)
|
63
|
+
self.class.new(@parts.map { |p| p.rotate_by(number) })
|
64
|
+
end
|
65
|
+
|
66
|
+
def <=>(other)
|
67
|
+
@parts <=> other.parts
|
68
|
+
end
|
69
|
+
|
70
|
+
def canonicalize
|
71
|
+
@canonicalize ||=
|
72
|
+
@parts.map.with_index do |part, index|
|
73
|
+
min_part = part.rotations.min
|
74
|
+
map_rotate_by_number = part.rotations.index(min_part)
|
75
|
+
rotate_by(index).map_rotate_by(map_rotate_by_number)
|
76
|
+
end.min
|
77
|
+
end
|
78
|
+
|
79
|
+
def equivalent?(other)
|
80
|
+
self == other || canonicalize == other.canonicalize
|
81
|
+
end
|
82
|
+
|
83
|
+
def inverse
|
84
|
+
self.class.new([@parts[0]] + @parts[1..].reverse)
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.from_raw_data(data)
|
88
|
+
raw_part_type, raw_parts = data.match(/(.*)\((.*)\)/).captures
|
89
|
+
part_type = PART_TYPES.find { |p| p.name == raw_part_type }
|
90
|
+
parts = raw_parts.split.map { |r| part_type.parse(r) }
|
91
|
+
new(parts)
|
92
|
+
end
|
93
|
+
|
94
|
+
def check_type_consistency(parts)
|
95
|
+
return unless parts.any? { |p| p.class != parts.first.class }
|
96
|
+
|
97
|
+
raise TypeError, "Cycles of heterogenous piece types #{parts.inspect} are not supported."
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -2,10 +2,11 @@
|
|
2
2
|
|
3
3
|
require 'twisty_puzzles/sticker_cycle'
|
4
4
|
require 'twisty_puzzles/utils/array_helper'
|
5
|
+
require 'twisty_puzzles/cube'
|
5
6
|
|
6
7
|
module TwistyPuzzles
|
7
8
|
# Factory for sticker cycles given part cycles.
|
8
|
-
class
|
9
|
+
class StickerCycleFactory
|
9
10
|
include Utils::ArrayHelper
|
10
11
|
|
11
12
|
def initialize(cube_size, incarnation_index)
|
data/lib/twisty_puzzles.rb
CHANGED
@@ -24,7 +24,7 @@ require 'twisty_puzzles/letter_scheme'
|
|
24
24
|
require 'twisty_puzzles/move_type_creator'
|
25
25
|
require 'twisty_puzzles/native'
|
26
26
|
require 'twisty_puzzles/parser'
|
27
|
-
require 'twisty_puzzles/
|
27
|
+
require 'twisty_puzzles/part_cycle'
|
28
28
|
require 'twisty_puzzles/puzzle'
|
29
29
|
require 'twisty_puzzles/reversible_applyable'
|
30
30
|
require 'twisty_puzzles/rotation'
|
@@ -34,6 +34,7 @@ require 'twisty_puzzles/skewb_move_parser'
|
|
34
34
|
require 'twisty_puzzles/skewb_notation'
|
35
35
|
require 'twisty_puzzles/skewb_state'
|
36
36
|
require 'twisty_puzzles/sticker_cycle'
|
37
|
+
require 'twisty_puzzles/sticker_cycle_factory'
|
37
38
|
require 'twisty_puzzles/twisty_puzzles_error'
|
38
39
|
require 'twisty_puzzles/version'
|
39
40
|
|
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.23
|
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-11-
|
11
|
+
date: 2021-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -224,7 +224,7 @@ files:
|
|
224
224
|
- lib/twisty_puzzles/letter_scheme.rb
|
225
225
|
- lib/twisty_puzzles/move_type_creator.rb
|
226
226
|
- lib/twisty_puzzles/parser.rb
|
227
|
-
- lib/twisty_puzzles/
|
227
|
+
- lib/twisty_puzzles/part_cycle.rb
|
228
228
|
- lib/twisty_puzzles/puzzle.rb
|
229
229
|
- lib/twisty_puzzles/reversible_applyable.rb
|
230
230
|
- lib/twisty_puzzles/rotation.rb
|
@@ -234,6 +234,7 @@ files:
|
|
234
234
|
- lib/twisty_puzzles/skewb_notation.rb
|
235
235
|
- lib/twisty_puzzles/skewb_state.rb
|
236
236
|
- lib/twisty_puzzles/sticker_cycle.rb
|
237
|
+
- lib/twisty_puzzles/sticker_cycle_factory.rb
|
237
238
|
- lib/twisty_puzzles/twisty_puzzles_error.rb
|
238
239
|
- lib/twisty_puzzles/utils.rb
|
239
240
|
- lib/twisty_puzzles/utils/array_helper.rb
|