Skip to content

Commit

Permalink
Add check in the goban to fix 'null' errors.
Browse files Browse the repository at this point in the history
Turns out the goban wasn't checking to make sure it was legal to traverse down
the movetree before it did so. Simple fix: make sure that the goban has
children.

Fixes #124
  • Loading branch information
artasparks committed Aug 17, 2015
1 parent 3a95c25 commit 3583f7c
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 11 deletions.
11 changes: 6 additions & 5 deletions src/compiled/glift.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions src/compiled/glift_combined.js
Original file line number Diff line number Diff line change
Expand Up @@ -7457,7 +7457,9 @@ glift.rules.goban = {
movetree = mt.getTreeFromRoot(),
captures = []; // array of captures.
goban.loadStonesFromMovetree(movetree); // Load root placements.
for (var i = 0; i < treepath.length; i++) {
for (var i = 0;
i < treepath.length && movetree.node().numChildren() > 0;
i++) {
movetree.moveDown(treepath[i]);
captures.push(goban.loadStonesFromMovetree(movetree));
}
Expand Down Expand Up @@ -13751,8 +13753,8 @@ glift.widgets.options.CORRECT_VARIATIONS_PROBLEM = {
// an illegal move.
return;
}
var hooks = widget.hooks();
widget.applyBoardData(data);
var callback = widget.sgfOptions.problemCallback;
if (widget.correctness === undefined) {
if (data.result === problemResults.CORRECT) {
widget.iconBar.destroyTempIcons();
Expand All @@ -13765,7 +13767,7 @@ glift.widgets.options.CORRECT_VARIATIONS_PROBLEM = {
'multiopen-boxonly',
widget.numCorrectAnswers + '/' + widget.totalCorrectAnswers,
{ fill: '#0CC', stroke: '#0CC'});
callback(problemResults.CORRECT);
hooks.problemCorrect();
} else {
widget.iconBar.addTempText(
'multiopen-boxonly',
Expand All @@ -13782,7 +13784,7 @@ glift.widgets.options.CORRECT_VARIATIONS_PROBLEM = {
widget.iconBar.setCenteredTempIcon('multiopen-boxonly', 'cross', 'red');
widget.iconBar.clearTempText('multiopen-boxonly');
widget.correctness = problemResults.INCORRECT;
callback(problemResults.INCORRECT);
hooks.problemIncorrect();
}
}
},
Expand Down
9 changes: 9 additions & 0 deletions src/controllers/game_viewer_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@
deepEqual(gameViewer.treepath, [], 'Gamepath set to beginning');
});

test('Test Create: 1+ initial position', function() {
var gameViewer = glift.controllers.gameViewer({
sgfString: problem,
initialPosition: '1+'
});
deepEqual(gameViewer.currentMoveNumber(), 2);
ok(gameViewer);
});

test('Test NextMove / PrevMove', function() {
var gameViewer = glift.controllers.gameViewer({ sgfString: problem });
var displayData = gameViewer.nextMove();
Expand Down
8 changes: 8 additions & 0 deletions src/parse/parse_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
module('glift.parse.parseTest');
var fromFileName = glift.parse.fromFileName;
var parseType = glift.parse.parseType;
var sgfs = testdata.sgfs

test('fromFileName', function() {
var oldFromString = glift.parse.fromString;
Expand All @@ -17,4 +18,11 @@

glift.parse.fromString = oldFromString;
});

test('from string: SGF, escaped comment', function() {
var sgf = sgfs.escapedComment;
var mt = glift.parse.fromString(sgf, parseType.SGF);
ok(mt);
ok(/Awesome!/.test(mt.properties().getComment()), 'should be awesome');
});
})();
4 changes: 3 additions & 1 deletion src/rules/goban.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ glift.rules.goban = {
movetree = mt.getTreeFromRoot(),
captures = []; // array of captures.
goban.loadStonesFromMovetree(movetree); // Load root placements.
for (var i = 0; i < treepath.length; i++) {
for (var i = 0;
i < treepath.length && movetree.node().numChildren() > 0;
i++) {
movetree.moveDown(treepath[i]);
captures.push(goban.loadStonesFromMovetree(movetree));
}
Expand Down
4 changes: 3 additions & 1 deletion src/testdata/sgfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ testdata.sgfs = {
"RU[Japanese]SZ[19]KM[0.00]\n" +
"PW[White]PB[Black])",

escapedComment: "(;GM[1]FF[4]C[Josh[1k\\]: Go is Awesome!])",

veryeasy:
"(;GM[1]FF[4]CA[UTF-8]AP[CGoban:3]ST[2]\n" +
"C[Here's a basic example problem]" +
Expand Down Expand Up @@ -215,5 +217,5 @@ testdata.sgfs = {
"" +
"Black 125 was the losing move. Black should have played Black 125 at Black 145 instead." +
"" +
"**228 moves: White won by resignation.**])"
"**228 moves: White won by resignation.**])",
};

0 comments on commit 3583f7c

Please sign in to comment.