Class: TwistyPuzzles::SkewbMove
- Inherits:
-
AbstractMove
- Object
- AbstractMove
- TwistyPuzzles::SkewbMove
- Defined in:
- lib/twisty_puzzles/skewb_move.rb
Overview
Base class for skewb moves.
Constant Summary
Constants inherited from AbstractMove
AbstractMove::AXES, AbstractMove::MOVE_METRICS, AbstractMove::SLICE_FACES, AbstractMove::SLICE_NAMES
Instance Attribute Summary collapse
-
#axis_corner ⇒ Object
readonly
Returns the value of attribute axis_corner.
-
#direction ⇒ Object
readonly
Returns the value of attribute direction.
Instance Method Summary collapse
- #identifying_fields ⇒ Object
-
#initialize(axis_corner, direction) ⇒ SkewbMove
constructor
A new instance of SkewbMove.
- #mirror(normal_face) ⇒ Object
- #puzzles ⇒ Object
- #rotate_by(rotation) ⇒ Object
- #slice_move? ⇒ Boolean
- #to_s ⇒ Object
Methods inherited from AbstractMove
#<=>, #can_swap?, check_move_metric, #decide_meaning, #eql?, #equivalent?, #equivalent_internal?, #hash, #identity?, #inverse, #join_with_cancellation, #move_count, #prepend_inner_m_slice_move, #prepend_slice_move, #swap, #swap_internal
Methods included from Utils::ArrayHelper
#apply_permutation, #check_types, #find_only, #only, #replace_once, #rotate_out_nils, #turned_equals?
Methods included from Utils::StringHelper
#camel_case_to_snake_case, #format_time, #simple_class_name, #snake_case_class_name
Constructor Details
#initialize(axis_corner, direction) ⇒ SkewbMove
Returns a new instance of SkewbMove.
11 12 13 14 15 16 17 18 |
# File 'lib/twisty_puzzles/skewb_move.rb', line 11 def initialize(axis_corner, direction) raise TypeError unless axis_corner.is_a?(Corner) raise TypeError unless direction.is_a?(SkewbDirection) super() @axis_corner = axis_corner.rotate_face_up(axis_corner.faces.min_by(&:piece_index)) @direction = direction end |
Instance Attribute Details
#axis_corner ⇒ Object (readonly)
Returns the value of attribute axis_corner.
24 25 26 |
# File 'lib/twisty_puzzles/skewb_move.rb', line 24 def axis_corner @axis_corner end |
#direction ⇒ Object (readonly)
Returns the value of attribute direction.
24 25 26 |
# File 'lib/twisty_puzzles/skewb_move.rb', line 24 def direction @direction end |
Instance Method Details
#identifying_fields ⇒ Object
34 35 36 |
# File 'lib/twisty_puzzles/skewb_move.rb', line 34 def [@axis_corner, @direction] end |
#mirror(normal_face) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/twisty_puzzles/skewb_move.rb', line 51 def mirror(normal_face) faces = @axis_corner.adjacent_faces replaced_face = find_only(faces) { |f| f.same_axis?(normal_face) } new_corner = Corner.between_faces(replace_once(faces, replaced_face, replaced_face.opposite)) self.class.new(new_corner, @direction.inverse) end |
#puzzles ⇒ Object
20 21 22 |
# File 'lib/twisty_puzzles/skewb_move.rb', line 20 def puzzles [Puzzle::SKEWB] end |
#rotate_by(rotation) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/twisty_puzzles/skewb_move.rb', line 38 def rotate_by(rotation) nice_face = find_only(@axis_corner.adjacent_faces) do |f| f.same_axis?(rotation.axis_face) end nice_direction = rotation.translated_direction(nice_face) nice_face_corners = nice_face.clockwise_corners on_nice_face_index = nice_face_corners.index { |c| c.turned_equals?(@axis_corner) } new_corner = nice_face_corners[(on_nice_face_index + nice_direction.value) % nice_face_corners.length] self.class.new(new_corner, @direction) end |
#slice_move? ⇒ Boolean
30 31 32 |
# File 'lib/twisty_puzzles/skewb_move.rb', line 30 def slice_move? false end |
#to_s ⇒ Object
26 27 28 |
# File 'lib/twisty_puzzles/skewb_move.rb', line 26 def to_s "#{@axis_corner}#{@direction.name}" end |