From 5ee676ed70b9e4824c6cbe76442b376888e6c2f8 Mon Sep 17 00:00:00 2001 From: Eric Campbell <1234goal@gmail.com> Date: Thu, 5 Nov 2015 21:26:59 -0800 Subject: [PATCH 1/5] clarify logic and parameter passing --- app/controllers/MathSwipeController.coffee | 38 ++++--- app/services/ShareGameService.coffee | 47 ++++---- bundle.js | 120 ++++++++++++--------- 3 files changed, 121 insertions(+), 84 deletions(-) diff --git a/app/controllers/MathSwipeController.coffee b/app/controllers/MathSwipeController.coffee index 1aa2d84..3725267 100644 --- a/app/controllers/MathSwipeController.coffee +++ b/app/controllers/MathSwipeController.coffee @@ -33,26 +33,25 @@ class MathSwipeController TrackingService.desktopView() @cursorToPointer() ShareGameService.setMessage() - @initialize window.location.hash + @initialize window.location.hash, 3 # # Uncomment the following line to perform general tests # GeneralTests.tests @board - initialize: (hash) -> + initialize: (hash, length = 3) -> solutionPlacements = [] - goals = [] + inputLengths = [] boardValues = [] - hasCompleteBoard = false - if hash? and hash isnt '' - hasCompleteBoard = ShareGameService.decode boardValues, goals, solutionPlacements - unless hasCompleteBoard - length = 3 - goals = [] - solutionPlacements = [] - inputs = [] - inputLengths = RandomizedFitLength.generate length * length - @generateInputs inputLengths, inputs, goals - boardValues = @generateBoard inputs, length, solutionPlacements + inputs = [] + goals = [] + + decoded = ShareGameService.decodeMap() + [boardValues, goals, solutionPlacements] = ShareGameService.parse decoded + + if @malformedDecode boardValues, goals, solutionPlacements + inputLengths = RandomizedFitLength.generate length ** 2 + [inputs, goals] = @generateInputs inputLengths + boardValues = @generateBoard inputs, length, solutionPlacements @goalContainer = new GoalContainer goals, Colors @board = new Board boardValues, @gameScene, goals, @symbols, @@ -62,8 +61,9 @@ class MathSwipeController ResetButton.bindClick @board, RunningSum RunningSum.empty() + @createNewGame() unless ShareGameService.reloadPageWithHash(@board, - solutionPlacements, SolutionService) + solutionPlacements, SolutionService) isMobile: () -> Android: () -> @@ -124,14 +124,18 @@ class MathSwipeController generateBoard: (inputs, length, solutionPlacements) -> DFS.setEquationsOnGrid length, inputs, AdjacentCellsCalculator, solutionPlacements - generateInputs: (inputLengths, inputs, goals) -> + generateInputs: (inputLengths, goals = [], inputs = []) -> for inputSize in inputLengths value = -1 while value < 1 or value > 300 expression = ExpressionGenerator.generate inputSize value = InputSolver.compute expression goals.push (InputSolver.compute expression) - inputs.push expression.split('') + inputs.push (expression.split('')) + [inputs, goals] + + malformedDecode: (boardValues, goals, solutionPlacements) -> + boardValues.length < 1 or goals.length < 1 or solutionPlacements.length < 1 randExpression: (length) -> ExpressionGenerator.generate length diff --git a/app/services/ShareGameService.coffee b/app/services/ShareGameService.coffee index 5235ed0..0e7f1b9 100644 --- a/app/services/ShareGameService.coffee +++ b/app/services/ShareGameService.coffee @@ -4,6 +4,7 @@ class ShareGameService @reloadPageWithHash: (board, solutionPlacements, SolutionService) -> unless @checkSolutionPlacements board, solutionPlacements, SolutionService + console.log "bad solution placements, resetting hash" window.location.hash = '' return false hash = @encode board.initialValues, board.goals, solutionPlacements @@ -20,22 +21,31 @@ class ShareGameService btoa(JSON.stringify {b: boardValues, g: goals, p: solutionPlacements}) - @decode: (boardValues, goals, solutionPlacements) -> + @decodeMap: () -> try - decoded = atob window.location.hash.substr(1, window.location.hash.length) - decoded = JSON.parse decoded + decoded_s = atob window.location.hash.substr(1, window.location.hash.length) + decoded = JSON.parse decoded_s catch e decoded = null - return false unless decoded? and decoded.b? and decoded.g? and - decoded.p? and @isValidDecode decoded + return decoded + @parse: (decoded) -> + return [[],[],[]] unless @successfulDecode decoded + console.log "Successful decode!" length = Math.sqrt decoded.b.length - @decodeBoardValues decoded.b, boardValues, length - @decodeGoals decoded.g, goals - @decodeSolutionPlacements decoded.p, solutionPlacements, length - true - - @isValidDecode: (decoded) -> + b = @decodeBoardValues decoded.b, length + g = @decodeGoals decoded.g + p = @decodeSolutionPlacements decoded.p, length + [b, g, p] + + @successfulDecode: (decoded)-> + return decoded? and + decoded.p? and + decoded.g? and + decoded.p? and + @regexPass decoded + + @regexPass: (decoded) -> alphabet = ['"', '{', '}', '[', ']', ',', ':', 'b', 'g', 'p', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', @@ -44,24 +54,27 @@ class ShareGameService return false if alphabet.indexOf(char) is -1 true - @decodeBoardValues: (copy, boardValues, length) -> + @decodeBoardValues: (copy, length, boardValues=[] ) -> index = 0 for i in [0...length] row = [] for j in [0...length] row.push copy[index++] boardValues.push row + boardValues - @decodeGoals: (copy, goals) -> - goals.push goal for goal in copy + @decodeGoals: (toCopy) -> + console.log "goals", toCopy + toCopy[..] - @decodeSolutionPlacements: (copy, solutionPlacements, length) -> + @decodeSolutionPlacements: (copy, length, solutionPlacements=[]) -> for list in [0...copy.length] expression = [] for coord in [0...copy[list].length] expression.push [(Math.floor copy[list][coord] / length), (copy[list][coord] % length)] solutionPlacements.push expression + solutionPlacements @checkSolutionPlacements: (board, solutionPlacements, SolutionService) -> @initializeTempBoard board @@ -81,8 +94,7 @@ class ShareGameService @tempBoard.boardValues[cell.row][cell.col] = ' ' @pushDownTempBoard() - unless @solutionService.isSolution() - return false + return false unless @solutionService.isSolution() inputs.push solution console.log expression for expression in inputs @@ -120,5 +132,4 @@ class ShareGameService console.log $('#fb-share') $( '#fb-share' ).attr( 'data-href' , window.location.hash ) - module.exports = ShareGameService diff --git a/bundle.js b/bundle.js index 85e7e4d..50edeeb 100644 --- a/bundle.js +++ b/bundle.js @@ -9351,25 +9351,23 @@ TrackingService.desktopView(); this.cursorToPointer(); } - this.initialize(window.location.hash); + ShareGameService.setMessage(); + this.initialize(window.location.hash, 3); } - MathSwipeController.prototype.initialize = function(hash) { - var boardValues, goals, hasCompleteBoard, inputLengths, inputs, length, solutionPlacements; - solutionPlacements = []; - goals = []; - boardValues = []; - hasCompleteBoard = false; - if ((hash != null) && hash !== '') { - hasCompleteBoard = ShareGameService.decode(boardValues, goals, solutionPlacements); - } - if (!hasCompleteBoard) { + MathSwipeController.prototype.initialize = function(hash, length) { + var boardValues, decoded, goals, inputLengths, inputs, ref, ref1, solutionPlacements; + if (length == null) { length = 3; - goals = []; - solutionPlacements = []; - inputs = []; + } + solutionPlacements = goals = boardValues = inputs = inputLengths = []; + decoded = ShareGameService.decodeMap(); + console.log(decoded); + ref = ShareGameService.parse(decoded), boardValues = ref[0], goals = ref[1], solutionPlacements = ref[2]; + if (boardValues.length < 1) { + console.log("Unsuccessful decode!"); inputLengths = RandomizedFitLength.generate(length * length); - this.generateInputs(inputLengths, inputs, goals); + ref1 = this.generateInputs(inputLengths), inputs = ref1[0], goals = ref1[1]; boardValues = this.generateBoard(inputs, length, solutionPlacements); } this.goalContainer = new GoalContainer(goals, Colors); @@ -9460,9 +9458,14 @@ return DFS.setEquationsOnGrid(length, inputs, AdjacentCellsCalculator, solutionPlacements); }; - MathSwipeController.prototype.generateInputs = function(inputLengths, inputs, goals) { - var expression, i, inputSize, len, results, value; - results = []; + MathSwipeController.prototype.generateInputs = function(inputLengths, goals, inputs) { + var expression, i, inputSize, len, value; + if (goals == null) { + goals = []; + } + if (inputs == null) { + inputs = []; + } for (i = 0, len = inputLengths.length; i < len; i++) { inputSize = inputLengths[i]; value = -1; @@ -9471,9 +9474,9 @@ value = InputSolver.compute(expression); } goals.push(InputSolver.compute(expression)); - results.push(inputs.push(expression.split(''))); + inputs.push(expression.split('')); } - return results; + return [inputs, goals]; }; MathSwipeController.prototype.randExpression = function(length) { @@ -10393,6 +10396,7 @@ ShareGameService.reloadPageWithHash = function(board, solutionPlacements, SolutionService) { var hash; if (!this.checkSolutionPlacements(board, solutionPlacements, SolutionService)) { + console.log("bad solution placements, resetting hash"); window.location.hash = ''; return false; } @@ -10416,26 +10420,36 @@ })); }; - ShareGameService.decode = function(boardValues, goals, solutionPlacements) { - var decoded, e, length; + ShareGameService.decodeMap = function() { + var decoded, decoded_s, e; try { - decoded = atob(window.location.hash.substr(1, window.location.hash.length)); - decoded = JSON.parse(decoded); + decoded_s = atob(window.location.hash.substr(1, window.location.hash.length)); + decoded = JSON.parse(decoded_s); } catch (_error) { e = _error; decoded = null; } - if (!((decoded != null) && (decoded.b != null) && (decoded.g != null) && (decoded.p != null) && this.isValidDecode(decoded))) { - return false; + return decoded; + }; + + ShareGameService.parse = function(decoded) { + var b, g, length, p; + if (!this.successfulDecode(decoded)) { + return [[], [], []]; } + console.log("Successful decode!"); length = Math.sqrt(decoded.b.length); - this.decodeBoardValues(decoded.b, boardValues, length); - this.decodeGoals(decoded.g, goals); - this.decodeSolutionPlacements(decoded.p, solutionPlacements, length); - return true; + b = this.decodeBoardValues(decoded.b, length); + g = this.decodeGoals(decoded.g); + p = this.decodeSolutionPlacements(decoded.p, length); + return [b, g, p]; }; - ShareGameService.isValidDecode = function(decoded) { + ShareGameService.successfulDecode = function(decoded) { + return (decoded != null) && (decoded.p != null) && (decoded.g != null) && (decoded.p != null) && this.regexPass(decoded); + }; + + ShareGameService.regexPass = function(decoded) { var alphabet, char, k, len; alphabet = ['"', '{', '}', '[', ']', ',', ':', 'b', 'g', 'p', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '+', '-', '*']; for (k = 0, len = decoded.length; k < len; k++) { @@ -10447,41 +10461,40 @@ return true; }; - ShareGameService.decodeBoardValues = function(copy, boardValues, length) { - var i, index, j, k, l, ref, ref1, results, row; + ShareGameService.decodeBoardValues = function(copy, length, boardValues) { + var i, index, j, k, l, ref, ref1, row; + if (boardValues == null) { + boardValues = []; + } index = 0; - results = []; for (i = k = 0, ref = length; 0 <= ref ? k < ref : k > ref; i = 0 <= ref ? ++k : --k) { row = []; for (j = l = 0, ref1 = length; 0 <= ref1 ? l < ref1 : l > ref1; j = 0 <= ref1 ? ++l : --l) { row.push(copy[index++]); } - results.push(boardValues.push(row)); + boardValues.push(row); } - return results; + return boardValues; }; - ShareGameService.decodeGoals = function(copy, goals) { - var goal, k, len, results; - results = []; - for (k = 0, len = copy.length; k < len; k++) { - goal = copy[k]; - results.push(goals.push(goal)); - } - return results; + ShareGameService.decodeGoals = function(toCopy) { + console.log("goals", toCopy); + return toCopy.slice(0); }; - ShareGameService.decodeSolutionPlacements = function(copy, solutionPlacements, length) { - var coord, expression, k, l, list, ref, ref1, results; - results = []; + ShareGameService.decodeSolutionPlacements = function(copy, length, solutionPlacements) { + var coord, expression, k, l, list, ref, ref1; + if (solutionPlacements == null) { + solutionPlacements = []; + } for (list = k = 0, ref = copy.length; 0 <= ref ? k < ref : k > ref; list = 0 <= ref ? ++k : --k) { expression = []; for (coord = l = 0, ref1 = copy[list].length; 0 <= ref1 ? l < ref1 : l > ref1; coord = 0 <= ref1 ? ++l : --l) { expression.push([Math.floor(copy[list][coord] / length), copy[list][coord] % length]); } - results.push(solutionPlacements.push(expression)); + solutionPlacements.push(expression); } - return results; + return solutionPlacements; }; ShareGameService.checkSolutionPlacements = function(board, solutionPlacements, SolutionService) { @@ -10581,6 +10594,15 @@ return this.tempBoard.boardValues[r2][c2] = temp; }; + ShareGameService.setMessage = function() { + var possible, text; + possible = ['Play MathSwipe with me! Try to beat my score at', 'Play MathSwipe with me! Try to solve my board at', 'Play MathSwipe with me! Solve my puzzle at']; + text = possible[Math.floor(Math.random() * 3)]; + $('#tweet').attr('data-text', text); + console.log($('#fb-share')); + return $('#fb-share').attr('data-href', window.location.hash); + }; + return ShareGameService; })(); From 00b3f7b213ed5c12100e62fbc85887bfd43f3dbf Mon Sep 17 00:00:00 2001 From: Eric Campbell <1234goal@gmail.com> Date: Thu, 5 Nov 2015 21:46:09 -0800 Subject: [PATCH 2/5] Simplify SolutionService --- app/services/SolutionService.coffee | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/app/services/SolutionService.coffee b/app/services/SolutionService.coffee index 64a1d03..b07685d 100644 --- a/app/services/SolutionService.coffee +++ b/app/services/SolutionService.coffee @@ -11,17 +11,18 @@ class SolutionService @value = InputSolver.compute @solution isSolution: -> - return false unless @solution? - return false if @solution[@solution.length - 1] is '+' or - @solution[@solution.length - 1] is '-' or - @solution[@solution.length - 1] is '*' - return false unless @value in @goals - if not @isCompleteExpression() + return false unless @solution? and @finished and @value in @goals + if @isCompleteExpression() + @valueIndex = @goals.indexOf @value + @goals[@valueIndex] = ' ' + true + else @RunningSum.display @RunningSum.solutionOperatorString - return false - @valueIndex = @goals.indexOf @value - @goals[@valueIndex] = ' ' - true + false + + finished: -> + @solution[@solution.length - 1] not in "+-*" and + @solution[0] not in "+-*" isCompleteExpression: -> @solution.search(/-?\d+[-+\*]\d+/g) is 0 From 8b7c719a9170ee4563b653908b3fd44daaf7b3ab Mon Sep 17 00:00:00 2001 From: Eric Campbell <1234goal@gmail.com> Date: Thu, 5 Nov 2015 22:27:43 -0800 Subject: [PATCH 3/5] Fix bug and remove logs --- app/services/ClickHandler.coffee | 12 ++++-------- app/services/ShareGameService.coffee | 6 +----- app/services/SolutionService.coffee | 8 +++----- 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/app/services/ClickHandler.coffee b/app/services/ClickHandler.coffee index 599ab06..359451c 100644 --- a/app/services/ClickHandler.coffee +++ b/app/services/ClickHandler.coffee @@ -9,8 +9,7 @@ class ClickHandler @clicked = [] @mouseDown = false - setMouseAsDown: -> - @mouseDown = true + setMouseAsDown: -> @mouseDown = true setMouseAsUp: -> unless @isMobile @@ -23,19 +22,16 @@ class ClickHandler @RunningSum.display @RunningSum.tilesEmptyString @mouseDown = false - isMouseDown: -> - @mouseDown + isMouseDown: -> @mouseDown - isOnMobile: -> - @isMobile + isOnMobile: -> @isMobile bindDefaultMouseEvents: -> body = $('body') body.click (e) => e.preventDefault() @unselectAll() - body.mousedown (e) => - e.preventDefault() + body.mousedown (e) => e.preventDefault() body.mouseup (e) => e.preventDefault() @unselectAll() unless @isMobile diff --git a/app/services/ShareGameService.coffee b/app/services/ShareGameService.coffee index 0e7f1b9..1d75a60 100644 --- a/app/services/ShareGameService.coffee +++ b/app/services/ShareGameService.coffee @@ -4,7 +4,6 @@ class ShareGameService @reloadPageWithHash: (board, solutionPlacements, SolutionService) -> unless @checkSolutionPlacements board, solutionPlacements, SolutionService - console.log "bad solution placements, resetting hash" window.location.hash = '' return false hash = @encode board.initialValues, board.goals, solutionPlacements @@ -31,7 +30,6 @@ class ShareGameService @parse: (decoded) -> return [[],[],[]] unless @successfulDecode decoded - console.log "Successful decode!" length = Math.sqrt decoded.b.length b = @decodeBoardValues decoded.b, length g = @decodeGoals decoded.g @@ -63,9 +61,7 @@ class ShareGameService boardValues.push row boardValues - @decodeGoals: (toCopy) -> - console.log "goals", toCopy - toCopy[..] + @decodeGoals: (toCopy) -> toCopy[..] @decodeSolutionPlacements: (copy, length, solutionPlacements=[]) -> for list in [0...copy.length] diff --git a/app/services/SolutionService.coffee b/app/services/SolutionService.coffee index b07685d..b82286c 100644 --- a/app/services/SolutionService.coffee +++ b/app/services/SolutionService.coffee @@ -3,8 +3,7 @@ InputSolver = require './InputSolver' class SolutionService constructor: (@board, goals, @RunningSum) -> - @goals = [] - @goals.push g for g in goals + @goals = goals[..] initialize: (clickedCells) -> @setSolutionString clickedCells @@ -12,6 +11,7 @@ class SolutionService isSolution: -> return false unless @solution? and @finished and @value in @goals + if @isCompleteExpression() @valueIndex = @goals.indexOf @value @goals[@valueIndex] = ' ' @@ -20,9 +20,7 @@ class SolutionService @RunningSum.display @RunningSum.solutionOperatorString false - finished: -> - @solution[@solution.length - 1] not in "+-*" and - @solution[0] not in "+-*" + finished: -> @solution[@solution.length - 1] not in "+-*" isCompleteExpression: -> @solution.search(/-?\d+[-+\*]\d+/g) is 0 From dcc3bc4a76ab54912ada810fe3c0a8319b6307f3 Mon Sep 17 00:00:00 2001 From: Eric Campbell <1234goal@gmail.com> Date: Thu, 5 Nov 2015 23:27:47 -0800 Subject: [PATCH 4/5] create hashing service --- app/controllers/MathSwipeController.coffee | 7 +- app/services/HashingService.coffee | 125 +++++++++++++++++++++ app/services/ShareGameService.coffee | 117 ------------------- 3 files changed, 129 insertions(+), 120 deletions(-) create mode 100644 app/services/HashingService.coffee diff --git a/app/controllers/MathSwipeController.coffee b/app/controllers/MathSwipeController.coffee index 3725267..60211f2 100644 --- a/app/controllers/MathSwipeController.coffee +++ b/app/controllers/MathSwipeController.coffee @@ -4,6 +4,7 @@ BoardSolvedService = require '../services/BoardSolvedService' ClickHandler = require '../services/ClickHandler' DFS = require '../services/DFS' ExpressionGenerator = require '../services/ExpressionGenerator' +HashingService = require '../services/HashingService' HowToPlay = require '../services/HowToPlay' InputSolver = require '../services/InputSolver' RandomizedFitLength = require '../services/RandomizedFitLength' @@ -45,8 +46,8 @@ class MathSwipeController inputs = [] goals = [] - decoded = ShareGameService.decodeMap() - [boardValues, goals, solutionPlacements] = ShareGameService.parse decoded + decoded = HashingService.decodeMap() + [boardValues, goals, solutionPlacements] = HashingService.parse decoded if @malformedDecode boardValues, goals, solutionPlacements inputLengths = RandomizedFitLength.generate length ** 2 @@ -62,7 +63,7 @@ class MathSwipeController ResetButton.bindClick @board, RunningSum RunningSum.empty() - @createNewGame() unless ShareGameService.reloadPageWithHash(@board, + @createNewGame() unless HashingService.reloadPageWithHash(@board, solutionPlacements, SolutionService) isMobile: () -> diff --git a/app/services/HashingService.coffee b/app/services/HashingService.coffee new file mode 100644 index 0000000..f62abaa --- /dev/null +++ b/app/services/HashingService.coffee @@ -0,0 +1,125 @@ +class HashingService + + @reloadPageWithHash: (board, solutionPlacements, SolutionService) -> + unless @checkSolutionPlacements board, solutionPlacements, SolutionService + @emptyHash() + return false + HashingService.setHash board.initialValues, board.goals, solutionPlacements + + @emptyHash: -> window.location.hash = '' + + @setHash: (boardValues, goals, solutionPlacements) -> + window.location.hash = @encode boardValues, goals, solutionPlacements + + @encode: (boardValues, goals, solutionPlacements) -> + boardValues = (JSON.stringify boardValues).replace(/(\[|\]|"|,|{|})*/g, '') + + length = Math.sqrt boardValues.length + for list in [0...solutionPlacements.length] + for pos in [0...solutionPlacements[list].length] + solutionPlacements[list][pos] = + solutionPlacements[list][pos][0] * length + + solutionPlacements[list][pos][1] + + btoa(JSON.stringify {b: boardValues, g: goals, p: solutionPlacements}) + + @decodeMap: () -> + try + decoded_s = atob window.location.hash.substr(1, window.location.hash.length) + decoded = JSON.parse decoded_s + catch e + decoded = null + return decoded + + @parse: (decoded) -> + return [[],[],[]] unless @successfulDecode decoded + length = Math.sqrt decoded.b.length + b = @decodeBoardValues decoded.b, length + g = @decodeGoals decoded.g + p = @decodeSolutionPlacements decoded.p, length + [b, g, p] + + @successfulDecode: (decoded)-> + return decoded? and + decoded.p? and + decoded.g? and + decoded.p? and + @regexPass decoded + + @regexPass: (decoded) -> + alphabet = ['"', '{', '}', '[', ']', ',', ':', + 'b', 'g', 'p', '1', '2', '3', '4', + '5', '6', '7', '8', '9', '0', + '+', '-', '*'] + for char in decoded + return false if char not in alphabet + true + + @decodeBoardValues: (copy, length, boardValues=[] ) -> + index = 0 + for i in [0...length] + row = [] + for j in [0...length] + row.push copy[index++] + boardValues.push row + boardValues + + @decodeGoals: (toCopy) -> toCopy[..] + + @decodeSolutionPlacements: (copy, length, solutionPlacements=[]) -> + for list in [0...copy.length] + expression = [] + for coord in [0...copy[list].length] + expression.push [(Math.floor copy[list][coord] / length), + (copy[list][coord] % length)] + solutionPlacements.push expression + solutionPlacements + + @checkSolutionPlacements: (board, solutionPlacements, SolutionService) -> + @initializeTempBoard board + @solutionService = new SolutionService @tempBoard, board.goals + + inputs = [] + for expression in solutionPlacements + clickedCells = [] + for index in [0...expression.length] + cell = expression[index] + clickedCells.push {row: cell[0], col: cell[1]} + @solutionService.initialize clickedCells + + solution = [] + for cell in clickedCells + solution.push @tempBoard.boardValues[cell.row][cell.col] + @tempBoard.boardValues[cell.row][cell.col] = ' ' + @pushDownTempBoard() + + return false unless @solutionService.isSolution() + inputs.push solution + + console.log expression for expression in inputs + console.log '\n' + true + + @initializeTempBoard: (board) -> + @tempBoard = {} + @tempBoard.boardValues = [] + for row, i in board.initialValues + @tempBoard.boardValues.push [] + for col in row + @tempBoard.boardValues[i].push col + + @pushDownTempBoard: -> + for row in [@tempBoard.boardValues.length-1..1] + for col in [@tempBoard.boardValues.length-1..0] + if @tempBoard.boardValues[row][col] is ' ' + for up in [row-1..0] + unless @tempBoard.boardValues[up][col] is ' ' + @swapCells row, col, up, col + break + + @swapCells: (r1, c1, r2, c2) -> + temp = @tempBoard.boardValues[r1][c1] + @tempBoard.boardValues[r1][c1] = @tempBoard.boardValues[r2][c2] + @tempBoard.boardValues[r2][c2] = temp + +module.exports = HashingService \ No newline at end of file diff --git a/app/services/ShareGameService.coffee b/app/services/ShareGameService.coffee index 1d75a60..6c61d59 100644 --- a/app/services/ShareGameService.coffee +++ b/app/services/ShareGameService.coffee @@ -2,123 +2,6 @@ $ = require 'jquery' class ShareGameService - @reloadPageWithHash: (board, solutionPlacements, SolutionService) -> - unless @checkSolutionPlacements board, solutionPlacements, SolutionService - window.location.hash = '' - return false - hash = @encode board.initialValues, board.goals, solutionPlacements - window.location.hash = hash - - @encode: (boardValues, goals, solutionPlacements) -> - boardValues = (JSON.stringify boardValues).replace(/(\[|\]|"|,|{|})*/g, '') - - length = Math.sqrt boardValues.length - for list in [0...solutionPlacements.length] - for pos in [0...solutionPlacements[list].length] - solutionPlacements[list][pos] = solutionPlacements[list][pos][0] * length + - solutionPlacements[list][pos][1] - - btoa(JSON.stringify {b: boardValues, g: goals, p: solutionPlacements}) - - @decodeMap: () -> - try - decoded_s = atob window.location.hash.substr(1, window.location.hash.length) - decoded = JSON.parse decoded_s - catch e - decoded = null - return decoded - - @parse: (decoded) -> - return [[],[],[]] unless @successfulDecode decoded - length = Math.sqrt decoded.b.length - b = @decodeBoardValues decoded.b, length - g = @decodeGoals decoded.g - p = @decodeSolutionPlacements decoded.p, length - [b, g, p] - - @successfulDecode: (decoded)-> - return decoded? and - decoded.p? and - decoded.g? and - decoded.p? and - @regexPass decoded - - @regexPass: (decoded) -> - alphabet = ['"', '{', '}', '[', ']', ',', ':', - 'b', 'g', 'p', '1', '2', '3', '4', - '5', '6', '7', '8', '9', '0', - '+', '-', '*'] - for char in decoded - return false if alphabet.indexOf(char) is -1 - true - - @decodeBoardValues: (copy, length, boardValues=[] ) -> - index = 0 - for i in [0...length] - row = [] - for j in [0...length] - row.push copy[index++] - boardValues.push row - boardValues - - @decodeGoals: (toCopy) -> toCopy[..] - - @decodeSolutionPlacements: (copy, length, solutionPlacements=[]) -> - for list in [0...copy.length] - expression = [] - for coord in [0...copy[list].length] - expression.push [(Math.floor copy[list][coord] / length), - (copy[list][coord] % length)] - solutionPlacements.push expression - solutionPlacements - - @checkSolutionPlacements: (board, solutionPlacements, SolutionService) -> - @initializeTempBoard board - @solutionService = new SolutionService @tempBoard, board.goals - - inputs = [] - for expression in solutionPlacements - clickedCells = [] - for index in [0...expression.length] - cell = expression[index] - clickedCells.push {row: cell[0], col: cell[1]} - @solutionService.initialize clickedCells - - solution = [] - for cell in clickedCells - solution.push @tempBoard.boardValues[cell.row][cell.col] - @tempBoard.boardValues[cell.row][cell.col] = ' ' - @pushDownTempBoard() - - return false unless @solutionService.isSolution() - inputs.push solution - - console.log expression for expression in inputs - console.log '\n' - true - - @initializeTempBoard: (board) -> - @tempBoard = {} - @tempBoard.boardValues = [] - for row, i in board.initialValues - @tempBoard.boardValues.push [] - for col in row - @tempBoard.boardValues[i].push col - - @pushDownTempBoard: -> - for row in [@tempBoard.boardValues.length-1..1] - for col in [@tempBoard.boardValues.length-1..0] - if @tempBoard.boardValues[row][col] is ' ' - for up in [row-1..0] - unless @tempBoard.boardValues[up][col] is ' ' - @swapCells row, col, up, col - break - - @swapCells: (r1, c1, r2, c2) -> - temp = @tempBoard.boardValues[r1][c1] - @tempBoard.boardValues[r1][c1] = @tempBoard.boardValues[r2][c2] - @tempBoard.boardValues[r2][c2] = temp - @setMessage: -> possible = ['Play MathSwipe with me! Try to beat my score at', 'Play MathSwipe with me! Try to solve my board at', From 251c0b865d7beb11dc7606624ddecf487b16b66c Mon Sep 17 00:00:00 2001 From: Eric Campbell <1234goal@gmail.com> Date: Thu, 5 Nov 2015 23:31:43 -0800 Subject: [PATCH 5/5] build --- bundle.js | 542 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 284 insertions(+), 258 deletions(-) diff --git a/bundle.js b/bundle.js index 50edeeb..1591352 100644 --- a/bundle.js +++ b/bundle.js @@ -65,7 +65,7 @@ Tuple = __webpack_require__(/*! ./app/models/Tuple */ 5); - Two = __webpack_require__(/*! two.js */ 25); + Two = __webpack_require__(/*! two.js */ 26); game = new MathSwipeController; @@ -9296,7 +9296,7 @@ \****************************************************/ /***/ function(module, exports, __webpack_require__) { - var $, AdjacentCellsCalculator, Board, BoardSolvedService, Cell, ClickHandler, Colors, DFS, ExpressionGenerator, GeneralTests, GoalContainer, HowToPlay, InputSolver, MathSwipeController, RandomizedFitLength, ResetButton, RunningSum, ShareGameService, SolutionService, Title, TrackingService; + var $, AdjacentCellsCalculator, Board, BoardSolvedService, Cell, ClickHandler, Colors, DFS, ExpressionGenerator, GeneralTests, GoalContainer, HashingService, HowToPlay, InputSolver, MathSwipeController, RandomizedFitLength, ResetButton, RunningSum, ShareGameService, SolutionService, Title, TrackingService; $ = __webpack_require__(/*! jquery */ 2); @@ -9310,33 +9310,35 @@ ExpressionGenerator = __webpack_require__(/*! ../services/ExpressionGenerator */ 11); - HowToPlay = __webpack_require__(/*! ../services/HowToPlay */ 12); + HashingService = __webpack_require__(/*! ../services/HashingService */ 12); - InputSolver = __webpack_require__(/*! ../services/InputSolver */ 13); + HowToPlay = __webpack_require__(/*! ../services/HowToPlay */ 13); - RandomizedFitLength = __webpack_require__(/*! ../services/RandomizedFitLength */ 14); + InputSolver = __webpack_require__(/*! ../services/InputSolver */ 14); - ResetButton = __webpack_require__(/*! ../services/ResetButton */ 15); + RandomizedFitLength = __webpack_require__(/*! ../services/RandomizedFitLength */ 15); - RunningSum = __webpack_require__(/*! ../services/RunningSum */ 16); + ResetButton = __webpack_require__(/*! ../services/ResetButton */ 16); - ShareGameService = __webpack_require__(/*! ../services/ShareGameService */ 17); + RunningSum = __webpack_require__(/*! ../services/RunningSum */ 17); - SolutionService = __webpack_require__(/*! ../services/SolutionService */ 18); + ShareGameService = __webpack_require__(/*! ../services/ShareGameService */ 18); - Title = __webpack_require__(/*! ../services/Title */ 19); + SolutionService = __webpack_require__(/*! ../services/SolutionService */ 19); + + Title = __webpack_require__(/*! ../services/Title */ 20); TrackingService = __webpack_require__(/*! ../services/TrackingService */ 8); - Board = __webpack_require__(/*! ../views/Board */ 20); + Board = __webpack_require__(/*! ../views/Board */ 21); - Cell = __webpack_require__(/*! ../views/Cell */ 21); + Cell = __webpack_require__(/*! ../views/Cell */ 22); - Colors = __webpack_require__(/*! ../views/Colors */ 22); + Colors = __webpack_require__(/*! ../views/Colors */ 23); - GoalContainer = __webpack_require__(/*! ../views/GoalContainer */ 23); + GoalContainer = __webpack_require__(/*! ../views/GoalContainer */ 24); - GeneralTests = __webpack_require__(/*! ../../tests/controllers/GeneralTests */ 24); + GeneralTests = __webpack_require__(/*! ../../tests/controllers/GeneralTests */ 25); MathSwipeController = (function() { function MathSwipeController() { @@ -9360,13 +9362,15 @@ if (length == null) { length = 3; } - solutionPlacements = goals = boardValues = inputs = inputLengths = []; - decoded = ShareGameService.decodeMap(); - console.log(decoded); - ref = ShareGameService.parse(decoded), boardValues = ref[0], goals = ref[1], solutionPlacements = ref[2]; - if (boardValues.length < 1) { - console.log("Unsuccessful decode!"); - inputLengths = RandomizedFitLength.generate(length * length); + solutionPlacements = []; + inputLengths = []; + boardValues = []; + inputs = []; + goals = []; + decoded = HashingService.decodeMap(); + ref = HashingService.parse(decoded), boardValues = ref[0], goals = ref[1], solutionPlacements = ref[2]; + if (this.malformedDecode(boardValues, goals, solutionPlacements)) { + inputLengths = RandomizedFitLength.generate(Math.pow(length, 2)); ref1 = this.generateInputs(inputLengths), inputs = ref1[0], goals = ref1[1]; boardValues = this.generateBoard(inputs, length, solutionPlacements); } @@ -9374,7 +9378,7 @@ this.board = new Board(boardValues, this.gameScene, goals, this.symbols, this.goalContainer, this.isMobile().any() != null, Cell, Colors, ClickHandler, SolutionService, BoardSolvedService, RunningSum); ResetButton.bindClick(this.board, RunningSum); RunningSum.empty(); - if (!ShareGameService.reloadPageWithHash(this.board, solutionPlacements, SolutionService)) { + if (!HashingService.reloadPageWithHash(this.board, solutionPlacements, SolutionService)) { return this.createNewGame(); } }; @@ -9479,6 +9483,10 @@ return [inputs, goals]; }; + MathSwipeController.prototype.malformedDecode = function(boardValues, goals, solutionPlacements) { + return boardValues.length < 1 || goals.length < 1 || solutionPlacements.length < 1; + }; + MathSwipeController.prototype.randExpression = function(length) { return ExpressionGenerator.generate(length); }; @@ -10123,6 +10131,230 @@ /***/ }, /* 12 */ +/*!********************************************!*\ + !*** ./app/services/HashingService.coffee ***! + \********************************************/ +/***/ function(module, exports) { + + var HashingService, + indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; + + HashingService = (function() { + function HashingService() {} + + HashingService.reloadPageWithHash = function(board, solutionPlacements, SolutionService) { + if (!this.checkSolutionPlacements(board, solutionPlacements, SolutionService)) { + this.emptyHash(); + return false; + } + return HashingService.setHash(board.initialValues, board.goals, solutionPlacements); + }; + + HashingService.emptyHash = function() { + return window.location.hash = ''; + }; + + HashingService.setHash = function(boardValues, goals, solutionPlacements) { + return window.location.hash = this.encode(boardValues, goals, solutionPlacements); + }; + + HashingService.encode = function(boardValues, goals, solutionPlacements) { + var k, l, length, list, pos, ref, ref1; + boardValues = (JSON.stringify(boardValues)).replace(/(\[|\]|"|,|{|})*/g, ''); + length = Math.sqrt(boardValues.length); + for (list = k = 0, ref = solutionPlacements.length; 0 <= ref ? k < ref : k > ref; list = 0 <= ref ? ++k : --k) { + for (pos = l = 0, ref1 = solutionPlacements[list].length; 0 <= ref1 ? l < ref1 : l > ref1; pos = 0 <= ref1 ? ++l : --l) { + solutionPlacements[list][pos] = solutionPlacements[list][pos][0] * length + solutionPlacements[list][pos][1]; + } + } + return btoa(JSON.stringify({ + b: boardValues, + g: goals, + p: solutionPlacements + })); + }; + + HashingService.decodeMap = function() { + var decoded, decoded_s, e; + try { + decoded_s = atob(window.location.hash.substr(1, window.location.hash.length)); + decoded = JSON.parse(decoded_s); + } catch (_error) { + e = _error; + decoded = null; + } + return decoded; + }; + + HashingService.parse = function(decoded) { + var b, g, length, p; + if (!this.successfulDecode(decoded)) { + return [[], [], []]; + } + length = Math.sqrt(decoded.b.length); + b = this.decodeBoardValues(decoded.b, length); + g = this.decodeGoals(decoded.g); + p = this.decodeSolutionPlacements(decoded.p, length); + return [b, g, p]; + }; + + HashingService.successfulDecode = function(decoded) { + return (decoded != null) && (decoded.p != null) && (decoded.g != null) && (decoded.p != null) && this.regexPass(decoded); + }; + + HashingService.regexPass = function(decoded) { + var alphabet, char, k, len; + alphabet = ['"', '{', '}', '[', ']', ',', ':', 'b', 'g', 'p', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '+', '-', '*']; + for (k = 0, len = decoded.length; k < len; k++) { + char = decoded[k]; + if (indexOf.call(alphabet, char) < 0) { + return false; + } + } + return true; + }; + + HashingService.decodeBoardValues = function(copy, length, boardValues) { + var i, index, j, k, l, ref, ref1, row; + if (boardValues == null) { + boardValues = []; + } + index = 0; + for (i = k = 0, ref = length; 0 <= ref ? k < ref : k > ref; i = 0 <= ref ? ++k : --k) { + row = []; + for (j = l = 0, ref1 = length; 0 <= ref1 ? l < ref1 : l > ref1; j = 0 <= ref1 ? ++l : --l) { + row.push(copy[index++]); + } + boardValues.push(row); + } + return boardValues; + }; + + HashingService.decodeGoals = function(toCopy) { + return toCopy.slice(0); + }; + + HashingService.decodeSolutionPlacements = function(copy, length, solutionPlacements) { + var coord, expression, k, l, list, ref, ref1; + if (solutionPlacements == null) { + solutionPlacements = []; + } + for (list = k = 0, ref = copy.length; 0 <= ref ? k < ref : k > ref; list = 0 <= ref ? ++k : --k) { + expression = []; + for (coord = l = 0, ref1 = copy[list].length; 0 <= ref1 ? l < ref1 : l > ref1; coord = 0 <= ref1 ? ++l : --l) { + expression.push([Math.floor(copy[list][coord] / length), copy[list][coord] % length]); + } + solutionPlacements.push(expression); + } + return solutionPlacements; + }; + + HashingService.checkSolutionPlacements = function(board, solutionPlacements, SolutionService) { + var cell, clickedCells, expression, index, inputs, k, l, len, len1, len2, m, n, ref, solution; + this.initializeTempBoard(board); + this.solutionService = new SolutionService(this.tempBoard, board.goals); + inputs = []; + for (k = 0, len = solutionPlacements.length; k < len; k++) { + expression = solutionPlacements[k]; + clickedCells = []; + for (index = l = 0, ref = expression.length; 0 <= ref ? l < ref : l > ref; index = 0 <= ref ? ++l : --l) { + cell = expression[index]; + clickedCells.push({ + row: cell[0], + col: cell[1] + }); + } + this.solutionService.initialize(clickedCells); + solution = []; + for (m = 0, len1 = clickedCells.length; m < len1; m++) { + cell = clickedCells[m]; + solution.push(this.tempBoard.boardValues[cell.row][cell.col]); + this.tempBoard.boardValues[cell.row][cell.col] = ' '; + } + this.pushDownTempBoard(); + if (!this.solutionService.isSolution()) { + return false; + } + inputs.push(solution); + } + for (n = 0, len2 = inputs.length; n < len2; n++) { + expression = inputs[n]; + console.log(expression); + } + console.log('\n'); + return true; + }; + + HashingService.initializeTempBoard = function(board) { + var col, i, k, len, ref, results, row; + this.tempBoard = {}; + this.tempBoard.boardValues = []; + ref = board.initialValues; + results = []; + for (i = k = 0, len = ref.length; k < len; i = ++k) { + row = ref[i]; + this.tempBoard.boardValues.push([]); + results.push((function() { + var l, len1, results1; + results1 = []; + for (l = 0, len1 = row.length; l < len1; l++) { + col = row[l]; + results1.push(this.tempBoard.boardValues[i].push(col)); + } + return results1; + }).call(this)); + } + return results; + }; + + HashingService.pushDownTempBoard = function() { + var col, k, ref, results, row, up; + results = []; + for (row = k = ref = this.tempBoard.boardValues.length - 1; ref <= 1 ? k <= 1 : k >= 1; row = ref <= 1 ? ++k : --k) { + results.push((function() { + var l, ref1, results1; + results1 = []; + for (col = l = ref1 = this.tempBoard.boardValues.length - 1; ref1 <= 0 ? l <= 0 : l >= 0; col = ref1 <= 0 ? ++l : --l) { + if (this.tempBoard.boardValues[row][col] === ' ') { + results1.push((function() { + var m, ref2, results2; + results2 = []; + for (up = m = ref2 = row - 1; ref2 <= 0 ? m <= 0 : m >= 0; up = ref2 <= 0 ? ++m : --m) { + if (this.tempBoard.boardValues[up][col] !== ' ') { + this.swapCells(row, col, up, col); + break; + } else { + results2.push(void 0); + } + } + return results2; + }).call(this)); + } else { + results1.push(void 0); + } + } + return results1; + }).call(this)); + } + return results; + }; + + HashingService.swapCells = function(r1, c1, r2, c2) { + var temp; + temp = this.tempBoard.boardValues[r1][c1]; + this.tempBoard.boardValues[r1][c1] = this.tempBoard.boardValues[r2][c2]; + return this.tempBoard.boardValues[r2][c2] = temp; + }; + + return HashingService; + + })(); + + module.exports = HashingService; + + +/***/ }, +/* 13 */ /*!***************************************!*\ !*** ./app/services/HowToPlay.coffee ***! \***************************************/ @@ -10158,7 +10390,7 @@ /***/ }, -/* 13 */ +/* 14 */ /*!*****************************************!*\ !*** ./app/services/InputSolver.coffee ***! \*****************************************/ @@ -10222,7 +10454,7 @@ /***/ }, -/* 14 */ +/* 15 */ /*!*************************************************!*\ !*** ./app/services/RandomizedFitLength.coffee ***! \*************************************************/ @@ -10262,7 +10494,7 @@ /***/ }, -/* 15 */ +/* 16 */ /*!*****************************************!*\ !*** ./app/services/ResetButton.coffee ***! \*****************************************/ @@ -10296,7 +10528,7 @@ /***/ }, -/* 16 */ +/* 17 */ /*!****************************************!*\ !*** ./app/services/RunningSum.coffee ***! \****************************************/ @@ -10380,7 +10612,7 @@ /***/ }, -/* 17 */ +/* 18 */ /*!**********************************************!*\ !*** ./app/services/ShareGameService.coffee ***! \**********************************************/ @@ -10393,207 +10625,6 @@ ShareGameService = (function() { function ShareGameService() {} - ShareGameService.reloadPageWithHash = function(board, solutionPlacements, SolutionService) { - var hash; - if (!this.checkSolutionPlacements(board, solutionPlacements, SolutionService)) { - console.log("bad solution placements, resetting hash"); - window.location.hash = ''; - return false; - } - hash = this.encode(board.initialValues, board.goals, solutionPlacements); - return window.location.hash = hash; - }; - - ShareGameService.encode = function(boardValues, goals, solutionPlacements) { - var k, l, length, list, pos, ref, ref1; - boardValues = (JSON.stringify(boardValues)).replace(/(\[|\]|"|,|{|})*/g, ''); - length = Math.sqrt(boardValues.length); - for (list = k = 0, ref = solutionPlacements.length; 0 <= ref ? k < ref : k > ref; list = 0 <= ref ? ++k : --k) { - for (pos = l = 0, ref1 = solutionPlacements[list].length; 0 <= ref1 ? l < ref1 : l > ref1; pos = 0 <= ref1 ? ++l : --l) { - solutionPlacements[list][pos] = solutionPlacements[list][pos][0] * length + solutionPlacements[list][pos][1]; - } - } - return btoa(JSON.stringify({ - b: boardValues, - g: goals, - p: solutionPlacements - })); - }; - - ShareGameService.decodeMap = function() { - var decoded, decoded_s, e; - try { - decoded_s = atob(window.location.hash.substr(1, window.location.hash.length)); - decoded = JSON.parse(decoded_s); - } catch (_error) { - e = _error; - decoded = null; - } - return decoded; - }; - - ShareGameService.parse = function(decoded) { - var b, g, length, p; - if (!this.successfulDecode(decoded)) { - return [[], [], []]; - } - console.log("Successful decode!"); - length = Math.sqrt(decoded.b.length); - b = this.decodeBoardValues(decoded.b, length); - g = this.decodeGoals(decoded.g); - p = this.decodeSolutionPlacements(decoded.p, length); - return [b, g, p]; - }; - - ShareGameService.successfulDecode = function(decoded) { - return (decoded != null) && (decoded.p != null) && (decoded.g != null) && (decoded.p != null) && this.regexPass(decoded); - }; - - ShareGameService.regexPass = function(decoded) { - var alphabet, char, k, len; - alphabet = ['"', '{', '}', '[', ']', ',', ':', 'b', 'g', 'p', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '+', '-', '*']; - for (k = 0, len = decoded.length; k < len; k++) { - char = decoded[k]; - if (alphabet.indexOf(char) === -1) { - return false; - } - } - return true; - }; - - ShareGameService.decodeBoardValues = function(copy, length, boardValues) { - var i, index, j, k, l, ref, ref1, row; - if (boardValues == null) { - boardValues = []; - } - index = 0; - for (i = k = 0, ref = length; 0 <= ref ? k < ref : k > ref; i = 0 <= ref ? ++k : --k) { - row = []; - for (j = l = 0, ref1 = length; 0 <= ref1 ? l < ref1 : l > ref1; j = 0 <= ref1 ? ++l : --l) { - row.push(copy[index++]); - } - boardValues.push(row); - } - return boardValues; - }; - - ShareGameService.decodeGoals = function(toCopy) { - console.log("goals", toCopy); - return toCopy.slice(0); - }; - - ShareGameService.decodeSolutionPlacements = function(copy, length, solutionPlacements) { - var coord, expression, k, l, list, ref, ref1; - if (solutionPlacements == null) { - solutionPlacements = []; - } - for (list = k = 0, ref = copy.length; 0 <= ref ? k < ref : k > ref; list = 0 <= ref ? ++k : --k) { - expression = []; - for (coord = l = 0, ref1 = copy[list].length; 0 <= ref1 ? l < ref1 : l > ref1; coord = 0 <= ref1 ? ++l : --l) { - expression.push([Math.floor(copy[list][coord] / length), copy[list][coord] % length]); - } - solutionPlacements.push(expression); - } - return solutionPlacements; - }; - - ShareGameService.checkSolutionPlacements = function(board, solutionPlacements, SolutionService) { - var cell, clickedCells, expression, index, inputs, k, l, len, len1, len2, m, n, ref, solution; - this.initializeTempBoard(board); - this.solutionService = new SolutionService(this.tempBoard, board.goals); - inputs = []; - for (k = 0, len = solutionPlacements.length; k < len; k++) { - expression = solutionPlacements[k]; - clickedCells = []; - for (index = l = 0, ref = expression.length; 0 <= ref ? l < ref : l > ref; index = 0 <= ref ? ++l : --l) { - cell = expression[index]; - clickedCells.push({ - row: cell[0], - col: cell[1] - }); - } - this.solutionService.initialize(clickedCells); - solution = []; - for (m = 0, len1 = clickedCells.length; m < len1; m++) { - cell = clickedCells[m]; - solution.push(this.tempBoard.boardValues[cell.row][cell.col]); - this.tempBoard.boardValues[cell.row][cell.col] = ' '; - } - this.pushDownTempBoard(); - if (!this.solutionService.isSolution()) { - return false; - } - inputs.push(solution); - } - for (n = 0, len2 = inputs.length; n < len2; n++) { - expression = inputs[n]; - console.log(expression); - } - console.log('\n'); - return true; - }; - - ShareGameService.initializeTempBoard = function(board) { - var col, i, k, len, ref, results, row; - this.tempBoard = {}; - this.tempBoard.boardValues = []; - ref = board.initialValues; - results = []; - for (i = k = 0, len = ref.length; k < len; i = ++k) { - row = ref[i]; - this.tempBoard.boardValues.push([]); - results.push((function() { - var l, len1, results1; - results1 = []; - for (l = 0, len1 = row.length; l < len1; l++) { - col = row[l]; - results1.push(this.tempBoard.boardValues[i].push(col)); - } - return results1; - }).call(this)); - } - return results; - }; - - ShareGameService.pushDownTempBoard = function() { - var col, k, ref, results, row, up; - results = []; - for (row = k = ref = this.tempBoard.boardValues.length - 1; ref <= 1 ? k <= 1 : k >= 1; row = ref <= 1 ? ++k : --k) { - results.push((function() { - var l, ref1, results1; - results1 = []; - for (col = l = ref1 = this.tempBoard.boardValues.length - 1; ref1 <= 0 ? l <= 0 : l >= 0; col = ref1 <= 0 ? ++l : --l) { - if (this.tempBoard.boardValues[row][col] === ' ') { - results1.push((function() { - var m, ref2, results2; - results2 = []; - for (up = m = ref2 = row - 1; ref2 <= 0 ? m <= 0 : m >= 0; up = ref2 <= 0 ? ++m : --m) { - if (this.tempBoard.boardValues[up][col] !== ' ') { - this.swapCells(row, col, up, col); - break; - } else { - results2.push(void 0); - } - } - return results2; - }).call(this)); - } else { - results1.push(void 0); - } - } - return results1; - }).call(this)); - } - return results; - }; - - ShareGameService.swapCells = function(r1, c1, r2, c2) { - var temp; - temp = this.tempBoard.boardValues[r1][c1]; - this.tempBoard.boardValues[r1][c1] = this.tempBoard.boardValues[r2][c2]; - return this.tempBoard.boardValues[r2][c2] = temp; - }; - ShareGameService.setMessage = function() { var possible, text; possible = ['Play MathSwipe with me! Try to beat my score at', 'Play MathSwipe with me! Try to solve my board at', 'Play MathSwipe with me! Solve my puzzle at']; @@ -10611,7 +10642,7 @@ /***/ }, -/* 18 */ +/* 19 */ /*!*********************************************!*\ !*** ./app/services/SolutionService.coffee ***! \*********************************************/ @@ -10620,18 +10651,13 @@ var InputSolver, SolutionService, indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; - InputSolver = __webpack_require__(/*! ./InputSolver */ 13); + InputSolver = __webpack_require__(/*! ./InputSolver */ 14); SolutionService = (function() { function SolutionService(board, goals, RunningSum) { - var g, i, len; this.board = board; this.RunningSum = RunningSum; - this.goals = []; - for (i = 0, len = goals.length; i < len; i++) { - g = goals[i]; - this.goals.push(g); - } + this.goals = goals.slice(0); } SolutionService.prototype.initialize = function(clickedCells) { @@ -10641,22 +10667,22 @@ SolutionService.prototype.isSolution = function() { var ref; - if (this.solution == null) { - return false; - } - if (this.solution[this.solution.length - 1] === '+' || this.solution[this.solution.length - 1] === '-' || this.solution[this.solution.length - 1] === '*') { - return false; - } - if (ref = this.value, indexOf.call(this.goals, ref) < 0) { + if (!((this.solution != null) && this.finished && (ref = this.value, indexOf.call(this.goals, ref) >= 0))) { return false; } - if (!this.isCompleteExpression()) { + if (this.isCompleteExpression()) { + this.valueIndex = this.goals.indexOf(this.value); + this.goals[this.valueIndex] = ' '; + return true; + } else { this.RunningSum.display(this.RunningSum.solutionOperatorString); return false; } - this.valueIndex = this.goals.indexOf(this.value); - this.goals[this.valueIndex] = ' '; - return true; + }; + + SolutionService.prototype.finished = function() { + var ref; + return ref = this.solution[this.solution.length - 1], indexOf.call("+-*", ref) < 0; }; SolutionService.prototype.isCompleteExpression = function() { @@ -10682,7 +10708,7 @@ /***/ }, -/* 19 */ +/* 20 */ /*!***********************************!*\ !*** ./app/services/Title.coffee ***! \***********************************/ @@ -10709,7 +10735,7 @@ /***/ }, -/* 20 */ +/* 21 */ /*!********************************!*\ !*** ./app/views/Board.coffee ***! \********************************/ @@ -10928,7 +10954,7 @@ /***/ }, -/* 21 */ +/* 22 */ /*!*******************************!*\ !*** ./app/views/Cell.coffee ***! \*******************************/ @@ -10938,7 +10964,7 @@ $ = __webpack_require__(/*! jquery */ 2); - Colors = __webpack_require__(/*! ./Colors */ 22); + Colors = __webpack_require__(/*! ./Colors */ 23); Cell = (function() { function Cell(col1, row1, size, scene, board, clickHandler, symbolBlueprint) { @@ -11136,7 +11162,7 @@ /***/ }, -/* 22 */ +/* 23 */ /*!*********************************!*\ !*** ./app/views/Colors.coffee ***! \*********************************/ @@ -11159,7 +11185,7 @@ /***/ }, -/* 23 */ +/* 24 */ /*!****************************************!*\ !*** ./app/views/GoalContainer.coffee ***! \****************************************/ @@ -11214,7 +11240,7 @@ /***/ }, -/* 24 */ +/* 25 */ /*!***********************************************!*\ !*** ./tests/controllers/GeneralTests.coffee ***! \***********************************************/ @@ -11228,9 +11254,9 @@ ExpressionGenerator = __webpack_require__(/*! ../../app/services/ExpressionGenerator */ 11); - InputSolver = __webpack_require__(/*! ../../app/services/InputSolver */ 13); + InputSolver = __webpack_require__(/*! ../../app/services/InputSolver */ 14); - RandomizedFitLength = __webpack_require__(/*! ../../app/services/RandomizedFitLength */ 14); + RandomizedFitLength = __webpack_require__(/*! ../../app/services/RandomizedFitLength */ 15); Tuple = __webpack_require__(/*! ../../app/models/Tuple */ 5); @@ -11313,7 +11339,7 @@ /***/ }, -/* 25 */ +/* 26 */ /*!*******************************!*\ !*** ./~/two.js/build/two.js ***! \*******************************/