Class: TwistyPuzzles::SkewbState
Overview
Represents the state (i.e. the sticker positions) of a Skewb.
Constant Summary
collapse
- MATCHING_CORNERS =
Pairs of coordinate pairs that should match in case of solved layers.
begin
matching_corners = []
Corner::ELEMENTS.each do |c1|
Corner::ELEMENTS.each do |c2|
next unless c1.common_edge_with?(c2)
check_parts = []
c1.rotations.each do |c1_rot|
next unless c2.face_symbols.include?(c1_rot.face_symbols.first)
c2_rot = c2.rotate_face_symbol_up(c1_rot.face_symbols.first)
check_parts.push(
[
SkewbCoordinate.for_corner(c1_rot),
SkewbCoordinate.for_corner(c2_rot)
]
)
end
matching_corners.push(check_parts)
end
end
matching_corners.uniq
end
- LAYER_CHECK_NEIGHBORS =
Pairs of stickers that can be used to check whether the “outside” of a layer on the given face is a proper layer.
begin
layer_check_neighbors = {}
MATCHING_CORNERS.each do |a, b|
[[a.first.face, b], [b.first.face, a]].each do |face, coordinates|
layer_check_neighbors[face] ||= coordinates
end
end
layer_check_neighbors
end
CubeConstants::ALPHABET_SIZE, CubeConstants::CHIRALITY_FACE_SYMBOLS, CubeConstants::FACE_NAMES, CubeConstants::FACE_SYMBOLS, CubeConstants::OPPOSITE_FACE_SYMBOLS, CubeConstants::SKEWB_STICKERS
CubePrintHelper::COLOR_MODES, CubePrintHelper::FACE_SYMBOL_INFOS, CubePrintHelper::SKEWB_FACE_SIZE
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#chirality_canonical_face_symbol, #opposite_face_symbol, #valid_chirality?
#apply_permutation, #check_types, #find_only, #only, #replace_once, #rotate_out_nils, #turned_equals?
#color_character, #color_symbol, #cube_string, #empty_name, #face_lines, #ll_string, #maybe_reverse, #pad_lines, #simple_face_lines, #skewb_ascii_art, #skewb_ascii_art_line, #skewb_face_lines, #skewb_string, #zip_concat_lines
Constructor Details
#initialize(native) ⇒ SkewbState
Returns a new instance of SkewbState.
53
54
55
56
57
|
# File 'lib/twisty_puzzles/skewb_state.rb', line 53
def initialize(native)
raise TypeError unless native.is_a?(Native::SkewbState)
@native = native
end
|
Instance Attribute Details
#native ⇒ Object
Returns the value of attribute native.
59
60
61
|
# File 'lib/twisty_puzzles/skewb_state.rb', line 59
def native
@native
end
|
Class Method Details
.for_solved_colors(solved_colors) ⇒ Object
61
62
63
64
|
# File 'lib/twisty_puzzles/skewb_state.rb', line 61
def self.for_solved_colors(solved_colors)
native = Native::SkewbState.new(solved_colors)
new(native)
end
|
Instance Method Details
#[](coordinate) ⇒ Object
112
113
114
|
# File 'lib/twisty_puzzles/skewb_state.rb', line 112
def [](coordinate)
@native[coordinate.native]
end
|
#[]=(coordinate, color) ⇒ Object
116
117
118
119
|
# File 'lib/twisty_puzzles/skewb_state.rb', line 116
def []=(coordinate, color)
@native[coordinate.native] = color
sticker_array(coordinate.face)[coordinate.coordinate] = color
end
|
#any_layer_solved? ⇒ Boolean
121
122
123
|
# File 'lib/twisty_puzzles/skewb_state.rb', line 121
def any_layer_solved?
!solved_layers.empty?
end
|
#apply_algorithm(alg) ⇒ Object
104
105
106
|
# File 'lib/twisty_puzzles/skewb_state.rb', line 104
def apply_algorithm(alg)
alg.apply_to(self)
end
|
#apply_move(move) ⇒ Object
100
101
102
|
# File 'lib/twisty_puzzles/skewb_state.rb', line 100
def apply_move(move)
move.apply_to(self)
end
|
#apply_rotation(rot) ⇒ Object
108
109
110
|
# File 'lib/twisty_puzzles/skewb_state.rb', line 108
def apply_rotation(rot)
rot.apply_to_skewb(self)
end
|
#center_face(color) ⇒ Object
#colored_to_s ⇒ Object
96
97
98
|
# File 'lib/twisty_puzzles/skewb_state.rb', line 96
def colored_to_s
skewb_string(self, :color)
end
|
#dup ⇒ Object
88
89
90
|
# File 'lib/twisty_puzzles/skewb_state.rb', line 88
def dup
SkewbState.new(@native.dup)
end
|
#eql?(other) ⇒ Boolean
Also known as:
==
66
67
68
|
# File 'lib/twisty_puzzles/skewb_state.rb', line 66
def eql?(other)
self.class.equal?(other.class) && @native == other.native
end
|
#hash ⇒ Object
72
73
74
|
# File 'lib/twisty_puzzles/skewb_state.rb', line 72
def hash
@hash ||= [self.class, @native].hash
end
|
#layer_at_face_solved?(face) ⇒ Boolean
Note that this does NOT say that the layer corresponding to the given face is solved. The face argument is used as the position where a solved face is present.
147
148
149
150
151
|
# File 'lib/twisty_puzzles/skewb_state.rb', line 147
def layer_at_face_solved?(face)
return false unless native.face_solved?(face.face_symbol)
layer_check_neighbors(face).map { |c| self[c] }.uniq.length == 1
end
|
#layer_check_neighbors(face) ⇒ Object
141
142
143
|
# File 'lib/twisty_puzzles/skewb_state.rb', line 141
def layer_check_neighbors(face)
LAYER_CHECK_NEIGHBORS[face]
end
|
#layer_solved?(color) ⇒ Boolean
131
132
133
134
135
|
# File 'lib/twisty_puzzles/skewb_state.rb', line 131
def layer_solved?(color)
Face::ELEMENTS.any? do |f|
self[SkewbCoordinate.for_center(f)] == color && layer_at_face_solved?(f)
end
end
|
#solved_layers ⇒ Object
Returns the color of all solved layers. Empty if there is none.
126
127
128
129
|
# File 'lib/twisty_puzzles/skewb_state.rb', line 126
def solved_layers
solved_faces = Face::ELEMENTS.select { |f| layer_at_face_solved?(f) }
solved_faces.map { |f| self[SkewbCoordinate.for_center(f)] }
end
|
#sticker_array(face) ⇒ Object
TODO: Get rid of this backwards compatibility artifact
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/twisty_puzzles/skewb_state.rb', line 77
def sticker_array(face)
raise TypeError unless face.is_a?(Face)
center_sticker = self[SkewbCoordinate.for_center(face)]
corner_stickers =
face.clockwise_corners.sort.map do |c|
self[SkewbCoordinate.for_corner(c)]
end
[center_sticker] + corner_stickers
end
|
#to_s ⇒ Object
92
93
94
|
# File 'lib/twisty_puzzles/skewb_state.rb', line 92
def to_s
skewb_string(self, :nocolor)
end
|