added async stone detection thread

This commit is contained in:
2023-07-26 09:46:33 +02:00
parent 3c02d413a2
commit 7b63568fa5
2 changed files with 24 additions and 10 deletions

View File

@@ -1,4 +1,5 @@
#!/usr/bin/python #!/usr/bin/python
from copy import copy
from tetromino import Tetromino from tetromino import Tetromino
@@ -59,7 +60,7 @@ class Field():
def rotate_state(self): def rotate_state(self):
self.state = self.rotate_90_degree_anticlckwise(self.state) self.state = self.rotate_90_degree_anticlckwise(self.state)
#self.state = self.matrixflip(self.state, 'v') #self.state = self.matrixflip(self.state, 'v')
print(self.state) #print(self.state)
def get_line_count(self): def get_line_count(self):
return self.cleared_rows return self.cleared_rows
@@ -148,6 +149,18 @@ class Field():
self._line_clear() self._line_clear()
return row return row
def predict_gaps_in_next_rotation(self):
tmp_state = copy(self.state)
tmp_state = self.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(
["".join([row[col] for row in tmp_state]).lstrip().count(' ')
for col in range(Field.WIDTH)])
def count_gaps(self): def count_gaps(self):
""" """
Check each column one by one to make sure there are no gaps in the Check each column one by one to make sure there are no gaps in the

View File

@@ -90,17 +90,18 @@ class Litris(GameBase):
self.drop_down() self.drop_down()
print(self.field) print(self.field)
if self.field.get_line_count() >= 6 and self.field.height() <= 2: if self.field.get_line_count() >= 6 and self.field.height() <= 2:
self.update_move_mode() if self.field.predict_gaps_in_next_rotation() <= 6:
self.field.rotate_state() self.update_move_mode()
#self.update_move_mode() self.field.rotate_state()
self.field.reset_half_field() #self.update_move_mode()
#field_mem = copy(self.field) self.field.reset_half_field()
#self.field = copy(self.field_mem) #field_mem = copy(self.field)
#self.field_mem = copy(field_mem) #self.field = copy(self.field_mem)
#self.field_mem = copy(field_mem)
self.field.cleared_rows = 1 self.field.cleared_rows = 1
cv.waitKey(200) cv.waitKey(200)
self.stone_id_thread.set_pick_up_status(False) self.stone_id_thread.set_pick_up_status(False)