Class: Scrambler::RandomState::CornerOrientation

Inherits:
Object
  • Object
show all
Defined in:
lib/scrambler/random_state/corner_orientation.rb

Instance Method Summary collapse

Constructor Details

#initialize(orientation = [0] * 7) ⇒ CornerOrientation

Returns a new instance of CornerOrientation.



11
12
13
14
15
16
17
18
# File 'lib/scrambler/random_state/corner_orientation.rb', line 11

def initialize(orientation = [0] * 7)
  case orientation
  when Array
    @orientation = orientation.clone
  else
    @orientation = convert_to_array orientation
  end
end

Instance Method Details

#to_aObject



20
21
22
# File 'lib/scrambler/random_state/corner_orientation.rb', line 20

def to_a
  @orientation
end

#to_iObject



24
25
26
27
# File 'lib/scrambler/random_state/corner_orientation.rb', line 24

def to_i
  n = -1
  @orientation.inject(0) { |sum, i| n += 1; sum + i * (3**n) }
end

#turn!(move) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/scrambler/random_state/corner_orientation.rb', line 29

def turn!(move)
  o = @orientation
  case move
  when :R
    @orientation = [(o[1] + 1) % 3, (o[5] + 2) % 3, o[2], o[3], (o[0] + 2) % 3, (o[4] + 1) % 3, o[6]]
  when :F
    @orientation = [o[0], (o[2] + 1) % 3, (o[6] + 2) % 3, o[3], o[4], (o[1] + 2) % 3, (o[5] + 1) % 3]
  when :U
    @orientation = [o[3], o[0], o[1], o[2], o[4], o[5], o[6]]
  end
  self
end