twisty_puzzles 0.0.22 → 0.0.26

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b027980f0003ca98c1c331bf442b3ac511a0e3bdc6bf68df6a1cb863b7a7d0a1
4
- data.tar.gz: c1ad15aef159ebe5fb99dd0a7fc299d88fd88ecdc0418a7e730150a3d5dc8448
3
+ metadata.gz: fa3e196d509ec1452a947269c43028b2ee5e3be803f4d3bf510ef5c170d01310
4
+ data.tar.gz: 704d10067e79b8d78e3eb5367795200695d4445a44873d198936136568ddc3e4
5
5
  SHA512:
6
- metadata.gz: 10035a7afbb795b610d2e6c9408d86a13606327ba934c9a0e044a10fe316efa32eb25da74a3244d4762e8083aa0334b5e40f19cc6bbed9b1f0660b70e1df9122
7
- data.tar.gz: 67434787b689f5466a66ff202d5a0da06c7d92c051f836ef3c09e638e9d82d9475b4e2f79089062561508da9dcc3f2025fcab1818aab5f891a7416e43ac2c56d
6
+ metadata.gz: 197fc8e07f87b42434f8b126fa9fdcec56a5a47f883d7faf892aecf9c440e01d97c991f15734bdfdda42ee95ca78660f2da7cde1d165c37f2613218532894361
7
+ data.tar.gz: 840a076a049ef64a39c82e4b8f6f9721d71be47bc8a232c278bd7f2cc67bd564e2f4dd566b59d1db14582ec6be2a6b4cc6c6001d2eafe51bcb7ce5335dda3bf9
@@ -20,7 +20,9 @@ module TwistyPuzzles
20
20
  @moves = moves
21
21
  end
22
22
 
23
- EMPTY = Algorithm.new([])
23
+ def self.empty
24
+ Algorithm.new([])
25
+ end
24
26
 
25
27
  # Creates a one move algorithm.
26
28
  def self.move(move)
@@ -43,7 +43,7 @@ module TwistyPuzzles
43
43
  raise TypeError unless algorithm.is_a?(Algorithm)
44
44
 
45
45
  CubeState.check_cube_size(cube_size)
46
- alg = Algorithm::EMPTY
46
+ alg = Algorithm.empty
47
47
  algorithm.moves.each do |m|
48
48
  alg = push_with_cancellation(alg, m, cube_size)
49
49
  end
@@ -107,7 +107,7 @@ module TwistyPuzzles
107
107
  def self.rotation_sequences
108
108
  @rotation_sequences ||=
109
109
  begin
110
- trivial_rotation_algs = [Algorithm::EMPTY]
110
+ trivial_rotation_algs = [Algorithm.empty]
111
111
  single_rotation_algs = Rotation::NON_ZERO_ROTATIONS.map { |e| Algorithm.move(e) }
112
112
  combined_rotation_algs = self.combined_rotation_algs
113
113
  rotation_algs = trivial_rotation_algs + single_rotation_algs + combined_rotation_algs
@@ -57,7 +57,7 @@ module TwistyPuzzles
57
57
  end
58
58
 
59
59
  def colors
60
- @face_symbols_to_colors.values
60
+ @face_symbols_to_colors.to_a.sort_by(&:first).map(&:last)
61
61
  end
62
62
 
63
63
  def turned(top_color, front_color)
@@ -173,6 +173,10 @@ module TwistyPuzzles
173
173
  @native = native
174
174
  end
175
175
 
176
+ def to_s
177
+ "#{self.class}(#{face}, #{cube_size}, #{x}, #{y})"
178
+ end
179
+
176
180
  attr_reader :native
177
181
 
178
182
  def face
@@ -286,7 +286,7 @@ module TwistyPuzzles
286
286
  # lie where the given other face currently is.
287
287
  def rotation_to(other)
288
288
  if other == self
289
- Algorithm::EMPTY
289
+ Algorithm.empty
290
290
  else
291
291
  # There can be multiple solutions.
292
292
  axis_face =
@@ -470,7 +470,6 @@ module TwistyPuzzles
470
470
  # Represents one wing or the position of one wing on the cube.
