-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathlevel_generator.py
44 lines (35 loc) · 1.34 KB
/
level_generator.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
import os
import uuid
class LevelGenerator(object):
'''
If this constructor is overridden, call it with super().__init__(dir, game) from the subclass.
'''
def __init__(self, dir, game):
self.dir = dir
if self.dir[-1] != "/":
self.dir += "/"
self.game = game.lower()
def generate(self):
'''
:return: the id and path of the next level to be evaluated.
'''
raise NotImplementedError
class ParamGenerator(LevelGenerator):
def __init__(self, dir, game, width, height):
super().__init__(dir, game)
self.width = width
self.height = height
self.script = os.path.dirname(os.path.realpath(__file__)) + '/lib/gvgai_generator/app_v3.js'
def generate(self, params=[], difficulty=None):
name = self.game + "_" + str(uuid.uuid1())
if difficulty is not None:
name += "_dif" + str(round(params[0], 2))
params = ["difficulty"] + params + [self.width, self.height]
else:
params = [self.width, self.height] + params
params = [str(param) for param in params]
param_str = " ".join(params)
file = self.dir + name + ".txt"
os.system("node " + self.script + " " + self.game + " " + file + " " + param_str)
path = os.path.abspath(file)
return path