deflatten debug
This commit is contained in:
parent
e168df5609
commit
d7b3b6aba9
@ -46,12 +46,12 @@ class Game:
|
|||||||
|
|
||||||
def _flatten(self, vertex):
|
def _flatten(self, vertex):
|
||||||
x, y = vertex
|
x, y = vertex
|
||||||
return (y - 1) * self.size + (x - 1)
|
return (x - 1) * self.size + (y - 1)
|
||||||
|
|
||||||
def _deflatten(self, idx):
|
def _deflatten(self, idx):
|
||||||
x = idx % self.size + 1
|
x = idx // self.size + 1
|
||||||
y = idx // self.size + 1
|
y = idx % self.size + 1
|
||||||
return (x,y)
|
return (x, y)
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
self.board = [utils.EMPTY] * (self.size ** 2)
|
self.board = [utils.EMPTY] * (self.size ** 2)
|
||||||
@ -88,7 +88,7 @@ class Game:
|
|||||||
if choice == self.size ** 2:
|
if choice == self.size ** 2:
|
||||||
move = utils.PASS
|
move = utils.PASS
|
||||||
else:
|
else:
|
||||||
move = (choice % self.size + 1, choice / self.size + 1)
|
move = self._deflatten(choice)
|
||||||
return move, prob
|
return move, prob
|
||||||
|
|
||||||
def do_move(self, color, vertex):
|
def do_move(self, color, vertex):
|
||||||
|
@ -23,6 +23,11 @@ class GoEnv:
|
|||||||
x, y = vertex
|
x, y = vertex
|
||||||
return (x - 1) * self.game.size + (y - 1)
|
return (x - 1) * self.game.size + (y - 1)
|
||||||
|
|
||||||
|
def simulate_deflatten(self, idx):
|
||||||
|
x = idx // self.game.size + 1
|
||||||
|
y = idx % self.game.size + 1
|
||||||
|
return (x, y)
|
||||||
|
|
||||||
def _find_group(self, start):
|
def _find_group(self, start):
|
||||||
color = self.simulate_board[self.simulate_flatten(start)]
|
color = self.simulate_board[self.simulate_flatten(start)]
|
||||||
# print ("color : ", color)
|
# print ("color : ", color)
|
||||||
@ -140,7 +145,7 @@ class GoEnv:
|
|||||||
if action == self.game.size ** 2:
|
if action == self.game.size ** 2:
|
||||||
vertex = (0, 0)
|
vertex = (0, 0)
|
||||||
else:
|
else:
|
||||||
vertex = (action / self.game.size + 1, action % self.game.size + 1)
|
vertex = self.simulate_deflatten(action)
|
||||||
if state[0, 0, 0, -1] == utils.BLACK:
|
if state[0, 0, 0, -1] == utils.BLACK:
|
||||||
color = utils.BLACK
|
color = utils.BLACK
|
||||||
else:
|
else:
|
||||||
@ -192,7 +197,7 @@ class GoEnv:
|
|||||||
if action == self.game.size ** 2:
|
if action == self.game.size ** 2:
|
||||||
vertex = utils.PASS
|
vertex = utils.PASS
|
||||||
else:
|
else:
|
||||||
vertex = (action % self.game.size + 1, action / self.game.size + 1)
|
vertex = self.simulate_deflatten(action)
|
||||||
# print(vertex)
|
# print(vertex)
|
||||||
# print(self.board)
|
# print(self.board)
|
||||||
self.simulate_board = (state[:, :, :, 7] - state[:, :, :, 15]).reshape(-1).tolist()
|
self.simulate_board = (state[:, :, :, 7] - state[:, :, :, 15]).reshape(-1).tolist()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user