added first draft litris

This commit is contained in:
2023-07-20 19:17:38 +02:00
parent 378259ab1c
commit 0b97e346d8

View File

@@ -34,6 +34,8 @@ import numpy as np
from utils import mse
from game_base_class import GameBase
import random
from pynput.keyboard import Key, Controller
BLOCK_FULL = [[0, 0, 0, 0], [0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 0]]
BLOCK_SMALL = [[1, 1], [1, 1]]
@@ -56,6 +58,8 @@ class Litris(GameBase):
def __init__(self, overlay):
super().__init__(overlay)
self.keyboard = Controller()
self.data_coordinates = np.zeros((20, 20), dtype=object)
self.stone_coordinates = np.zeros((4, 4), dtype=object)
self.observation = np.zeros((20, 20), dtype=int)
@@ -212,15 +216,21 @@ class Litris(GameBase):
def move_stone(self, col_movement):
keyboard.press('Down')
if col_movement is None:
return
# Press and release space
self.keyboard.press(Key.down)
self.keyboard.release(Key.down)
cv.waitKey(500)
if col_movement < 0:
for i in range(0, col_movement, - 1):
keyboard.press('Left')
self.keyboard.press(Key.left)
self.keyboard.release(Key.left)
cv.waitKey(500)
else:
for i in range(0, col_movement, 1):
keyboard.press('Right')
self.keyboard.press(Key.right)
self.keyboard.release(Key.right)
cv.waitKey(500)
def point_in_rect(self, point):