471
471
  class Wing < Part
472
472
  extend EdgeLike
473
- WING_BASE_INDEX_INVERTED_FACE_SYMBOLS = %i[U R B].freeze
474
473
  FACES = 2
475
474
 
476
475
  ELEMENTS = generate_parts
@@ -543,8 +542,7 @@ module TwistyPuzzles
543
542
 
544
543
  # One index of such a piece on a on a NxN face.
545
544
  def base_index_on_other_face(face, _cube_size, incarnation_index)
546
- # TODO: Make this more elegant than hardcoding
547
- inverse = WING_BASE_INDEX_INVERTED_FACE_SYMBOLS.include?(face.face_symbol)
545
+ inverse = face.piece_index.even?
548
546
  coordinates = [0, 1 + incarnation_index]
549
547
  inverse ? coordinates.reverse : coordinates
550
548
  end
@@ -675,5 +673,5 @@ module TwistyPuzzles
675
673
 
676
674
  # TODO: Add obliques
677
675
 
678
- PART_TYPES = [Corner, Edge, XCenter, TCenter, Face, Edge, Midge, Wing].freeze
676
+ PART_TYPES = [Corner, Edge, XCenter, TCenter, Face, Midge, Wing].freeze
679
677
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'twisty_puzzles/utils/array_helper'
4
+ require 'twisty_puzzles/utils/string_helper'
4
5
  require 'twisty_puzzles/sticker_cycle_factory'
5
6
  require 'twisty_puzzles/cube'
6
7
 
@@ -11,6 +12,8 @@ module TwistyPuzzles
11
12
  # Check StickerCycleFactory for making it concrete and applyable.
12
13
  class PartCycle
13
14
  include Utils::ArrayHelper
15
+ include Utils::StringHelper
16
+ extend Utils::StringHelper
14
17
 
15
18
  RAW_DATA_RESERVED = [' ', '(', ')'].freeze
16
19
 
@@ -39,21 +42,54 @@ module TwistyPuzzles
39
42
  @parts.first.class
40
43
  end
41
44
 
45
+ def contains_any_part?(parts)
46
+ !(@parts & parts).empty?
47
+ end
48
+
42
49
  def to_s
43
50
  @parts.join(' ')
44
51
  end
45
52
 
46
53
  def to_raw_data
47
- "#{part_type}(#{self})"
54
+ "#{simple_class_name(part_type)}(#{self})"
48
55
  end
49
56
 
50
57
  def length
51
58
  @parts.length
52
59
  end
53
60
 
61
+ def rotate_by(number)
62
+ self.class.new(@parts.rotate(number))
63
+ end
64
+
65
+ def map_rotate_by(number)
66
+ self.class.new(@parts.map { |p| p.rotate_by(number) })
67
+ end
68
+
69
+ def <=>(other)
70
+ @parts <=> other.parts
71
+ end
72
+
73
+ def canonicalize
74
+ @canonicalize ||=
75
+ @parts.map.with_index do |part, index|
76
+ min_part = part.rotations.min
77
+ map_rotate_by_number = part.rotations.index(min_part)
78
+ rotate_by(index).map_rotate_by(map_rotate_by_number)
79
+ end.min
80
+ end
81
+
82
+ def equivalent?(other)
83
+ self == other || canonicalize == other.canonicalize
84
+ end
85
+
86
+ def inverse
87
+ self.class.new([@parts[0]] + @parts[1..].reverse)
88
+ end
89
+
54
90
  def self.from_raw_data(data)
55
91
  raw_part_type, raw_parts = data.match(/(.*)\((.*)\)/).captures
56
- part_type = PART_TYPES.find { |p| p.name == raw_part_type }
92
+ part_type = PART_TYPES.find { |p| simple_class_name(p) == raw_part_type }
57
93
  parts = raw_parts.split.map { |r| part_type.parse(r) }
58
94
  new(parts)
59
95
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TwistyPuzzles
4
- VERSION = '0.0.22'
4
+ VERSION = '0.0.26'
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.22
4
+ version: 0.0.26
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-09 00:00:00.000000000 Z
11
+ date: 2021-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize