-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
97 lines (79 loc) · 3.07 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import threading
import time
import pyautogui
import gametype
from fieldpainter import FieldPainter
from outputmanager import PrintOutputManager
from piecepicker import InputPiecePicker, AutoPiecePicker
from scoringcalculator import IngoScoringCalculator
from tetrisgame import TetrisGame
from tetrosolver import TetroSolver, TetroConfig
__exit = False
__timeToDraw = False
SLOWNESS = 0.00
def colorPicker():
global __exit
while not __exit:
currentPos = pyautogui.position()
currentColor = pyautogui.pixel(currentPos.x, currentPos.y)
print(f"Color at mouse: {currentColor}")
time.sleep(0.5)
def tetroSolver(solver):
global __timeToDraw
global __exit
while not __exit:
if not solver.check():
__exit = True
__timeToDraw = True
time.sleep(SLOWNESS)
if __name__ == "__main__":
mode = pyautogui.confirm(text='Tetrosolver', title='Select mode', buttons=['REAL', 'MANUAL', 'AUTO'])
tetrisorigin = None
outputManager = None
replay = True
gameType = gametype.GameType.INGO
game = None
if mode == "REAL":
selectedGame = pyautogui.confirm(text='Tetrosolver', title='Select game', buttons=['INGO', 'LUMPTY', 'JSTRIS'])
if selectedGame == "INGO":
gameType = gametype.GameType.INGO
elif selectedGame == "JSTRIS":
gameType = gametype.GameType.JSTRIS
else:
gameType = gametype.GameType.LUMPTY
game = TetrisGame(gameType)
else:
game = TetrisGame()
if mode == "MANUAL":
game.piecePicker = InputPiecePicker()
game.outputManager = PrintOutputManager()
else:
SLOWNESS = 0.1
game.piecePicker = AutoPiecePicker()
game.scoringCalculator = IngoScoringCalculator()
fieldPainter = FieldPainter(gameType)
while replay:
solverConfig = TetroConfig()
#solverConfig.log = True
#solverConfig.fieldConfig.log = True
solverConfig.fieldConfig.FLAT_FACTOR = 1.1720148713567564
solverConfig.fieldConfig.HOLE_FACTOR = 5.312056910769751
solverConfig.fieldConfig.HEIGHT_FACTOR = 0.1765673301273726
solverConfig.fieldConfig.LINE_FACTOR = 1.4106621037891096
#solverConfig.fieldConfig.HEIGHT_FACTOR_HIGH_LIMIT = (2 * Field.HEIGHT) / 3
#solverConfig.fieldConfig.HEIGHT_FACTOR_HIGH = solverConfig.fieldConfig.HEIGHT_FACTOR * 2
solver = TetroSolver(game, solverConfig)
runThread = threading.Thread(target=tetroSolver, args=[solver])
#runThread = threading.Thread(target=colorPicker)
runThread.start()
while (not __exit) or __timeToDraw:
if __timeToDraw:
__timeToDraw = False
fieldPainter.paintField(solver.getField(), solver.getGameScore())
__exit = True
runThread.join()
retry = pyautogui.confirm(text=f"Game over: score was {solver.getField().rowsCleared}", title='Finished', buttons=['RERUN', 'EXIT'])
if retry == "EXIT":
replay = False
else:
__exit = False