Class: Scrambler::RandomState::CornerPermutation

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

Instance Method Summary collapse

Constructor Details

#initialize(permutation = [0, 1, 2, 3, 4, 5, 6]) ⇒ CornerPermutation

Returns a new instance of CornerPermutation.



4
5
6
7
8
9
10
11
# File 'lib/scrambler/random_state/corner_permutation.rb', line 4

def initialize(permutation = [0, 1, 2, 3, 4, 5, 6])
  case permutation
  when Array
    @permutation = permutation.clone
  else
    @permutation = convert_to_array(permutation)
  end
end

Instance Method Details

#to_aObject



13
14
15
# File 'lib/scrambler/random_state/corner_permutation.rb', line 13

def to_a
  @permutation
end

#to_iObject



17
18
19
20
21
# File 'lib/scrambler/random_state/corner_permutation.rb', line 17

def to_i
  @permutation.map do |piece|
    piece.to_s
  end.join.to_i
end

#turn!(move) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/scrambler/random_state/corner_permutation.rb', line 23

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