Class: RubiksCube::Solution

Inherits:
Object
  • Object
show all
Defined in:
lib/rubiks_cube/solution.rb

Overview

Abstract interface for a RubiksCube solution

Must implement:

solution: array or string of moves necessary to solve the cube
pretty:   human readable string of solution

Direct Known Subclasses

TwoCycleSolution

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cube) ⇒ Solution

Returns a new instance of Solution.



20
21
22
# File 'lib/rubiks_cube/solution.rb', line 20

def initialize(cube)
  @cube = Cube.new(cube.state)
end

Instance Attribute Details

#cubeObject (readonly)

Returns the value of attribute cube.



8
9
10
# File 'lib/rubiks_cube/solution.rb', line 8

def cube
  @cube
end

Instance Method Details

#lengthObject



32
33
34
# File 'lib/rubiks_cube/solution.rb', line 32

def length
  Array(solution).flatten.join(' ').split.count
end

#prettyObject

Human readable string of solution



16
17
18
# File 'lib/rubiks_cube/solution.rb', line 16

def pretty
  raise "#pretty unimplemented in #{self.class.name}"
end

#solutionObject

Array or String of moves necessary to solve the cube



11
12
13
# File 'lib/rubiks_cube/solution.rb', line 11

def solution
  raise "#solution unimplemented in #{self.class.name}"
end

#solved?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/rubiks_cube/solution.rb', line 28

def solved?
  cube.solved?
end

#stateObject



24
25
26
# File 'lib/rubiks_cube/solution.rb', line 24

def state
  cube.state
end