improve t-spin detection
This commit is contained in:
parent
10c9d3e238
commit
4b79ae02ca
@ -362,7 +362,7 @@ class Matrix(Grid):
|
|||||||
block.shine()
|
block.shine()
|
||||||
self.spotlight = row[self.COLUMNS // 2].coord
|
self.spotlight = row[self.COLUMNS // 2].coord
|
||||||
self.auto_repeat_timer.stop()
|
self.auto_repeat_timer.stop()
|
||||||
self.lock_signal.emit(len(self.complete_lines), self.piece.t_spin)
|
self.lock_signal.emit(len(self.complete_lines), self.piece.t_spin())
|
||||||
|
|
||||||
if self.complete_lines:
|
if self.complete_lines:
|
||||||
self.fall_timer.stop()
|
self.fall_timer.stop()
|
||||||
|
@ -70,7 +70,8 @@ class Tetromino:
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.orientation = 0
|
self.orientation = 0
|
||||||
self.t_spin = ""
|
self.rotation_point_5_used = False
|
||||||
|
self.rotated_last = False
|
||||||
|
|
||||||
def insert_into(self, matrix, position):
|
def insert_into(self, matrix, position):
|
||||||
self.matrix = matrix
|
self.matrix = matrix
|
||||||
@ -108,11 +109,15 @@ class Tetromino:
|
|||||||
Movement into occupied cells and Matrix walls and floors is not allowed
|
Movement into occupied cells and Matrix walls and floors is not allowed
|
||||||
Update the Grid if there is no drop trail
|
Update the Grid if there is no drop trail
|
||||||
"""
|
"""
|
||||||
return self._try_movement(
|
if self._try_movement(
|
||||||
(block.coord + Point(horizontally, vertically) for block in self.minoes),
|
(block.coord + Point(horizontally, vertically) for block in self.minoes),
|
||||||
trail,
|
trail,
|
||||||
update
|
update
|
||||||
)
|
):
|
||||||
|
self.rotated_last = False
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
def rotate(self, direction=CLOCKWISE):
|
def rotate(self, direction=CLOCKWISE):
|
||||||
"""
|
"""
|
||||||
@ -130,9 +135,12 @@ class Tetromino:
|
|||||||
mino.coord.rotate(self.minoes[0].coord, direction) for mino in self.minoes
|
mino.coord.rotate(self.minoes[0].coord, direction) for mino in self.minoes
|
||||||
)
|
)
|
||||||
|
|
||||||
for movement in self.SUPER_ROTATION_SYSTEM[self.orientation][direction]:
|
for rotation_point, movement in enumerate(self.SUPER_ROTATION_SYSTEM[self.orientation][direction]):
|
||||||
if self._try_movement(coord + Point(*movement) for coord in rotated_coords):
|
if self._try_movement(coord + Point(*movement) for coord in rotated_coords):
|
||||||
self.orientation = (self.orientation + direction) % 4
|
self.orientation = (self.orientation + direction) % 4
|
||||||
|
self.rotated_last = True
|
||||||
|
if rotation_point == 4:
|
||||||
|
self.rotation_point_5_used = True
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -155,6 +163,9 @@ class Tetromino:
|
|||||||
trail += 1
|
trail += 1
|
||||||
return trail
|
return trail
|
||||||
|
|
||||||
|
def t_spin(self):
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
class TetroI(Tetromino, metaclass=MetaTetro):
|
class TetroI(Tetromino, metaclass=MetaTetro):
|
||||||
"""
|
"""
|
||||||
@ -192,17 +203,12 @@ class TetroT(Tetromino, metaclass=MetaTetro):
|
|||||||
|
|
||||||
COORDS = (0, 0), (L, 0), (0, U), (R, 0)
|
COORDS = (0, 0), (L, 0), (0, U), (R, 0)
|
||||||
|
|
||||||
T_SLOT = (
|
T_SLOT = ((L, U), (R, U), (R, D), (L, D))
|
||||||
((L, U), (R, U), (L, D), (R, D)),
|
|
||||||
((R, U), (R, D), (L, U), (L, D)),
|
|
||||||
((R, D), (L, D), (R, U), (L, U)),
|
|
||||||
((L, D), (L, U), (R, D), (R, U)),
|
|
||||||
)
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
def rotate(self, direction=CLOCKWISE):
|
def t_spin(self):
|
||||||
"""
|
"""
|
||||||
Detects T-Spins:
|
Detects T-Spins:
|
||||||
this action can be achieved by first landing a T-Tetrimino,
|
this action can be achieved by first landing a T-Tetrimino,
|
||||||
@ -211,13 +217,17 @@ class TetroT(Tetromino, metaclass=MetaTetro):
|
|||||||
any three of the four cells diagonally adjacent to the center of self
|
any three of the four cells diagonally adjacent to the center of self
|
||||||
are occupied by existing Blocks.)
|
are occupied by existing Blocks.)
|
||||||
"""
|
"""
|
||||||
rotated = super().rotate(direction)
|
if not self.rotated_last:
|
||||||
if rotated:
|
return ""
|
||||||
|
|
||||||
|
if self.rotation_point_5_used:
|
||||||
|
return "T-Spin"
|
||||||
|
|
||||||
center = self.minoes[0].coord
|
center = self.minoes[0].coord
|
||||||
pa = center + Point(*self.T_SLOT[self.orientation][0])
|
pa = center + Point(*self.T_SLOT[self.orientation])
|
||||||
pb = center + Point(*self.T_SLOT[self.orientation][1])
|
pb = center + Point(*self.T_SLOT[(self.orientation+1)%4])
|
||||||
pc = center + Point(*self.T_SLOT[self.orientation][2])
|
pc = center + Point(*self.T_SLOT[(self.orientation+2)%4])
|
||||||
pd = center + Point(*self.T_SLOT[self.orientation][3])
|
pd = center + Point(*self.T_SLOT[(self.orientation+3)%4])
|
||||||
|
|
||||||
a = not self.matrix.is_empty_cell(pa)
|
a = not self.matrix.is_empty_cell(pa)
|
||||||
b = not self.matrix.is_empty_cell(pb)
|
b = not self.matrix.is_empty_cell(pb)
|
||||||
@ -225,10 +235,11 @@ class TetroT(Tetromino, metaclass=MetaTetro):
|
|||||||
d = not self.matrix.is_empty_cell(pd)
|
d = not self.matrix.is_empty_cell(pd)
|
||||||
|
|
||||||
if a and b and (c or d):
|
if a and b and (c or d):
|
||||||
self.t_spin = "T-Spin"
|
return "T-Spin"
|
||||||
elif c and d and (a or b):
|
elif c and d and (a or b):
|
||||||
self.t_spin = "Mini T-Spin"
|
return "Mini T-Spin"
|
||||||
return rotated
|
else:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
class TetroZ(Tetromino, metaclass=MetaTetro):
|
class TetroZ(Tetromino, metaclass=MetaTetro):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user