added first draft litris
This commit is contained in:
36
litris.py
36
litris.py
@@ -6,17 +6,17 @@ from field import Field
|
|||||||
from tetromino import Tetromino
|
from tetromino import Tetromino
|
||||||
from optimizer import Optimizer
|
from optimizer import Optimizer
|
||||||
|
|
||||||
O_FULL = [[0, 1, 1, 0], [0, 1, 1, 0]]
|
O_FULL = [[0, 0, 0, 0], [0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 0]]
|
||||||
D_FULL = [[0, 1, 1, 0], [0, 0, 1, 0]]
|
D_FULL = [[0, 0, 0, 0], [0, 1, 1, 0], [0, 0, 1, 0], [0, 0, 0, 0]]
|
||||||
L_FULL = [[0, 0, 1, 0], [1, 1, 1, 0]]
|
L_FULL = [[0, 0, 0, 0], [0, 0, 1, 0], [1, 1, 1, 0], [0, 0, 0, 0]]
|
||||||
J_FULL = [[1, 1, 1, 0], [0, 0, 1, 0]]
|
J_FULL = [[0, 0, 0, 0], [1, 1, 1, 0], [0, 0, 1, 0], [0, 0, 0, 0]]
|
||||||
I_FULL = [[1, 1, 1, 1], [0, 0, 0, 0]]
|
I_FULL = [[0, 0, 0, 0], [1, 1, 1, 1], [0, 0, 0, 0], [0, 0, 0, 0]]
|
||||||
C_FULL = [[0, 0, 0, 0], [0, 0, 1, 0]]
|
C_FULL = [[0, 0, 0, 0], [0, 0, 1, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
|
||||||
B_FULL = [[0, 0, 0, 0], [0, 1, 1, 0]]
|
B_FULL = [[0, 0, 0, 0], [0, 1, 1, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
|
||||||
A_FULL = [[0, 1, 1, 1], [0, 0, 0, 0]]
|
A_FULL = [[0, 0, 0, 0], [0, 1, 1, 1], [0, 0, 0, 0], [0, 0, 0, 0]]
|
||||||
S_FULL = [[0, 0, 1, 1], [0, 1, 1, 0]]
|
S_FULL = [[0, 0, 0, 0], [0, 0, 1, 1], [0, 1, 1, 0], [0, 0, 0, 0]]
|
||||||
Z_FULL = [[0, 1, 1, 0], [0, 0, 1, 1]]
|
Z_FULL = [[0, 0, 0, 0], [0, 1, 1, 0], [0, 0, 1, 1], [0, 0, 0, 0]]
|
||||||
T_FULL = [[0, 1, 1, 1], [0, 0, 1, 0]]
|
T_FULL = [[0, 0, 0, 0], [0, 1, 1, 1], [0, 0, 1, 0], [0, 0, 0, 0]]
|
||||||
|
|
||||||
class Litris(GameBase):
|
class Litris(GameBase):
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ class Litris(GameBase):
|
|||||||
self.keyboard = Controller()
|
self.keyboard = Controller()
|
||||||
|
|
||||||
self.data_coordinates = np.zeros((20, 20), dtype=object)
|
self.data_coordinates = np.zeros((20, 20), dtype=object)
|
||||||
self.stone_coordinates = np.zeros((2, 4), dtype=object)
|
self.stone_coordinates = np.zeros((4, 4), dtype=object)
|
||||||
self.observation = np.zeros((20, 20), dtype=int)
|
self.observation = np.zeros((20, 20), dtype=int)
|
||||||
|
|
||||||
self.colors = [1, 2, 3, 4, 5, 6, 7, 8, 9]
|
self.colors = [1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||||
@@ -57,13 +57,13 @@ class Litris(GameBase):
|
|||||||
for e in range(0, 20, 1):
|
for e in range(0, 20, 1):
|
||||||
for i in range(0, 20, 1):
|
for i in range(0, 20, 1):
|
||||||
self.data_coordinates[e][i] = [(i * dim) + (i * i_spacing), (e * dim) + (e * e_spacing), dim, dim]
|
self.data_coordinates[e][i] = [(i * dim) + (i * i_spacing), (e * dim) + (e * e_spacing), dim, dim]
|
||||||
for e in range(0, 2, 1):
|
for e in range(0, 4, 1):
|
||||||
for i in range(0, 4, 1):
|
for i in range(0, 4, 1):
|
||||||
self.stone_coordinates[e][i] = [(i * dim) + (i * i_spacing), (e * dim) + (e * e_spacing), dim, dim]
|
self.stone_coordinates[e][i] = [(i * dim) + (i * i_spacing), (e * dim) + (e * e_spacing), dim, dim]
|
||||||
|
|
||||||
def assess_playfield_and_make_move(self):
|
def assess_playfield_and_make_move(self):
|
||||||
# current_letter = self.new_stone_detection_and_identification()
|
current_letter = self.new_stone_detection_and_identification()
|
||||||
current_letter = self.stone_id()
|
#current_letter = self.stone_id()
|
||||||
#current_letter = 'D'
|
#current_letter = 'D'
|
||||||
print("current_letter: ", current_letter)
|
print("current_letter: ", current_letter)
|
||||||
if current_letter is None:
|
if current_letter is None:
|
||||||
@@ -157,13 +157,13 @@ class Litris(GameBase):
|
|||||||
screenshot = self.capture_window.get_screenshot()
|
screenshot = self.capture_window.get_screenshot()
|
||||||
#screenshot = cv.imread("litris/main_playfield.jpg")
|
#screenshot = cv.imread("litris/main_playfield.jpg")
|
||||||
# 1148 1412 580 845
|
# 1148 1412 580 845
|
||||||
screenshot = screenshot[643:782, 1148:1412]
|
screenshot = screenshot[580:845, 1148:1412]
|
||||||
#cv.imshow("screenshot", screenshot)
|
#cv.imshow("screenshot", screenshot)
|
||||||
#cv.waitKey(150)
|
#cv.waitKey(150)
|
||||||
|
|
||||||
# gray_needle = cv.cvtColor(self.needles[needle_key], cv.COLOR_BGR2GRAY)
|
# gray_needle = cv.cvtColor(self.needles[needle_key], cv.COLOR_BGR2GRAY)
|
||||||
# thresh_needle = cv.threshold(gray_needle, 0, 255, cv.THRESH_BINARY_INV + cv.THRESH_OTSU)[1]
|
# thresh_needle = cv.threshold(gray_needle, 0, 255, cv.THRESH_BINARY_INV + cv.THRESH_OTSU)[1]
|
||||||
rectangles = self.vision_stun.find(screenshot, self.needles[1], 0.85, 4)
|
rectangles = self.vision_stun.find(screenshot, self.needles[1], 0.85, 16)
|
||||||
if len(rectangles) == 0:
|
if len(rectangles) == 0:
|
||||||
if self.overlay.run_mode == 'stopped' or self.overlay.run_mode == 'paused':
|
if self.overlay.run_mode == 'stopped' or self.overlay.run_mode == 'paused':
|
||||||
return
|
return
|
||||||
@@ -284,7 +284,7 @@ class Litris(GameBase):
|
|||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
def point_in_smal_rect(self, point):
|
def point_in_smal_rect(self, point):
|
||||||
for e in range(0, 2, 1):
|
for e in range(0, 4, 1):
|
||||||
for i in range(0, 4, 1):
|
for i in range(0, 4, 1):
|
||||||
x1, y1, w, h = self.stone_coordinates[e][i]
|
x1, y1, w, h = self.stone_coordinates[e][i]
|
||||||
x2, y2 = x1 + w, y1 + h
|
x2, y2 = x1 + w, y1 + h
|
||||||
|
|||||||
Reference in New Issue
Block a user