added first draft litris
This commit is contained in:
13
litris.py
13
litris.py
@@ -138,14 +138,18 @@ class Litris(GameBase):
|
||||
|
||||
current_stone = self.new_stone_detection_and_identification()
|
||||
current_letter = self.get_letter_for_stone(current_stone)
|
||||
print("Current stone:", current_letter)
|
||||
if current_letter is None:
|
||||
return
|
||||
current_tetromino = Tetromino.create(current_letter)
|
||||
opt = Optimizer.get_optimal_drop(self.field, current_tetromino)
|
||||
rotation = 0 #opt['tetromino_rotation']
|
||||
rotation = opt['tetromino_rotation']
|
||||
column = opt['tetromino_column']
|
||||
print("Rota:", rotation)
|
||||
print("column:", column)
|
||||
current_tetromino.rotate(rotation)
|
||||
offset_col = current_tetromino.get_offset_column(rotation)
|
||||
print("offset column:", offset_col)
|
||||
self.field.drop(current_tetromino, column)
|
||||
self.move_stone(column - offset_col, rotation)
|
||||
print(self.field)
|
||||
@@ -348,26 +352,33 @@ class Litris(GameBase):
|
||||
# Press and release space
|
||||
self.keyboard.press(Key.down)
|
||||
self.keyboard.release(Key.down)
|
||||
print("direction pressed: down")
|
||||
cv.waitKey(250)
|
||||
|
||||
if rotation == 1:
|
||||
self.keyboard.press('q')
|
||||
self.keyboard.release('q')
|
||||
print("rotation 1 pressed: q")
|
||||
elif rotation == 2:
|
||||
self.keyboard.press('q')
|
||||
self.keyboard.release('q')
|
||||
print("rotation 2 pressed: q 1")
|
||||
cv.waitKey(40)
|
||||
self.keyboard.press('q')
|
||||
self.keyboard.release('q')
|
||||
print("rotation 2 pressed: q 2")
|
||||
elif rotation == 3:
|
||||
self.keyboard.press('q')
|
||||
self.keyboard.release('q')
|
||||
print("rotation 3 pressed: q 1")
|
||||
cv.waitKey(40)
|
||||
self.keyboard.press('q')
|
||||
self.keyboard.release('q')
|
||||
print("rotation 3 pressed: q 2")
|
||||
cv.waitKey(40)
|
||||
self.keyboard.press('q')
|
||||
self.keyboard.release('q')
|
||||
print("rotation 3 pressed: q 3")
|
||||
cv.waitKey(100)
|
||||
|
||||
if col_movement < 0:
|
||||
|
||||
Reference in New Issue
Block a user