Class: TwistyPuzzles::SliceMove
Overview
A slice move of any slice, not necessary the middle one.
Constant Summary
Constants inherited
from AbstractMove
AbstractMove::AXES, AbstractMove::MOVE_METRICS, AbstractMove::SLICE_FACES, AbstractMove::SLICE_NAMES
Instance Attribute Summary collapse
#axis_face, #direction
Instance Method Summary
collapse
Methods inherited from CubeMove
#puzzles
#can_swap?, #canonical_direction, #rotate_by, #same_axis?, #swap_internal, #translated_direction
#<=>, #can_swap?, check_move_metric, #decide_meaning, #direction, #eql?, #equivalent?, #hash, #identity?, #inverse, #join_with_cancellation, #move_count, #prepend_inner_m_slice_move, #puzzles, #rotate_by, #swap, #swap_internal
#apply_permutation, #check_types, #find_only, #only, #replace_once, #rotate_out_nils, #turned_equals?
#camel_case_to_snake_case, #format_time, #simple_class_name, #snake_case_class_name
Constructor Details
#initialize(axis_face, direction, slice_index) ⇒ SliceMove
Returns a new instance of SliceMove.
235
236
237
238
239
240
241
242
243
|
# File 'lib/twisty_puzzles/cube_move.rb', line 235
def initialize(axis_face, direction, slice_index)
super(axis_face, direction)
raise TypeError unless slice_index.is_a?(Integer)
unless slice_index >= 1
raise ArgumentError, "Invalid slice index #{slice_index} for slice move."
end
@slice_index = slice_index
end
|
Instance Attribute Details
#slice_index ⇒ Object
Returns the value of attribute slice_index.
245
246
247
|
# File 'lib/twisty_puzzles/cube_move.rb', line 245
def slice_index
@slice_index
end
|
Instance Method Details
#equivalent_internal?(other, cube_size) ⇒ Boolean
267
268
269
270
271
272
|
# File 'lib/twisty_puzzles/cube_move.rb', line 267
def equivalent_internal?(other, cube_size)
return other.equivalent_internal?(self, cube_size) if other.is_a?(FatMSliceMove)
return simplified(cube_size) == other.simplified(cube_size) if other.is_a?(SliceMove)
false
end
|
#identifying_fields ⇒ Object
247
248
249
|
# File 'lib/twisty_puzzles/cube_move.rb', line 247
def identifying_fields
super + [@slice_index]
end
|
#mirror(normal_face) ⇒ Object
259
260
261
262
263
264
265
|
# File 'lib/twisty_puzzles/cube_move.rb', line 259
def mirror(normal_face)
if normal_face.same_axis?(@axis_face)
SliceMove.new(@axis_face.opposite, @direction.inverse, @slice_index)
else
inverse
end
end
|
#prepend_fat_m_slice_move(_other, _cube_size) ⇒ Object
291
292
293
|
# File 'lib/twisty_puzzles/cube_move.rb', line 291
def prepend_fat_m_slice_move(_other, _cube_size)
nil
end
|
#prepend_fat_move(other, cube_size) ⇒ Object
295
296
297
298
299
|
# File 'lib/twisty_puzzles/cube_move.rb', line 295
def prepend_fat_move(other, cube_size)
other.prepend_slice_move(self, cube_size)
end
|
#prepend_rotation(_other, _cube_size) ⇒ Object
287
288
289
|
# File 'lib/twisty_puzzles/cube_move.rb', line 287
def prepend_rotation(_other, _cube_size)
nil
end
|
#prepend_slice_move(other, cube_size) ⇒ Object
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
|
# File 'lib/twisty_puzzles/cube_move.rb', line 301
def prepend_slice_move(other, cube_size)
return unless same_axis?(other)
this = simplified(cube_size)
if this.can_join_to_fat_mslice?(other, cube_size)
return Algorithm.move(FatMSliceMove.new(other.axis_face, other.direction))
end
other = other.simplified(cube_size)
return unless this.same_slice?(other)
Algorithm.move(
SliceMove.new(
other.axis_face,
other.direction + this.translated_direction(other.axis_face),
other.slice_index
)
)
end
|
#slice_move? ⇒ Boolean
255
256
257
|
# File 'lib/twisty_puzzles/cube_move.rb', line 255
def slice_move?
true
end
|
#to_s ⇒ Object
251
252
253
|
# File 'lib/twisty_puzzles/cube_move.rb', line 251
def to_s
"#{@slice_index > 1 ? @slice_index : ''}#{@axis_face.name.downcase}#{@direction.name}"
end
|
#translated_slice_index(other_axis_face, cube_size) ⇒ Object
274
275
276
277
278
279
280
281
282
283
284
285
|
# File 'lib/twisty_puzzles/cube_move.rb', line 274
def translated_slice_index(other_axis_face, cube_size)
if @slice_index >= cube_size - 1
raise ArgumentError,
"Slice index #{@slice_index} of #{self} is invalid for cube size #{cube_size}."
end
case @axis_face
when other_axis_face then @slice_index
when other_axis_face.opposite then invert_slice_index(cube_size)
else raise ArgumentError
end
end
|