Class: Scrambler::RandomState::TwoByTwo

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

Instance Method Summary collapse

Constructor Details

#initializeTwoByTwo

Returns a new instance of TwoByTwo.



8
9
10
# File 'lib/scrambler/random_state/two_by_two.rb', line 8

def initialize
  @solver = Solver.new
end

Instance Method Details

#scrambleObject



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

def scramble
  permutation = Solver::SOLVED_PERMUTATION.shuffle
  orientation = Array.new(6) { rand 3 }
  orientation += [(3 - (orientation.inject { |sum, i| sum + i } % 3)) % 3] # fix orientation parity

  @solver.solve(CornerPermutation.new(permutation), CornerOrientation.new(orientation))
end