Skip to content

Commit

Permalink
Board.ghosts is now a dictionary
Browse files Browse the repository at this point in the history
  • Loading branch information
yishn committed Mar 8, 2017
1 parent 2e180c7 commit 6bcc0a0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
30 changes: 15 additions & 15 deletions browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,21 @@ sabaki.setBoard = function(board) {
$li.toggleClass('smalllabel', label.length >= 3)
}

// Add ghost stone

if ([x, y] in board.ghosts) {
let [s, types] = board.ghosts[[x, y]]

for (let type of types) {
if (type == 'child') $li.addClass('ghost_' + s)
else if (type == 'sibling') $li.addClass('siblingghost_' + s)
else if (type == 'badmove') $li.addClass('badmove')
else if (type == 'doubtfulmove') $li.addClass('doubtfulmove')
else if (type == 'interestingmove') $li.addClass('interestingmove')
else if (type == 'goodmove') $li.addClass('goodmove')
}
}

// Set stone image

if ($li.hasClass('sign_' + sign)) continue
Expand All @@ -275,21 +290,6 @@ sabaki.setBoard = function(board) {
}
}

// Add ghosts

for (let [v, s, types] of board.ghosts) {
let $li = $('#goban .pos_' + v.join('-'))

for (let type of types) {
if (type == 'child') $li.addClass('ghost_' + s)
else if (type == 'sibling') $li.addClass('siblingghost_' + s)
else if (type == 'badmove') $li.addClass('badmove')
else if (type == 'doubtfulmove') $li.addClass('doubtfulmove')
else if (type == 'interestingmove') $li.addClass('interestingmove')
else if (type == 'goodmove') $li.addClass('goodmove')
}
}

// Add lines

$('#goban hr').remove()
Expand Down
2 changes: 1 addition & 1 deletion modules/board.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Board {
this.captures = {'-1': captures['-1'], '1': captures['1']}
this.arrangement = []
this.markups = {}
this.ghosts = []
this.ghosts = {}
this.lines = []

// Initialize arrangement
Expand Down
5 changes: 2 additions & 3 deletions modules/gametree.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ exports.getBoard = function(tree, index = 0, baseboard = null) {
return
}

if (board.ghosts.some(([w]) => w[0] == v[0] && w[1] == v[1]))
if (v in board.ghosts || !board.hasVertex(v))
return

let types = [type]
Expand All @@ -508,8 +508,7 @@ exports.getBoard = function(tree, index = 0, baseboard = null) {
}
}

if (!board.hasVertex(v)) return
board.ghosts.push([v, sign, types])
board.ghosts[v] = [sign, types]
}

if (index == tree.nodes.length - 1) {
Expand Down

0 comments on commit 6bcc0a0

Please sign in to comment.