From 0991fef527e73617114949a406e9da4632865e2d Mon Sep 17 00:00:00 2001 From: rtz19970824 <1289226405@qq.com> Date: Tue, 19 Dec 2017 15:09:46 +0800 Subject: [PATCH] deflatten debug --- AlphaGo/game.py | 10 +++++----- AlphaGo/strategy.py | 9 +++++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/AlphaGo/game.py b/AlphaGo/game.py index 3b62435..2a82d8e 100644 --- a/AlphaGo/game.py +++ b/AlphaGo/game.py @@ -46,12 +46,12 @@ class Game: def _flatten(self, vertex): x, y = vertex - return (y - 1) * self.size + (x - 1) + return (x - 1) * self.size + (y - 1) def _deflatten(self, idx): - x = idx % self.size + 1 - y = idx // self.size + 1 - return (x,y) + x = idx // self.size + 1 + y = idx % self.size + 1 + return (x, y) def clear(self): self.board = [utils.EMPTY] * (self.size ** 2) @@ -88,7 +88,7 @@ class Game: if choice == self.size ** 2: move = utils.PASS else: - move = (choice % self.size + 1, choice / self.size + 1) + move = self._deflatten(choice) return move, prob def do_move(self, color, vertex): diff --git a/AlphaGo/strategy.py b/AlphaGo/strategy.py index e9457cf..112f130 100644 --- a/AlphaGo/strategy.py +++ b/AlphaGo/strategy.py @@ -23,6 +23,11 @@ class GoEnv: x, y = vertex 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): color = self.simulate_board[self.simulate_flatten(start)] # print ("color : ", color) @@ -140,7 +145,7 @@ class GoEnv: if action == self.game.size ** 2: vertex = (0, 0) 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: color = utils.BLACK else: @@ -192,7 +197,7 @@ class GoEnv: if action == self.game.size ** 2: vertex = utils.PASS else: - vertex = (action % self.game.size + 1, action / self.game.size + 1) + vertex = self.simulate_deflatten(action) # print(vertex) # print(self.board) self.simulate_board = (state[:, :, :, 7] - state[:, :, :, 15]).reshape(-1).tolist()