Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send GTP play command according to the tree order #294

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
53 changes: 45 additions & 8 deletions src/components/App.js
Expand Up @@ -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))
}
}

Expand Down