litris update

This commit is contained in:
Thaloria@web.de
2023-07-25 08:43:04 +02:00
parent d3fa6fe807
commit 3c723fb602
3 changed files with 56 additions and 29 deletions

View File

@@ -23,6 +23,22 @@ class Field():
'{:2d} |'.format(i) + ' '.join(row) + '|'
for i, row in enumerate(self.state)]) + '\n' + BAR
def matrixflip(self, m, d):
tempm = m.copy()
if d == 'h':
for i in range(0, len(tempm), 1):
tempm[i].reverse()
elif d == 'v':
tempm.reverse()
return (tempm)
def rotate_90_degree_anticlckwise(self, 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):
new_matrix = []
for i in range(len(matrix[0])):
@@ -32,8 +48,13 @@ class Field():
return new_matrix
def reset_field(self):
self.state = [[' ' for cols in range(Field.WIDTH)]
for rows in range(Field.HEIGHT)]
def rotate_state(self):
self.state = self.rotate_90_degree_clckwise(self.state)
self.state = self.rotate_90_degree_anticlckwise(self.state)
#self.state = self.matrixflip(self.state, 'v')
print(self.state)
def get_line_count(self):

View File

@@ -1,3 +1,5 @@
from copy import copy
import cv2 as cv
import numpy as np
from game_base_class import GameBase
@@ -25,6 +27,7 @@ class Litris(GameBase):
self.fill_data_coordinates()
self.field = Field()
self.field_mem = Field()
#self.sd_reset_board = cv.imread("control_elements/sodoku_reset_button.jpg", cv.IMREAD_COLOR)
@@ -32,11 +35,6 @@ class Litris(GameBase):
self.move_mode = 1
def reset_field(self):
self.state = [[' ' for cols in range(Field.WIDTH)]
for rows in range(Field.HEIGHT)]
def fill_data_coordinates(self):
# 610 to 1950 = 1340 - 76 / 20 = 63
# 40 to 1380 = 1340 - 76 / 20 = 63
@@ -69,11 +67,11 @@ class Litris(GameBase):
current_tetromino = Tetromino.create(current_letter)
if self.move_mode == 2:
current_tetromino.rotate(1)
current_tetromino.rotate(3)
elif self.move_mode == 3:
current_tetromino.rotate(2)
elif self.move_mode == 4:
current_tetromino.rotate(3)
current_tetromino.rotate(1)
opt = Optimizer.get_optimal_drop(self.field, current_tetromino)
@@ -87,12 +85,20 @@ class Litris(GameBase):
self.field.drop(current_tetromino, column)
self.move_stone(column - offset_col, rotation)
self.drop_down()
self.stone_id_thread.set_pick_up_status(False)
print(self.field)
#if self.field.get_line_count() % 6 == 0:
# self.field.rotate_state()
# self.update_move_mode()
# self.field.cleared_rows = 1
if self.field.get_line_count() >= 10:
self.update_move_mode()
self.field.rotate_state()
#self.update_move_mode()
#self.field.reset_field()
#field_mem = copy(self.field)
#self.field = copy(self.field_mem)
#self.field_mem = copy(field_mem)
self.field.cleared_rows = 1
cv.waitKey(200)
self.stone_id_thread.set_pick_up_status(False)
def drop_down(self):

View File

@@ -199,30 +199,30 @@ class Tetromino():
elif mode == 3:
offset_map= {
'i': {0: 8, 1: 10, 2: 8, 3: 10},
'a': {0: 8, 1: 9, 2: 8, 3: 9},
'b': {0: 8, 1: 9, 2: 8, 3: 9},
'c': {0: 8, 1: 8, 2: 8, 3: 8},
'a': {0: 8, 1: 10, 2: 8, 3: 10},
'b': {0: 9, 1: 10, 2: 9, 3: 10},
'c': {0: 9, 1: 9, 2: 9, 3: 9},
'o': {0: 9, 1: 9, 2: 9, 3: 9},
'd': {0: 9, 1: 9, 2: 9, 3: 9},
't': {0: 8, 1: 8, 2: 9, 3: 8},
's': {0: 9, 1: 9, 2: 9, 3: 9},
'z': {0: 9, 1: 9, 2: 9, 3: 9},
'j': {0: 9, 1: 8, 2: 8, 3: 8},
'l': {0: 9, 1: 8, 2: 8, 3: 8}
't': {0: 8, 1: 9, 2: 9, 3: 7},
's': {0: 8, 1: 9, 2: 8, 3: 9},
'z': {0: 8, 1: 9, 2: 8, 3: 9},
'j': {0: 9, 1: 9, 2: 8, 3: 9},
'l': {0: 9, 1: 9, 2: 8, 3: 9}
}
else: #mode == 4:
offset_map = {
'i': {0: 8, 1: 9, 2: 8, 3: 9},
'a': {0: 9, 1: 9, 2: 9, 3: 9},
'b': {0: 9, 1: 9, 2: 9, 3: 9},
'i': {0: 10, 1: 8, 2: 8, 3: 10},
'a': {0: 10, 1: 9, 2: 10, 3: 9},
'b': {0: 10, 1: 9, 2: 10, 3: 9},
'c': {0: 10, 1: 10, 2: 10, 3: 10},
'o': {0: 9, 1: 9, 2: 9, 3: 9},
'd': {0: 9, 1: 9, 2: 9, 3: 9},
't': {0: 9, 1: 9, 2: 8, 3: 9},
's': {0: 9, 1: 9, 2: 9, 3: 9},
'z': {0: 9, 1: 9, 2: 9, 3: 9},
'j': {0: 8, 1: 9, 2: 9, 3: 9},
'l': {0: 8, 1: 9, 2: 9, 3: 9}
't': {0: 9, 1: 8, 2: 9, 3: 9},
's': {0: 9, 1: 9, 2: 8, 3: 9},
'z': {0: 9, 1: 9, 2: 8, 3: 9},
'j': {0: 9, 1: 9, 2: 9, 3: 8},
'l': {0: 9, 1: 9, 2: 9, 3: 8}
}
return offset_map.get(self.letter)[rotation]