Commit e870d10a authored by Shengyi Jiang's avatar Shengyi Jiang
Browse files

minor code inspection correction

parent 845cec59
......@@ -18,20 +18,22 @@ class Game2048Env(gym.Env):
self.observation_space = gym.spaces.Box(low=0, high=2048, shape=(4, 4))
self.render = render
self.done = False
self.state = [[0, 0, 0, 0] for i in range(4)]
self.state = [[0, 0, 0, 0] for _ in range(4)]
self.score = 0
self.score_dict = {}
for num in range(1, 12):
self.score_dict[2 ** num] = 2 ** (num - 1)
self.episode_length = 0
self.info = {}
self.port = None
self.gui_process = None
if self.render:
self._GUIRun()
msg = self.port.recv()
assert msg == 'init_ok'
def reset(self):
self.state = [[0, 0, 0, 0] for i in range(4)]
self.state = [[0, 0, 0, 0] for _ in range(4)]
self._generateNew(2)
self.done = False
self.info = {}
......@@ -41,6 +43,7 @@ class Game2048Env(gym.Env):
self.port.send(("reset", (self.score, self.state)))
msg = self.port.recv()
assert msg == 'reset_ok'
return self.state.copy()
# returns obs, rew, done, info
def step(self, action: int):
......@@ -126,7 +129,7 @@ class Game2048Env(gym.Env):
self.port.send(("step", (self.score, self.state)))
msg = self.port.recv()
assert msg == 'step_ok'
return self.state, self.score - prev_score, self.done, self.info
return self.state.copy(), self.score - prev_score, self.done, self.info
def close(self):
if self.port is not None:
......@@ -182,7 +185,7 @@ class Game2048Env(gym.Env):
def _initGUI(self, port, remote_port):
app = QApplication(sys.argv)
qt_game = Game2048GUI(port, remote_port)
Game2048GUI(port, remote_port)
sys.exit(app.exec_())
def _checkBoard(self):
......@@ -248,7 +251,7 @@ class Game2048GUI(QMainWindow):
def _initUI(self):
self.color_dict = {}
self.score = 0
self.state = [[0, 0, 0, 0] for i in range(4)]
self.state = [[0, 0, 0, 0] for _ in range(4)]
# you can change to whatever you like :)
self.color_dict[0] = 'white'
......@@ -297,7 +300,7 @@ class Game2048GUI(QMainWindow):
def _initBoardUI(self):
self.scoreboard.setText('Score : {}'.format(0))
self.state_labels = [[0, 0, 0, 0] for i in range(4)]
self.state_labels = [[0, 0, 0, 0] for _ in range(4)]
for i in range(4):
for j in range(4):
self.state_labels[i][j] = QLabel(self)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment