twisty_puzzles 0.0.35 → 0.0.36

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: 66e7a9b86d8d381b95a5f8f81736ce6df3bf121742c5b802dc1197f587ff064b
4
- data.tar.gz: 21d10876ef99087df6e243a9b405c5272e74a13601fd71a3389a11a2c225905c
3
+ metadata.gz: df8607246caad9c85160d9691c18310413ce77ea95281587b100c209e4e52f49
4
+ data.tar.gz: d4139596d095f04fc35f1acbd4e6a9c37f7d645ec6592b9326c8404dab016e08
5
5
  SHA512:
6
- metadata.gz: fa1def58113526fa40421e30650da8fcd5f136947405697fa04e2c62278a618f9efdb7ce7b1a22979e3794aa8e59a9f2b1e2d723627e09567d16adb58fe6c3dd
7
- data.tar.gz: 95af3315c8fa3036780b9fe70abd2dd1b7afabe42a04c2373a791f3da401f7be1d7dde5ba3201c68b69b25ba7904955496c07855faee617c67367781b4f4b2db
6
+ metadata.gz: 175d6f08ae032973a21dbd40846940cad500648c9a36642b7046f6e9732685dc018e756b30359bdbe92210e97a3d576970f6c76a11238a7baccb45757c1b1616
7
+ data.tar.gz: 87e69dbce166cdca251ae02b66cbeabbe903016cd0582d0a293058023d455578888c8cb658f9350e73972b6aa1584d1c6cc3aa2d2645eaa03e49746e3b838fed
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
- ![Ruby](https://github.com/Lykos/twisty_puzzles/workflows/Ruby/badge.svg)
2
- ![Rubocop](https://github.com/Lykos/twisty_puzzles/workflows/Rubocop/badge.svg)
1
+ [![Ruby](https://github.com/Lykos/twisty_puzzles/workflows/Ruby/badge.svg)](https://github.com/Lykos/twisty_puzzles/actions/workflows/ruby.yml)
2
+ [![Rubocop](https://github.com/Lykos/twisty_puzzles/workflows/Rubocop/badge.svg)](https://github.com/Lykos/twisty_puzzles/actions/workflows/rubocop.yml)
3
+ [![cpp-linter](https://github.com/Lykos/twisty_puzzles/workflows/c-linter/badge.svg)](https://github.com/Lykos/twisty_puzzles/actions/workflows/clinter.yml)
3
4
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
5
  [![Gem Version](https://badge.fury.io/rb/twisty_puzzles.svg)](https://badge.fury.io/rb/twisty_puzzles)
5
6
 
@@ -2,4 +2,5 @@
2
2
 
3
3
  #include <ruby.h>
4
4
 
5
+ // TODO: Deprecate
5
6
  void init_sticker_cycle_class_under(VALUE module);
@@ -23,7 +23,7 @@ module TwistyPuzzles
23
23
  end
24
24
 
25
25
  def hash
26
- @hash ||= ([self.class] + identifying_fields).hash
26
+ @hash ||= [self.class, identifying_fields].hash
27
27
  end
28
28
 
29
29
  def eql?(other)
@@ -21,11 +21,11 @@ module TwistyPuzzles
21
21
 
22
22
  def parse_named_captures(match)
23
23
  present_named_captures = match.named_captures.compact
24
- present_named_captures.map do |name, string|
24
+ present_named_captures.to_h do |name, string|
25
25
  key = parse_part_key(name).to_sym
26
26
  value = parse_move_part(name, string)
27
27
  [key, value]
28
- end.to_h
28
+ end
29
29
  end
30
30
 
31
31
  def parse_move(move_string)
@@ -38,7 +38,7 @@ module TwistyPuzzles
38
38
  alias == eql?
39
39
 
40
40
  def hash
41
- @hash ||= ([self.class] + @moves).hash
41
+ @hash ||= [self.class, @moves].hash
42
42
  end
43
43
 
44
44
  def length
@@ -111,9 +111,9 @@ module TwistyPuzzles
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
114
- rotation_algs.map do |alg|
114
+ rotation_algs.to_h do |alg|
115
115
  [rotated_center_state(alg.moves), alg]
116
- end.to_h.freeze
116
+ end.freeze
117
117
  end
118
118
  end
119
119
 
@@ -35,7 +35,7 @@ module TwistyPuzzles
35
35
  alias == eql?
36
36
 
37
37
  def hash
38
- @hash ||= ([self.class] + colors).hash
38
+ @hash ||= [self.class, colors].hash
39
39
  end
40
40
 
41
41
  def color(face_symbol)
@@ -167,9 +167,10 @@ module TwistyPuzzles
167
167
 
168
168
  def obvious_turned_face_symbols_to_colors(top_color, front_color)
169
169
  result = { U: top_color, F: front_color }
170
- opposites = result.map do |face_symbol, color|
171
- [opposite_face_symbol(face_symbol), opposite_color(color)]
172
- end.to_h
170
+ opposites =
171
+ result.to_h do |face_symbol, color|
172
+ [opposite_face_symbol(face_symbol), opposite_color(color)]
173
+ end
173
174
  result.merge!(opposites)
174
175
  end
175
176
 
@@ -19,7 +19,7 @@ module TwistyPuzzles
19
19
  # Algorithm that is used like a commutator but actually isn't one.
20
20
  class FakeCommutator < Commutator
21
21
  def initialize(algorithm)
22
- raise ArgumentError unless algorithm.is_a?(Algorithm)
22
+ raise TypeError unless algorithm.is_a?(Algorithm)
23
23
 
24
24
  super()
25
25
  @algorithm = algorithm
@@ -46,11 +46,45 @@ module TwistyPuzzles
46
46
  end
47
47
  end
48
48
 
49
+ # A commutator sequence of the form [A, B] + [C, D].
50
+ class CommutatorSequence < Commutator
51
+ def initialize(commutators)
52
+ raise TypeError unless commutators.is_a?(Array) && commutators.all?(Commutator)
53
+
54
+ super()
55
+ @commutators = commutators
56
+ end
57
+
58
+ attr_reader :commutators
59
+
60
+ def eql?(other)
61
+ self.class.equal?(other.class) && @commutators == other.commutators
62
+ end
63
+
64
+ alias == eql?
65
+
66
+ def hash
67
+ @hash ||= [self.class, @commutators].hash
68
+ end
69
+
70
+ def inverse
71
+ CommutatorSequence.new(@commutators.map(&:inverse).reverse)
72
+ end
73
+
74
+ def to_s
75
+ @commutators.join(' + ')
76
+ end
77
+
78
+ def algorithm
79
+ @commutators.map(&:algorithm).reduce(:+, Algorithm.empty)
80
+ end
81
+ end
82
+
49
83
  # Pure commutator of the form A B A' B'.
50
84
  class PureCommutator < Commutator
51
85
  def initialize(first_part, second_part)
52
- raise ArgumentError unless first_part.is_a?(Algorithm)
53
- raise ArgumentError unless second_part.is_a?(Algorithm)
86
+ raise TypeError unless first_part.is_a?(Algorithm)
87
+ raise TypeError unless second_part.is_a?(Algorithm)
54
88
 
55
89
  super()
56
90
  @first_part = first_part
@@ -101,9 +135,9 @@ module TwistyPuzzles
101
135
  # Setup commutator of the form A B A'.
102
136
  class SetupCommutator < Commutator
103
137
  def initialize(setup, inner_commutator)
104
- raise ArgumentError, 'Setup move has to be an algorithm.' unless setup.is_a?(Algorithm)
138
+ raise TypeError, 'Setup move has to be an algorithm.' unless setup.is_a?(Algorithm)
105
139
  unless inner_commutator.is_a?(Commutator)
106
- raise ArgumentError, 'Inner commutator has to be a commutator.'
140
+ raise TypeError, 'Inner commutator has to be a commutator.'
107
141
  end
108
142
 
109
143
  super()
@@ -35,7 +35,7 @@ module TwistyPuzzles
35
35
  end
36
36
 
37
37
  def self.create_stickers_hash(stickers)
38
- FACE_SYMBOLS.zip(stickers).map do |face_symbol, face_stickers|
38
+ FACE_SYMBOLS.zip(stickers).to_h do |face_symbol, face_stickers|
39
39
  face = Face.for_face_symbol(face_symbol)
40
40
  face_hash = {
41
41
  stickers: face_stickers,
@@ -46,7 +46,7 @@ module TwistyPuzzles
46
46
  y_base_face_symbol: face.coordinate_index_base_face(0).face_symbol
47
47
  }
48
48
  [face_symbol, face_hash]
49
- end.to_h
49
+ end
50
50
  end
51
51
 
52
52
  def initialize(native)
@@ -11,13 +11,14 @@ module TwistyPuzzles # rubocop:disable Style/Documentation
11
11
  end
12
12
 
13
13
  # Parser for commutators and algorithms.
14
- class Parser
14
+ class Parser # rubocop:disable Metrics/ClassLength
15
15
  OPENING_BRACKET = '['
16
16
  OPENING_PAREN = '('
17
17
  CLOSING_BRACKET = ']'
18
18
  CLOSING_PAREN = ')'
19
19
  SLASH = '/'
20
20
  COMMA = ','
21
+ PLUS = '+'
21
22
  SETUP_SEPARATORS = %w[; :].freeze
22
23
  PURE_SEPARATORS = [SLASH, COMMA].freeze
23
24
  SEPARATORS = (SETUP_SEPARATORS + PURE_SEPARATORS).freeze
@@ -141,6 +142,8 @@ module TwistyPuzzles # rubocop:disable Style/Documentation
141
142
  separator = parse_separator
142
143
  comm = parse_commutator_internal_after_separator(setup_or_first_part, separator)
143
144
  skip_spaces
145
+ return parse_commutator_sum_with_prefix(comm) if @scanner.peek(1) == PLUS
146
+
144
147
  complain('end of commutator') unless @scanner.eos?
145
148
  comm
146
149
  end
@@ -230,10 +233,23 @@ module TwistyPuzzles # rubocop:disable Style/Documentation
230
233
  skip_spaces
231
234
  parse_close_bracket
232
235
  skip_spaces
236
+ return parse_commutator_sum_with_prefix(comm) if @scanner.peek(1) == PLUS
237
+
233
238
  complain('end of commutator') unless @scanner.eos?
234
239
  comm
235
240
  end
236
241
 
242
+ def parse_plus
243
+ complain('operator of commutator sequence') unless @scanner.getch == PLUS
244
+ end
245
+
246
+ def parse_commutator_sum_with_prefix(commutator)
247
+ skip_spaces
248
+ parse_plus
249
+ skip_spaces
250
+ CommutatorSequence.new([commutator, parse_commutator])
251
+ end
252
+
237
253
  def parse_move_internal
238
254
  move = @scanner.scan(@move_parser.regexp)
239
255
  return unless move
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TwistyPuzzles
4
- VERSION = '0.0.35'
4
+ VERSION = '0.0.36'
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.35
4
+ version: 0.0.36
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernhard F. Brodowsky
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-30 00:00:00.000000000 Z
11
+ date: 2022-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -164,7 +164,7 @@ dependencies:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
- description:
167
+ description:
168
168
  email: bernhard.brodowsky@gmail.com
169
169
  executables: []
170
170
  extensions:
@@ -247,7 +247,8 @@ metadata:
247
247
  homepage_uri: https://github.com/Lykos/twisty_puzzles
248
248
  source_code_uri: https://github.com/Lykos/twisty_puzzles
249
249
  changelog_uri: https://github.com/Lykos/twisty_puzzles/blob/master/CHANGELOG.md
250
- post_install_message:
250
+ rubygems_mfa_required: 'true'
251
+ post_install_message:
251
252
  rdoc_options: []
252
253
  require_paths:
253
254
  - lib
@@ -263,7 +264,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
263
264
  version: '0'
264
265
  requirements: []
265
266
  rubygems_version: 3.2.22
266
- signing_key:
267
+ signing_key:
267
268
  specification_version: 4
268
269
  summary: Gem for my cube_trainer rails app. Some things are better left in a separate
269
270
  gem with no rails, e.g. native extensions. The main purpose is to support my Rails