diff --git a/src/compiled/glift.js b/src/compiled/glift.js index c6c32abf..677d8ce8 100644 --- a/src/compiled/glift.js +++ b/src/compiled/glift.js @@ -235,8 +235,8 @@ glift.rules.autonumber=function(a){var b=/\d+/,c=/0\d/;a.recurseFromRoot(functio g=h=0,k=k.stones;g=a)throw"Invalid Intersections. Was: "+a;this.ints=a||19;for(var b=[],c=0;c=a)throw"Invalid Intersections. Was: "+a;this.ints=a||19;for(var b=[],c=0;c=f.numCaptures&&(this._getCaptures(f,a, e),0=a.liberties&&a.consideringToCaptures();a.clearExceptCaptures()},_findConnected:function(a,b,c){var g=glift.util;if(void 0===a.seen[b.hash()]&&!this.outBounds(b)){a.seen[b.hash()]=!0;var h=this.getStone(b);if(h===glift.enums.states.EMPTY)a.liberties++;else if(h!==g.colors.oppositeColor(c))if(h===c)a.considering.push(b),this._findConnected(a, @@ -383,9 +383,10 @@ glift.widgets.options.BOARD_EDITOR={_markMap:{bstone_a:glift.enums.marks.LABEL_A f=b.controller.getCurrentPlayer();a[e]?(c=b.controller.addPlacement(c,a[e]),b.applyBoardData(c)):d[e]?(c=b.controller.addMark(c,d[e]))&&b.applyBoardData(c):"twostones"===e&&(c=b.controller.addStone(c,f))&&b.applyBoardData(c)},stoneMouseover:function(a,b,c){var d=glift.enums.marks,e=glift.widgets.options.BOARD_EDITOR._markMap,f=glift.widgets.options.BOARD_EDITOR._placementMap,g={BLACK:"BLACK_HOVER",WHITE:"WHITE_HOVER"},h=b.controller.getCurrentPlayer();a=b.display.intersections();var k=b.iconBar.getIcon("multiopen").getActive().iconName; void 0!==f[k]?(d=f[k],b.controller.canAddStone(c,h)&&a.setStoneColor(c,g[d])):"twostones"===k?(d=b.controller.getCurrentPlayer(),b.controller.canAddStone(c,h)&&a.setStoneColor(c,g[d])):e[k]&&!a.hasMark(c)&&(g=e[k],g===d.LABEL_NUMERIC?a.addTempMark(c,g,b.controller.currentNumericMark()):g===d.LABEL_ALPHA?a.addTempMark(c,g,b.controller.currentAlphaMark()):a.addTempMark(c,g))},stoneMouseout:function(a,b,c){var d=b.controller.getCurrentPlayer(),d=b.iconBar.getIcon("multiopen").getActive().iconName;a= b.display.intersections();if("twostones"===d||"bstone"===d||"wstone"===d)d=b.controller.getCurrentPlayer(),b.controller.canAddStone(c,d)&&a.setStoneColor(c,"EMPTY");a.clearTempMarks()},icons:["start","end","arrowleft","arrowright","twostones bstone wstone bstone_a bstone_1 bstone_triangle bstone_square nostone-xmark".split(" ")],problemConditions:{},showVariations:glift.enums.showVariations.ALWAYS,controllerFunc:glift.controllers.boardEditor}; -glift.widgets.options.CORRECT_VARIATIONS_PROBLEM={stoneClick:function(a,b,c){a=b.controller.getCurrentPlayer();a=b.controller.addStone(c,a);var d=glift.enums.problemResults;if(a.result!==d.FAILURE){b.applyBoardData(a);var e=b.sgfOptions.problemCallback;void 0===b.correctness&&(a.result===d.CORRECT?(b.iconBar.destroyTempIcons(),void 0===b.correctNextSet[c.toString()]&&(b.correctNextSet[c.toString()]=!0,b.numCorrectAnswers++,b.numCorrectAnswers===b.totalCorrectAnswers?(b.correctness=d.CORRECT,b.iconBar.addTempText("multiopen-boxonly", -b.numCorrectAnswers+"/"+b.totalCorrectAnswers,{fill:"#0CC",stroke:"#0CC"}),e(d.CORRECT)):(b.iconBar.addTempText("multiopen-boxonly",b.numCorrectAnswers+"/"+b.totalCorrectAnswers,{fill:"#000",stroke:"#000"}),setTimeout(function(){b.controller.initialize();b.applyBoardData(b.controller.getEntireBoardState())},b.sgfOptions.correctVariationsResetTime)))):a.result==d.INCORRECT&&(b.iconBar.destroyTempIcons(),b.iconBar.setCenteredTempIcon("multiopen-boxonly","cross","red"),b.iconBar.clearTempText("multiopen-boxonly"), -b.correctness=d.INCORRECT,e(d.INCORRECT)))}},showVariations:glift.enums.showVariations.NEVER,icons:["refresh","problem-explanation","multiopen-boxonly"],controllerFunc:glift.controllers.staticProblem,correctVariationsResetTime:750,statusBarIcons:["fullscreen"]};glift.widgets.options.EXAMPLE={stoneClick:function(a,b,c){},icons:[],problemConditions:{},showVariations:glift.enums.showVariations.NEVER,controllerFunc:glift.controllers.gameViewer,stoneMouseover:function(){},stoneMouseout:function(){},statusBarIcons:["fullscreen"]}; +glift.widgets.options.CORRECT_VARIATIONS_PROBLEM={stoneClick:function(a,b,c){a=b.controller.getCurrentPlayer();a=b.controller.addStone(c,a);var d=glift.enums.problemResults;if(a.result!==d.FAILURE){var e=b.hooks();b.applyBoardData(a);void 0===b.correctness&&(a.result===d.CORRECT?(b.iconBar.destroyTempIcons(),void 0===b.correctNextSet[c.toString()]&&(b.correctNextSet[c.toString()]=!0,b.numCorrectAnswers++,b.numCorrectAnswers===b.totalCorrectAnswers?(b.correctness=d.CORRECT,b.iconBar.addTempText("multiopen-boxonly", +b.numCorrectAnswers+"/"+b.totalCorrectAnswers,{fill:"#0CC",stroke:"#0CC"}),e.problemCorrect()):(b.iconBar.addTempText("multiopen-boxonly",b.numCorrectAnswers+"/"+b.totalCorrectAnswers,{fill:"#000",stroke:"#000"}),setTimeout(function(){b.controller.initialize();b.applyBoardData(b.controller.getEntireBoardState())},b.sgfOptions.correctVariationsResetTime)))):a.result==d.INCORRECT&&(b.iconBar.destroyTempIcons(),b.iconBar.setCenteredTempIcon("multiopen-boxonly","cross","red"),b.iconBar.clearTempText("multiopen-boxonly"), +b.correctness=d.INCORRECT,e.problemIncorrect()))}},showVariations:glift.enums.showVariations.NEVER,icons:["refresh","problem-explanation","multiopen-boxonly"],controllerFunc:glift.controllers.staticProblem,correctVariationsResetTime:750,statusBarIcons:["fullscreen"]}; +glift.widgets.options.EXAMPLE={stoneClick:function(a,b,c){},icons:[],problemConditions:{},showVariations:glift.enums.showVariations.NEVER,controllerFunc:glift.controllers.gameViewer,stoneMouseover:function(){},stoneMouseout:function(){},statusBarIcons:["fullscreen"]}; glift.widgets.options.GAME_VIEWER={stoneClick:function(a,b,c){a=b.controller.getCurrentPlayer();c=b.controller.addStone(c,a);b.applyBoardData(c)},keyMappings:{ARROW_LEFT:"iconActions.arrowleft.click",ARROW_RIGHT:"iconActions.arrowright.click",",":"iconActions.arrowleft.click",".":"iconActions.arrowright.click","<":"iconActions.jump-left-arrow.click",">":"iconActions.jump-right-arrow.click","]":function(a){a.controller.moveUpVariations();a.applyBoardData(a.controller.getNextBoardState())},"[":function(a){a.controller.moveDownVariations(); a.applyBoardData(a.controller.getNextBoardState())}},icons:["jump-left-arrow","jump-right-arrow","arrowleft","arrowright"],showVariations:glift.enums.showVariations.MORE_THAN_ONE,problemConditions:{},controllerFunc:glift.controllers.gameViewer,statusBarIcons:["game-info","move-indicator","fullscreen"]}; glift.widgets.options.REDUCED_GAME_VIEWER={stoneClick:function(a,b,c){a=b.controller.getCurrentPlayer();c=b.controller.addStone(c,a);b.applyBoardData(c)},icons:["arrowleft","arrowright"],problemConditions:{},showVariations:glift.enums.showVariations.MORE_THAN_ONE,controllerFunc:glift.controllers.gameViewer,statusBarIcons:["game-info","move-indicator","fullscreen"]}; diff --git a/src/compiled/glift_combined.js b/src/compiled/glift_combined.js index 07de61f4..d446081b 100644 --- a/src/compiled/glift_combined.js +++ b/src/compiled/glift_combined.js @@ -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)); } @@ -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(); @@ -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', @@ -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(); } } }, diff --git a/src/controllers/game_viewer_test.js b/src/controllers/game_viewer_test.js index fe8f431b..74ab6060 100644 --- a/src/controllers/game_viewer_test.js +++ b/src/controllers/game_viewer_test.js @@ -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(); diff --git a/src/parse/parse_test.js b/src/parse/parse_test.js index 6e51f7a5..2c5bd596 100644 --- a/src/parse/parse_test.js +++ b/src/parse/parse_test.js @@ -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; @@ -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'); + }); })(); diff --git a/src/rules/goban.js b/src/rules/goban.js index a4238272..52d081d8 100644 --- a/src/rules/goban.js +++ b/src/rules/goban.js @@ -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)); } diff --git a/src/testdata/sgfs.js b/src/testdata/sgfs.js index 7723fa50..f74d5d56 100644 --- a/src/testdata/sgfs.js +++ b/src/testdata/sgfs.js @@ -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]" + @@ -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.**])", };