def encode(self, game_state): board_tensor = np.zeros(self.shape()) current_player = game_state.current_player next_player = game_state.current_player.other if current_player == Player.yellow: board_tensor[0, :, :] = 1 for r in range(self.board_height): for c in range(self.board_width): p = Point(row=r + 1, col=c + 1) occupied = game_state.board.get(p) if occupied == None: # empty, check if completes canoe if game_state.board.is_on_grid(p): board_tensor[3][r][c] = 1 if game_state.completes_canoe(p, current_player): board_tensor[4][r][c] = 1 if game_state.completes_canoe(p, next_player): board_tensor[5][r][c] = 1 elif occupied == current_player: board_tensor[1][r][c] = 1 else: board_tensor[2][r][c] = 1 return board_tensor
def decode_point_index(self, index): r = index // self.board_width c = index % self.board_width return Point(row=r + 1, col=c + 1)