Class: Scrambler::RandomState::CornerOrientation
- Inherits:
-
Object
- Object
- Scrambler::RandomState::CornerOrientation
- Defined in:
- lib/scrambler/random_state/corner_orientation.rb
Instance Method Summary collapse
-
#initialize(orientation = [0] * 7) ⇒ CornerOrientation
constructor
A new instance of CornerOrientation.
- #to_a ⇒ Object
- #to_i ⇒ Object
- #turn!(move) ⇒ Object
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_a ⇒ Object
20 21 22 |
# File 'lib/scrambler/random_state/corner_orientation.rb', line 20 def to_a @orientation end |
#to_i ⇒ Object
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 |