Class: TwistyPuzzles::CompiledAlgorithm

Inherits:
Object
  • Object
show all
Includes:
ReversibleApplyable
Defined in:
lib/twisty_puzzles/compiled_algorithm.rb

Overview

Base class for a compiled algorithm for a particular puzzle.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ReversibleApplyable

#apply_temporarily_to, #apply_to_dupped

Constructor Details

#initialize(native) ⇒ CompiledAlgorithm

Returns a new instance of CompiledAlgorithm.

Raises:

  • (TypeError)


10
11
12
13
14
# File 'lib/twisty_puzzles/compiled_algorithm.rb', line 10

def initialize(native)
  raise TypeError unless native.is_a?(self.class::NATIVE_CLASS)

  @native = native
end

Instance Attribute Details

#inverseObject



26
27
28
29
30
31
32
33
# File 'lib/twisty_puzzles/compiled_algorithm.rb', line 26

def inverse
  @inverse ||=
    begin
      alg = self.class.new(@native.inverse)
      alg.inverse = self
      alg
    end
end

#nativeObject (readonly)

Returns the value of attribute native.



16
17
18
# File 'lib/twisty_puzzles/compiled_algorithm.rb', line 16

def native
  @native
end

Instance Method Details

#+(other) ⇒ Object



35
36
37
# File 'lib/twisty_puzzles/compiled_algorithm.rb', line 35

def +(other)
  self.class.new(@native + other.native)
end

#apply_to(state) ⇒ Object



39
40
41
# File 'lib/twisty_puzzles/compiled_algorithm.rb', line 39

def apply_to(state)
  @native.apply_to(state.native)
end

#mirror(normal_face) ⇒ Object



22
23
24
# File 'lib/twisty_puzzles/compiled_algorithm.rb', line 22

def mirror(normal_face)
  self.class.new(@native.mirror(normal_face.face_symbol))
end

#rotate_by(rotation) ⇒ Object



18
19
20
# File 'lib/twisty_puzzles/compiled_algorithm.rb', line 18

def rotate_by(rotation)
  self.class.new(@native.rotate_by(rotation.axis_face.face_symbol, rotation.direction.value))
end