litris fixes
This commit is contained in:
32
litris.py
32
litris.py
@@ -101,6 +101,10 @@ class Litris(GameBase):
|
|||||||
# 2: cv.imread("sodoku/2.jpg", cv.IMREAD_COLOR),
|
# 2: cv.imread("sodoku/2.jpg", cv.IMREAD_COLOR),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def reset_field(self):
|
||||||
|
self.state = [[' ' for cols in range(Field.WIDTH)]
|
||||||
|
for rows in range(Field.HEIGHT)]
|
||||||
|
|
||||||
def fill_data_coordinates(self):
|
def fill_data_coordinates(self):
|
||||||
# 610 to 1950 = 1340 - 76 / 20 = 63
|
# 610 to 1950 = 1340 - 76 / 20 = 63
|
||||||
# 40 to 1380 = 1340 - 76 / 20 = 63
|
# 40 to 1380 = 1340 - 76 / 20 = 63
|
||||||
@@ -133,7 +137,10 @@ class Litris(GameBase):
|
|||||||
#ier = 0
|
#ier = 0
|
||||||
|
|
||||||
current_stone = self.new_stone_detection_and_identification()
|
current_stone = self.new_stone_detection_and_identification()
|
||||||
current_tetromino = Tetromino.create(self.get_letter_for_stone(current_stone))
|
current_letter = self.get_letter_for_stone(current_stone)
|
||||||
|
if current_letter is None:
|
||||||
|
return
|
||||||
|
current_tetromino = Tetromino.create(current_letter)
|
||||||
opt = Optimizer.get_optimal_drop(self.field, current_tetromino)
|
opt = Optimizer.get_optimal_drop(self.field, current_tetromino)
|
||||||
rotation = opt['tetromino_rotation']
|
rotation = opt['tetromino_rotation']
|
||||||
column = opt['tetromino_column']
|
column = opt['tetromino_column']
|
||||||
@@ -141,6 +148,7 @@ class Litris(GameBase):
|
|||||||
offset_col = current_tetromino.get_offset_column(rotation)
|
offset_col = current_tetromino.get_offset_column(rotation)
|
||||||
self.field.drop(current_tetromino, column)
|
self.field.drop(current_tetromino, column)
|
||||||
self.move_stone(column - offset_col, rotation)
|
self.move_stone(column - offset_col, rotation)
|
||||||
|
print(self.field)
|
||||||
|
|
||||||
#time.sleep(0.2)
|
#time.sleep(0.2)
|
||||||
#self.observation = new_observation
|
#self.observation = new_observation
|
||||||
@@ -199,6 +207,8 @@ class Litris(GameBase):
|
|||||||
rectangles = self.vision_stun.find(screenshot, self.needles[1], 0.85, 16)
|
rectangles = self.vision_stun.find(screenshot, self.needles[1], 0.85, 16)
|
||||||
if len(rectangles) == 0:
|
if len(rectangles) == 0:
|
||||||
cv.waitKey(100)
|
cv.waitKey(100)
|
||||||
|
if self.overlay.run_mode == 'stopped' or self.overlay.run_mode == 'paused':
|
||||||
|
return
|
||||||
continue
|
continue
|
||||||
points = self.vision_stun.get_click_points(rectangles)
|
points = self.vision_stun.get_click_points(rectangles)
|
||||||
|
|
||||||
@@ -238,6 +248,8 @@ class Litris(GameBase):
|
|||||||
return "Z"
|
return "Z"
|
||||||
elif np.array_equal(stone, T1_FULL):
|
elif np.array_equal(stone, T1_FULL):
|
||||||
return "T"
|
return "T"
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def find_place_for_stone(self, stone, current_board):
|
def find_place_for_stone(self, stone, current_board):
|
||||||
@@ -337,17 +349,23 @@ class Litris(GameBase):
|
|||||||
cv.waitKey(250)
|
cv.waitKey(250)
|
||||||
|
|
||||||
if rotation == 1:
|
if rotation == 1:
|
||||||
self.keyboard.press('e')
|
self.keyboard.press('q')
|
||||||
self.keyboard.release('e')
|
self.keyboard.release('q')
|
||||||
elif rotation == 2:
|
elif rotation == 2:
|
||||||
self.keyboard.press('e')
|
self.keyboard.press('q')
|
||||||
self.keyboard.release('e')
|
self.keyboard.release('q')
|
||||||
cv.waitKey(40)
|
cv.waitKey(40)
|
||||||
self.keyboard.press('e')
|
self.keyboard.press('q')
|
||||||
self.keyboard.release('e')
|
self.keyboard.release('q')
|
||||||
elif rotation == 3:
|
elif rotation == 3:
|
||||||
self.keyboard.press('q')
|
self.keyboard.press('q')
|
||||||
self.keyboard.release('q')
|
self.keyboard.release('q')
|
||||||
|
cv.waitKey(40)
|
||||||
|
self.keyboard.press('q')
|
||||||
|
self.keyboard.release('q')
|
||||||
|
cv.waitKey(40)
|
||||||
|
self.keyboard.press('q')
|
||||||
|
self.keyboard.release('q')
|
||||||
|
|
||||||
if col_movement < 0:
|
if col_movement < 0:
|
||||||
for i in range(0, col_movement, - 1):
|
for i in range(0, col_movement, - 1):
|
||||||
|
|||||||
16
tetromino.py
16
tetromino.py
@@ -169,17 +169,17 @@ class Tetromino():
|
|||||||
|
|
||||||
def get_offset_column(self, rotation):
|
def get_offset_column(self, rotation):
|
||||||
offset_map= {
|
offset_map= {
|
||||||
'i': {0: 10, 1: 9, 2: 10, 3: 9},
|
'i': {0: 8, 1: 9, 2: 9, 3: 9},
|
||||||
'a': {0: 9, 1: 9, 2: 9, 3: 9},
|
'a': {0: 9, 1: 9, 2: 9, 3: 9},
|
||||||
'b': {0: 9, 1: 8, 2: 10, 3: 8},
|
'b': {0: 9, 1: 9, 2: 9, 3: 9},
|
||||||
'c': {0: 8, 1: 8, 2: 8, 3: 8},
|
'c': {0: 10, 1: 9, 2: 9, 3: 9},
|
||||||
'o': {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},
|
'd': {0: 9, 1: 9, 2: 9, 3: 9},
|
||||||
't': {0: 9, 1: 9, 2: 10, 3: 9},
|
't': {0: 9, 1: 9, 2: 9, 3: 9},
|
||||||
's': {0: 9, 1: 9, 2: 9, 3: 9},
|
's': {0: 9, 1: 10, 2: 9, 3: 10},
|
||||||
'z': {0: 9, 1: 9, 2: 9, 3: 9},
|
'z': {0: 9, 1: 10, 2: 9, 3: 10},
|
||||||
'j': {0: 9, 1: 8, 2: 8, 3: 8},
|
'j': {0: 9, 1: 9, 2: 10, 3: 9},
|
||||||
'l': {0: 9, 1: 8, 2: 8, 3: 8}
|
'l': {0: 9, 1: 9, 2: 9, 3: 9}
|
||||||
}
|
}
|
||||||
return offset_map.get(self.letter)[rotation]
|
return offset_map.get(self.letter)[rotation]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user