twisty_puzzles 0.0.24 → 0.0.28

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: 3890521ee97a60869d26b02813cd151f663c41c8df2be9c43f3c1feeb753da33
4
- data.tar.gz: 62b7ce3c679d64c2540c82376ce793e858f08dbd8f36382af54919bb0f5c4887
3
+ metadata.gz: 7843aac67563062698ede8d6de86b76153901bcccee07d3367863ef9e81096d4
4
+ data.tar.gz: 4fe82e4186f3c832c502279748b27310658da80b057c9ff99ce22f5b04c46308
5
5
  SHA512:
6
- metadata.gz: 76e7431b9aadae1764e84aa94163c78dbff203f80a21acfa9a4f19a03f916f899ca751d2c1c78a6b0514722bb14ee9a3e53f6fc87fd7a69c4e6b67ef301415cb
7
- data.tar.gz: 60d7bdbb9101ca596e85fbad048eff6efc826dc03ba300006d818c5767b361d7ef7e673e48e7113a31f9cf31040adc2f47e62e4345eeaa900564570b0e19461a
6
+ metadata.gz: 1df3581ec635a06f6c0ef9221a518d5174fbfa4b30e7439f27e2c3ff1b185141d7dd5e86a979c9b66610af5b21d6564f61ae8b93909e43c7e2b79976f4c3333d
7
+ data.tar.gz: cc0899a42896b078a423fb511f61b63dc3f9a327824a0a68d9cfce17857cffaa7f5288a15629ab527e6c0ebb3257ce026c139028b008dec1699fcbdb61fa02ed
@@ -4,7 +4,7 @@ module TwistyPuzzles
4
4
  # Base class for directions.
5
5
  class AbstractDirection
6
6
  include Comparable
7
- POSSIBLE_DIRECTION_NAMES = [[''], ['2', '2\''], ['\'', '3', '’']].freeze
7
+ POSSIBLE_DIRECTION_NAMES = [[''], ['2', '2\''], ['\'', '3', '’', '‘', '´', '`']].freeze
8
8
  SIMPLE_DIRECTION_NAMES = (['0'] + POSSIBLE_DIRECTION_NAMES.map(&:first)).freeze
9
9
  POSSIBLE_SKEWB_DIRECTION_NAMES = [['', '2\''], ['\'', '2']].freeze
10
10
  SIMPLE_SKEWB_DIRECTION_NAMES = (['0'] + POSSIBLE_SKEWB_DIRECTION_NAMES.map(&:first)).freeze
@@ -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
@@ -72,6 +72,11 @@ module TwistyPuzzles
72
72
  true
73
73
  end
74
74
 
75
+ def self.exists_on_cube_size?(cube_size)
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?)
78
+ end
79
+
75
80
  def num_incarnations(_cube_size)
76
81
  1
77
82
  end
@@ -286,7 +291,7 @@ module TwistyPuzzles
286
291
  # lie where the given other face currently is.
287
292
  def rotation_to(other)
288
293
  if other == self
289
- Algorithm::EMPTY
294
+ Algorithm.empty
290
295
  else
291
296
  # There can be multiple solutions.
292
297
  axis_face =
@@ -470,7 +475,6 @@ module TwistyPuzzles
470
475
  # Represents one wing or the position of one wing on the cube.
471
476
  class Wing < Part
472
477
  extend EdgeLike
473
- WING_BASE_INDEX_INVERTED_FACE_SYMBOLS = %i[U R B].freeze
474
478
  FACES = 2
475
479
 
476
480
  ELEMENTS = generate_parts
@@ -479,10 +483,6 @@ module TwistyPuzzles
479
483
  4
480
484
  end
481
485
 
482
- def self.exists_on_odd_cube_sizes?
483
- false
484
- end
485
-
486
486
  def self.max_parseable_face_symbols
487
487
  FACES + 1
488
488
  end
@@ -543,8 +543,7 @@ module TwistyPuzzles
543
543
 
544
544
  # One index of such a piece on a on a NxN face.
545
545
  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)
546
+ inverse = face.piece_index.even?
548
547
  coordinates = [0, 1 + incarnation_index]
549
548
  inverse ? coordinates.reverse : coordinates
550
549
  end
@@ -13,6 +13,7 @@ module TwistyPuzzles
13
13
  class PartCycle
14
14
  include Utils::ArrayHelper
15
15
  include Utils::StringHelper
16
+ extend Utils::StringHelper
16
17
 
17
18
  RAW_DATA_RESERVED = [' ', '(', ')'].freeze
18
19
 
@@ -78,6 +79,21 @@ module TwistyPuzzles
78
79
  end.min
79
80
  end
80
81
 
82
+ # Note that this returns the same answer for all rotations of one part.
83
+ def contains?(part)
84
+ @parts.any? { |p| p.turned_equals?(part) }
85
+ end
86
+
87
+ # Returns an equivalent cycle that starts with the given part.
88
+ # Raises an error if the cycle doesn't contain the given part.
89
+ def start_with(part)
90
+ raise ArgumentError unless contains?(part)
91
+
92
+ index = @parts.find_index { |p| p.turned_equals?(part) }
93
+ map_rotate_by_number = @parts[index].rotations.index(part)
94
+ rotate_by(@parts.length - index).map_rotate_by(map_rotate_by_number)
95
+ end
96
+
81
97
  def equivalent?(other)
82
98
  self == other || canonicalize == other.canonicalize
83
99
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TwistyPuzzles
4
- VERSION = '0.0.24'
4
+ VERSION = '0.0.28'
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.24
4
+ version: 0.0.28
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-10 00:00:00.000000000 Z
11
+ date: 2021-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize