From 28e4d259b7474542a5434b9c0e16dd03914a961c Mon Sep 17 00:00:00 2001 From: aq_dogmoves Date: Mon, 16 Oct 2017 21:18:49 +0900 Subject: [PATCH] Send GTP Play command according to the order --- src/components/App.js | 53 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/src/components/App.js b/src/components/App.js index 435b8d930..73a0b69ab 100644 --- a/src/components/App.js +++ b/src/components/App.js @@ -2039,17 +2039,54 @@ class App extends Component { this.sendGTPCommand(controller, new gtp.Command(null, 'boardsize', board.width)) this.sendGTPCommand(controller, new gtp.Command(null, 'clear_board')) - for (let x = 0; x < board.width; x++) { - for (let y = 0; y < board.height; y++) { - let vertex = [x, y] - let sign = board.get(vertex) - if (sign === 0) continue + let vertexSequence = [] + let colorSequence = [] + let tree = this.state.treePosition[0] + let index = this.state.treePosition[1] + let stoneData = { B: 1, W: -1 } + let handicapData = { AB: "B", AW: "W" } + + let prevExist = true + while (prevExist) { + prevExist = false + + if (index >= 0) { + let node = tree.nodes[index] + for (let prop in stoneData) { + if (!(prop in node)) continue + + colorSequence.unshift(prop) + vertexSequence.unshift(node[prop][0]) + break + } - let color = sign > 0 ? 'B' : 'W' - let point = board.vertex2coord(vertex) + for (let prop in handicapData) { + if (!(prop in node)) continue - this.sendGTPCommand(controller, new gtp.Command(null, 'play', color, point)) + for (let value of node[prop]) { + colorSequence.unshift(handicapData[prop]) + vertexSequence.unshift(value) + } + } + } + + if (index - 1 >= 0) { + index = index - 1 + prevExist = true } + else if (tree.parent != null) { + tree = tree.parent + index = tree.nodes.length - 1 + prevExist = true + } + } + + for (let i = 0, n = colorSequence.length; i < n; ++i) { + let color = colorSequence[i] + let vertex = sgf.point2vertex(vertexSequence[i]) + let point = board.vertex2coord(vertex) + + this.sendGTPCommand(controller, new gtp.Command(null, 'play', color, point)) } }