litris update
This commit is contained in:
17
field.py
17
field.py
@@ -14,7 +14,6 @@ class Field():
|
||||
else:
|
||||
self.state = [[' ' for cols in range(Field.WIDTH)]
|
||||
for rows in range(Field.HEIGHT)]
|
||||
#self.rotate_90_degree_clckwise(self.state)
|
||||
self.cleared_rows = 1
|
||||
|
||||
def __str__(self):
|
||||
@@ -24,7 +23,8 @@ class Field():
|
||||
'{:2d} |'.format(i) + ' '.join(row) + '|'
|
||||
for i, row in enumerate(self.state)]) + '\n' + BAR
|
||||
|
||||
def matrixflip(self, m, d):
|
||||
@staticmethod
|
||||
def matrixflip(m, d):
|
||||
tempm = m.copy()
|
||||
if d == 'h':
|
||||
for i in range(0, len(tempm), 1):
|
||||
@@ -33,14 +33,16 @@ class Field():
|
||||
tempm.reverse()
|
||||
return (tempm)
|
||||
|
||||
def rotate_90_degree_anticlckwise(self, matrix):
|
||||
@staticmethod
|
||||
def rotate_90_degree_anticlckwise(matrix):
|
||||
new_matrix = []
|
||||
for i in range(len(matrix[0]), 0, -1):
|
||||
new_matrix.append(list(map(lambda x: x[i - 1], matrix)))
|
||||
|
||||
return new_matrix
|
||||
|
||||
def rotate_90_degree_clckwise(self, matrix):
|
||||
@staticmethod
|
||||
def rotate_90_degree_clckwise(matrix):
|
||||
new_matrix = []
|
||||
for i in range(len(matrix[0])):
|
||||
li = list(map(lambda x: x[i], matrix))
|
||||
@@ -58,9 +60,8 @@ class Field():
|
||||
self.state[row] = [' ' for cols in range(Field.WIDTH)]
|
||||
|
||||
def rotate_state(self):
|
||||
self.state = self.rotate_90_degree_anticlckwise(self.state)
|
||||
#self.state = self.matrixflip(self.state, 'v')
|
||||
#print(self.state)
|
||||
self.state = Field.rotate_90_degree_anticlckwise(self.state)
|
||||
|
||||
|
||||
def get_line_count(self):
|
||||
return self.cleared_rows
|
||||
@@ -158,7 +159,7 @@ class Field():
|
||||
|
||||
def predict_gaps_in_next_rotation(self):
|
||||
tmp_state = copy(self.state)
|
||||
tmp_state = self.rotate_90_degree_anticlckwise(tmp_state)
|
||||
tmp_state = Field.rotate_90_degree_anticlckwise(tmp_state)
|
||||
for row in range(int(self.HEIGHT/2)):
|
||||
tmp_state[row] = [' ' for cols in range(Field.WIDTH)]
|
||||
return sum(
|
||||
|
||||
Reference in New Issue
Block a user