# 改变棋盘编码方式，增强围棋机器人的智能肌肉

```class  SevenPlaneEncoder(Encoder):
def  __init__(self, board_size):
self.board_width, self.board_height = board_size
self.num_planes = 7
def  name(self):
return "sevenplane"
def  encode(self, game_state):
board_tensor = np.zeros(self.shape())
base_plane = {gampe_state.next_player: 0,
game_state.next_player.other: 3}
for row in range(self.board_height):
for col in range(self.board_width):
p = Point(row = row + 1, col = col + 1)
go_string = game_state.board.get_go_string(p)
if go_string is None:
if game_state.does_move_violate_ko(game_state.next_player,
Move.play(p)):
#将当前落子方会形成ko的位置设置为1
board_tensor[6][row][col] = 1
else:
'''
第二层编码拥有2个自由点的棋子，第3层编码拥有3个或以上自由点的棋子
'''
liberty_plane = min(3, go_string.num_liberties) - 1
#落子方编码在第2，3层，对方编码在第5，6层
liberty_plane += base_plane[go_string.color]
board_tensor[liberty_plane][row][col] = 1
return board_tensor```

```def  encode_point(self, point):
return self.board_with * (point.row - 1) + (point.col - 1)

def  decode_point_index(self, index):
row = index // self.board_width
col = index % self.board_width
return Point(row = row + 1, col + 1)

def  num_points(self):
return self.board_width * self.board_height
def shape(self):
return self.num_planes, self.board_height, self.width

def  create(board_size):
return SevenPlaneEncoder(board_size)```

```#momentum 对应上面公式中的b
#lr 对应学习率
#decay 对应学习率缩小比率
sgd = SGD(lr = 0.1, momentum = 0.9, decay = 0.01)```

`adagrad = Adagrad()`

144 篇文章41 人订阅

0 条评论