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 +4 -4
- data/lib/twisty_puzzles/algorithm.rb +3 -1
- data/lib/twisty_puzzles/cancellation_helper.rb +2 -2
- data/lib/twisty_puzzles/color_scheme.rb +1 -1
- data/lib/twisty_puzzles/coordinate.rb +4 -0
- data/lib/twisty_puzzles/cube.rb +3 -5
- data/lib/twisty_puzzles/part_cycle.rb +38 -2
- data/lib/twisty_puzzles/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: fa3e196d509ec1452a947269c43028b2ee5e3be803f4d3bf510ef5c170d01310
         | 
| 4 | 
            +
              data.tar.gz: 704d10067e79b8d78e3eb5367795200695d4445a44873d198936136568ddc3e4
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 197fc8e07f87b42434f8b126fa9fdcec56a5a47f883d7faf892aecf9c440e01d97c991f15734bdfdda42ee95ca78660f2da7cde1d165c37f2613218532894361
         | 
| 7 | 
            +
              data.tar.gz: 840a076a049ef64a39c82e4b8f6f9721d71be47bc8a232c278bd7f2cc67bd564e2f4dd566b59d1db14582ec6be2a6b4cc6c6001d2eafe51bcb7ce5335dda3bf9
         | 
| @@ -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 | 
| 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 | 
| 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
         | 
    
        data/lib/twisty_puzzles/cube.rb
    CHANGED
    
    | @@ -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 | 
| 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 | 
            -
                   | 
| 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,  | 
| 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 | 
| 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
         | 
    
        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.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 | 
            +
            date: 2021-12-06 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: colorize
         |