Class: TwistyPuzzles::AxisFaceAndDirectionMove
- Inherits:
-
AbstractMove
- Object
- AbstractMove
- TwistyPuzzles::AxisFaceAndDirectionMove
- Defined in:
- lib/twisty_puzzles/axis_face_and_direction_move.rb
Overview
Intermediate base class for all types of moves that have an axis face and a direction, i.e. cube moves and rotations.
Constant Summary
Constants inherited from AbstractMove
TwistyPuzzles::AbstractMove::AXES, TwistyPuzzles::AbstractMove::MOVE_METRICS, TwistyPuzzles::AbstractMove::SLICE_FACES, TwistyPuzzles::AbstractMove::SLICE_NAMES
Instance Attribute Summary collapse
-
#axis_face ⇒ Object
readonly
Returns the value of attribute axis_face.
-
#direction ⇒ Object
readonly
Returns the value of attribute direction.
Instance Method Summary collapse
- #can_swap?(other) ⇒ Boolean
- #canonical_direction ⇒ Object
- #identifying_fields ⇒ Object
-
#initialize(axis_face, direction) ⇒ AxisFaceAndDirectionMove
constructor
A new instance of AxisFaceAndDirectionMove.
- #mirror(normal_face) ⇒ Object
- #rotate_by(rotation) ⇒ Object
- #same_axis?(other) ⇒ Boolean
- #swap_internal(other) ⇒ Object
- #translated_direction(other_axis_face) ⇒ Object
Methods inherited from AbstractMove
#<=>, 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, #puzzles, #slice_move?, #swap
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_face, direction) ⇒ AxisFaceAndDirectionMove
Returns a new instance of AxisFaceAndDirectionMove.
10 11 12 13 14 15 16 17 |
# File 'lib/twisty_puzzles/axis_face_and_direction_move.rb', line 10 def initialize(axis_face, direction) raise TypeError, "Unsuitable axis face #{axis_face}." unless axis_face.is_a?(Face) raise TypeError unless direction.is_a?(CubeDirection) super() @axis_face = axis_face @direction = direction end |
Instance Attribute Details
#axis_face ⇒ Object (readonly)
Returns the value of attribute axis_face.
19 20 21 |
# File 'lib/twisty_puzzles/axis_face_and_direction_move.rb', line 19 def axis_face @axis_face end |
#direction ⇒ Object (readonly)
Returns the value of attribute direction.
19 20 21 |
# File 'lib/twisty_puzzles/axis_face_and_direction_move.rb', line 19 def direction @direction end |
Instance Method Details
#can_swap?(other) ⇒ Boolean
41 42 43 |
# File 'lib/twisty_puzzles/axis_face_and_direction_move.rb', line 41 def can_swap?(other) super || same_axis?(other) end |
#canonical_direction ⇒ Object
37 38 39 |
# File 'lib/twisty_puzzles/axis_face_and_direction_move.rb', line 37 def canonical_direction @axis_face.canonical_axis_face? ? @direction : @direction.inverse end |
#identifying_fields ⇒ Object
33 34 35 |
# File 'lib/twisty_puzzles/axis_face_and_direction_move.rb', line 33 def [@axis_face, @direction] end |
#mirror(normal_face) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/twisty_puzzles/axis_face_and_direction_move.rb', line 70 def mirror(normal_face) if normal_face.same_axis?(@axis_face) fields = replace_once( replace_once(, @direction, @direction.inverse), @axis_face, @axis_face.opposite ) self.class.new(*fields) else inverse end end |
#rotate_by(rotation) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/twisty_puzzles/axis_face_and_direction_move.rb', line 53 def rotate_by(rotation) raise TypeError unless rotation.is_a?(Rotation) if same_axis?(rotation) self else rotation_neighbors = rotation.axis_face.neighbors face_index = rotation_neighbors.index(@axis_face) raise unless face_index new_axis_face = rotation_neighbors[(face_index + rotation.direction.value) % rotation_neighbors.length] fields = replace_once(, @axis_face, new_axis_face) self.class.new(*fields) end end |
#same_axis?(other) ⇒ Boolean
29 30 31 |
# File 'lib/twisty_puzzles/axis_face_and_direction_move.rb', line 29 def same_axis?(other) @axis_face.same_axis?(other.axis_face) end |
#swap_internal(other) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/twisty_puzzles/axis_face_and_direction_move.rb', line 45 def swap_internal(other) if same_axis?(other) [other, self] else super end end |
#translated_direction(other_axis_face) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/twisty_puzzles/axis_face_and_direction_move.rb', line 21 def translated_direction(other_axis_face) case @axis_face when other_axis_face then @direction when other_axis_face.opposite then @direction.inverse else raise ArgumentError end end |