From 0b97e346d81be2c1973a21a1a652b7a5aadbc2e8 Mon Sep 17 00:00:00 2001 From: Thaloria Date: Thu, 20 Jul 2023 19:17:38 +0200 Subject: [PATCH] added first draft litris --- litris.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/litris.py b/litris.py index f249a75..b7e0c15 100644 --- a/litris.py +++ b/litris.py @@ -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):