Module: TwistyPuzzles::CubeConstants
- Includes:
- Utils::ArrayHelper
- Included in:
- CancellationHelper, ColorScheme, CubeState, Part, Part, SkewbCoordinate, SkewbState
- Defined in:
- lib/twisty_puzzles/cube_constants.rb
Overview
Various constants about the cube.
Constant Summary collapse
- FACE_SYMBOLS =
The order determines the priority of the faces.
%i[U F R L B D].freeze
- OPPOSITE_FACE_SYMBOLS =
[%i[U D], %i[F B], %i[R L]].freeze
- FACE_NAMES =
FACE_SYMBOLS.map(&:to_s).freeze
- ALPHABET_SIZE =
24
- SKEWB_STICKERS =
Stickers on each Skewb face.
5
- CHIRALITY_FACE_SYMBOLS =
%i[U R F].freeze
Instance Method Summary collapse
- #chirality_canonical_face_symbol(face_symbol) ⇒ Object
- #opposite_face_symbol(face_symbol) ⇒ Object
- #valid_chirality?(face_symbols) ⇒ Boolean
Methods included from Utils::ArrayHelper
#apply_permutation, #check_types, #find_only, #only, #replace_once, #rotate_out_nils, #turned_equals?
Instance Method Details
#chirality_canonical_face_symbol(face_symbol) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/twisty_puzzles/cube_constants.rb', line 29 def chirality_canonical_face_symbol(face_symbol) if CHIRALITY_FACE_SYMBOLS.include?(face_symbol) face_symbol else opposite_face_symbol(face_symbol) end end |
#opposite_face_symbol(face_symbol) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/twisty_puzzles/cube_constants.rb', line 21 def opposite_face_symbol(face_symbol) candidates = OPPOSITE_FACE_SYMBOLS.select { |ss| ss.include?(face_symbol) } raise if candidates.length > 1 raise ArgumentError, "Invalid face symbol #{face_symbol}." if candidates.empty? only(only(candidates).reject { |s| s == face_symbol }) end |
#valid_chirality?(face_symbols) ⇒ Boolean
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/twisty_puzzles/cube_constants.rb', line 37 def valid_chirality?(face_symbols) # To make it comparable to our CHIRALITY_FACE_SYMBOLS, we switch each face used in c # different from the ones used in the CHIRALITY_FACE_SYMBOLS for the opposite face. canonical_face_symbols = face_symbols.map { |f| chirality_canonical_face_symbol(f) } # Each time we swap a face for the opposite, the chirality direction should be inverted. no_swapped_face_symbols = canonical_face_symbols.zip(face_symbols).count { |a, b| a != b } inverted = no_swapped_face_symbols.odd? inverted_face_symbols = inverted ? canonical_face_symbols.reverse : canonical_face_symbols # If the corner is not equal modulo rotation to CHIRALITY_FACE_SYMBOLS after this # transformation, the original corner had a bad chirality. turned_equals?(inverted_face_symbols, CHIRALITY_FACE_SYMBOLS) end |