Class: TwistyPuzzles::CompiledCubeAlgorithm

Inherits:
CompiledAlgorithm show all
Defined in:
lib/twisty_puzzles/compiled_cube_algorithm.rb

Overview

Wrapper of the native C implementation of a compiled algorithm for a particular cube size.

Constant Summary collapse

NATIVE_CLASS =
Native::CubeAlgorithm

Instance Attribute Summary

Attributes inherited from CompiledAlgorithm

#inverse, #native

Class Method Summary collapse

Methods inherited from CompiledAlgorithm

#+, #apply_to, #initialize, #mirror, #rotate_by

Methods included from ReversibleApplyable

#apply_temporarily_to, #apply_to_dupped

Constructor Details

This class inherits a constructor from TwistyPuzzles::CompiledAlgorithm

Class Method Details

.for_moves(cube_size, moves) ⇒ Object



58
59
60
61
62
# File 'lib/twisty_puzzles/compiled_cube_algorithm.rb', line 58

def self.for_moves(cube_size, moves)
  transformed_moves = moves.flat_map { |m| transform_move(m, cube_size) }
  native = Native::CubeAlgorithm.new(cube_size, transformed_moves)
  new(native)
end

.transform_move(move, cube_size) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/twisty_puzzles/compiled_cube_algorithm.rb', line 44

def self.transform_move(move, cube_size)
  decided_move = move.decide_meaning(cube_size)
  case decided_move
  when Rotation then transform_rotation(decided_move, cube_size)
  when FatMSliceMove then transform_fat_mslice_move(decided_move, cube_size)
  # Note that this also covers InnerMSliceMove
  when SliceMove then transform_slice_move(decided_move)
  when FatMove then transform_fat_move(decided_move)
  else
    raise TypeError, "Invalid move type #{move.class} that becomes #{decided_move.class} " \
                     "for cube size #{cube_size}."
  end
end