Class: TwistyPuzzles::FatMove

Inherits:
CubeMove show all
Defined in:
lib/twisty_puzzles/cube_move.rb

Overview

A fat move with a width. For width 1, this becomes a normal outer move.

Constant Summary collapse

OUTER_MOVES =
Face::ELEMENTS.product(CubeDirection::NON_ZERO_DIRECTIONS).map do |f, d|
  FatMove.new(f, d)
end.freeze

Constants inherited from AbstractMove

AbstractMove::AXES, AbstractMove::MOVE_METRICS, AbstractMove::SLICE_FACES, AbstractMove::SLICE_NAMES

Instance Attribute Summary collapse

Attributes inherited from AxisFaceAndDirectionMove

#axis_face, #direction

Instance Method Summary collapse

Methods inherited from CubeMove

#puzzles

Methods inherited from AxisFaceAndDirectionMove

#can_swap?, #canonical_direction, #mirror, #rotate_by, #same_axis?, #swap_internal, #translated_direction

Methods inherited from AbstractMove

#<=>, #can_swap?, check_move_metric, #decide_meaning, #direction, #eql?, #equivalent?, #equivalent_internal?, #hash, #identity?, #inverse, #join_with_cancellation, #mirror, #move_count, #prepend_inner_m_slice_move, #puzzles, #rotate_by, #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_face, direction, width = 1) ⇒ FatMove

Returns a new instance of FatMove.

Raises:

  • (TypeError)


94
95
96
97
98
99
100
# File 'lib/twisty_puzzles/cube_move.rb', line 94

def initialize(axis_face, direction, width = 1)
  super(axis_face, direction)
  raise TypeError unless width.is_a?(Integer)
  raise ArgumentError, "Invalid width #{width} for fat move." unless width >= 1

  @width = width
end

Instance Attribute Details

#widthObject (readonly)

Returns the value of attribute width.



106
107
108
# File 'lib/twisty_puzzles/cube_move.rb', line 106

def width
  @width
end

Instance Method Details

#identifying_fieldsObject



108
109
110
# File 'lib/twisty_puzzles/cube_move.rb', line 108

def identifying_fields
  super + [@width]
end

#inverted_width(cube_size) ⇒ Object



124
125
126
# File 'lib/twisty_puzzles/cube_move.rb', line 124

def inverted_width(cube_size)
  cube_size - @width
end

#prepend_fat_m_slice_move(other, cube_size) ⇒ Object



134
135
136
137
138
139
140
# File 'lib/twisty_puzzles/cube_move.rb', line 134

def prepend_fat_m_slice_move(other, cube_size)
  if adjacent_mslice_move?(other)
    Algorithm.move(FatMove.new(@axis_face, @direction, cube_size - 1))
  elsif contained_mslice_move?(other, cube_size)
    Algorithm.move(FatMove.new(@axis_face, @direction, 1))
  end
end

#prepend_fat_move(other, cube_size) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/twisty_puzzles/cube_move.rb', line 142

def prepend_fat_move(other, cube_size)
  if same_fat_block?(other)
    merge_with_same_fat_block(other)
  elsif opposite_fat_block?(other, cube_size)
    merge_with_opposite_fat_block(other)
  elsif leaves_inner_slice_move?(other)
    Algorithm.move(inner_slice_move)
  elsif other.leaves_inner_slice_move?(self)
    Algorithm.move(other.inner_slice_move)
  elsif leaves_inner_fat_mslice_move?(other, cube_size)
    Algorithm.move(inner_fat_mslice_move(cube_size))
  elsif other.leaves_inner_fat_mslice_move?(self, cube_size)
    Algorithm.move(other.inner_fat_mslice_move(cube_size))
  end
end

#prepend_rotation(other, cube_size) ⇒ Object



128
129
130
131
132
# File 'lib/twisty_puzzles/cube_move.rb', line 128

def prepend_rotation(other, cube_size)
  # Note that changing the order is safe because that method returns nil if no cancellation
  # can be performed.
  other.prepend_fat_move(self, cube_size)
end

#prepend_slice_move(other, cube_size) ⇒ Object



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/twisty_puzzles/cube_move.rb', line 158

def prepend_slice_move(other, cube_size)
  return unless same_axis?(other)

  translated_direction = other.translated_direction(@axis_face)
  translated_slice_index = other.translated_slice_index(@axis_face, cube_size)
  move =
    case translated_slice_index
    when @width
      return unless translated_direction == @direction

      with_width(@width + 1)
    when @width - 1
      return unless translated_direction == @direction.inverse

      with_width(@width - 1)
    else
      return
    end
  Algorithm.move(move)
end

#slice_move?Boolean

Returns:

  • (Boolean)


116
117
118
# File 'lib/twisty_puzzles/cube_move.rb', line 116

def slice_move?
  false
end

#to_sObject



112
113
114
# File 'lib/twisty_puzzles/cube_move.rb', line 112

def to_s
  "#{@width > 2 ? @width : ''}#{@axis_face.name}#{@width > 1 ? 'w' : ''}#{@direction.name}"
end

#with_width(width) ⇒ Object



120
121
122
# File 'lib/twisty_puzzles/cube_move.rb', line 120

def with_width(width)
  FatMove.new(@axis_face, @direction, width)
end