-
Notifications
You must be signed in to change notification settings - Fork 1
/
Display.py
51 lines (39 loc) · 1.4 KB
/
Display.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
import argparse
import random
from Settings import Settings
#from environment.AutoPlayEnvironment import AutoPlayEnvironment
from environment.ManualPlayEnvironment import ManualPlayer
from graphics.DummyGraphicModule import DummyGraphicModule
from graphics.GraphicModule import GraphicModule
parser = argparse.ArgumentParser()
parser.add_argument("-e", "--env-type", help="Set environment type", type=str, default="auto")
parser.add_argument("-g", "--use-graphic", help="Using graphic interface", type=bool, default=True)
args = parser.parse_args()
settings = Settings()
class Error(Exception):
"""Base class for other exceptions"""
pass
class AutoplaySelected(Error):
"""Raised when Autoplay is selected"""
pass
def random_tetromino():
return random.randrange(0, settings.ACTIONS)
TETROMINO_AGENT = random_tetromino
if __name__ == '__main__':
settings = Settings()
if args.use_graphic:
graphic_interface = GraphicModule(settings)
else:
graphic_interface = DummyGraphicModule()
if args.env_type == "manual":
env_model = ManualPlayer(settings, graphic_interface)
else:
raise AutoplaySelected
#env_model = AutoPlayEnvironment(settings, graphic_interface)
turns = 0
while True:
turns += 1
_, _, end = env_model.action(TETROMINO_AGENT())
if end:
print("Turns: " + str(turns))
turns = 0