Untitled
unknown
python
2 years ago
3.1 kB
6
Indexable
from copy import deepcopy
def TetrisMove(strArr):
def check_filled_rows(matrix):
count_filled = 0
for row_id in range(len(matrix)):
if all(matrix[row_id][col_id] == 1 \
for col_id in range(len(matrix[row_id]))):
count_filled += 1
return count_filled
rotation_I = {"I":[(0,0), (1, 0), (2, 0), (3, 0)], "J":[(0,0), (1, 0), (2, 0), (2, -1)],\
"L":[(0,0), (0, 1), (1, 1), (2, 1)], "O":[(0,0), (0, 1), (1, 1), (1, 0)], "S":[(0,0), (1, 0), (1, 1), (2, 1)],\
"T":[(0,0), (1, 0), (1, -1), (2, 0)], "Z":[(0,0), (1, 0), (1, -1), (2, -1)]}
rotation_II = {"I":[(0,0), (1, 0), (2, 0), (3, 0)], "J":[(0,0), (0, 1), (1, 0), (2, 0)],\
"L":[(0,0), (1, 0), (2, 0), (2, 1)], "O":[(0,0), (0, 1), (1, 1), (1, 0)], "S":[(0,0), (1, 0), (1, 1), (2, 1)],\
"T":[(0,0), (1, 0), (1, 1), (2, 0)], "Z":[(0,0), (1, 0), (1, -1), (2, -1)]}
rotation_III = {"I":[(0,0), (0, 1), (0, 2), (0, 3)], "J":[(0,0), (0, 1), (0, 2), (-1, 0)],\
"L":[(0,0), (0, 1), (0, 2), (-1, 2)], "O":[(0,0), (0, 1), (1, 1), (1, 0)], "S":[(0,0), (0, 1), (-1, 1), (-1, 2)],\
"T":[(0,0), (0, 1), (-1, 1), (0, 2)], "Z":[(0,0), (0, 1), (1, 1), (1, 2)]}
rotation_IV = {"I":[(0,0), (0, 1), (0, 2), (0, 3)], "J":[(0,0), (0, 1), (0, 2), (1, 2)],\
"L":[(0,0), (0, 1), (0, 2), (1, 0)], "O":[(0,0), (0, 1), (1, 1), (1, 0)], "S":[(0,0), (0, 1), (-1, 1), (-1, 2)],\
"T":[(0,0), (0, 1), (1, 1), (0, 2)], "Z":[(0,0), (0, 1), (1, 1), (1, 2)]}
rotations = [rotation_I, rotation_II, rotation_III, rotation_IV]
matrix_area = []
for row in range(10):
matrix_area.append([])
for column in range(12):
matrix_area[-1].append(0)
maxes = []
for rotation in rotations:
block_parameters = rotation[strArr[0]]
index = 0
for block in strArr[1:]:
for row_id in range(1, int(block) + 1):
matrix_area[(-1)*row_id][index] = 1
index += 1
max_filled_rows = 0
for row_id in range(len(matrix_area)):
for col_id in range(len(matrix_area[row_id])):
if all( 0 <= row_id + param[0] < len(matrix_area) and\
0 <= col_id + param[1] < len(matrix_area[row_id])\
and matrix_area[row_id + param[0]][col_id + param[1]] + 1< 2\
for param in block_parameters):
temp_matrix = deepcopy(matrix_area)
for param in block_parameters:
temp_matrix[row_id + param[0]][col_id + param[1]] = 1
temp_filled = check_filled_rows(temp_matrix)
if max_filled_rows < temp_filled:
max_filled_rows = temp_filled
maxes.append(max_filled_rows)
return max(maxes)
# Example usage
print TetrisMove(raw_input().split())
Editor is loading...
Leave a Comment