From 00641f16c889093b32b8e97a6050817f6fe43780 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Fri, 3 Nov 2023 00:18:41 -0400 Subject: added weird symmetries (and some more puzzles) --- app/assets/javascripts/wittle/display2.js | 19 +++- app/assets/javascripts/wittle/puzzle.js | 74 ++++++++++----- app/assets/javascripts/wittle/serializer.js | 22 ++++- app/assets/javascripts/wittle/solve.js | 12 +-- app/assets/javascripts/wittle/trace2.js | 134 ++++++++++++++++++---------- app/assets/javascripts/wittle/validate.js | 4 +- 6 files changed, 181 insertions(+), 84 deletions(-) (limited to 'app/assets/javascripts') diff --git a/app/assets/javascripts/wittle/display2.js b/app/assets/javascripts/wittle/display2.js index 52069d6..ddf3968 100644 --- a/app/assets/javascripts/wittle/display2.js +++ b/app/assets/javascripts/wittle/display2.js @@ -1,3 +1,20 @@ +var SYM_TYPE_NONE = 0 +var SYM_TYPE_HORIZONTAL = 1 +var SYM_TYPE_VERTICAL = 2 +var SYM_TYPE_ROTATIONAL = 3 +var SYM_TYPE_ROTATE_LEFT = 4 +var SYM_TYPE_ROTATE_RIGHT = 5 +var SYM_TYPE_FLIP_XY = 6 +var SYM_TYPE_FLIP_NEG_XY = 7 +var SYM_TYPE_PARALLEL_H = 8 +var SYM_TYPE_PARALLEL_V = 9 +var SYM_TYPE_PARALLEL_H_FLIP = 10 +var SYM_TYPE_PARALLEL_V_FLIP = 11 +var SYM_TYPE_PILLAR_PARALLEL = 12 +var SYM_TYPE_PILLAR_HORIZONTAL = 13 +var SYM_TYPE_PILLAR_VERTICAL = 14 +var SYM_TYPE_PILLAR_ROTATIONAL = 15 + namespace(function() { window.draw = function(puzzle, target='puzzle') { @@ -260,7 +277,7 @@ function drawStartAndEnd(puzzle, svg) { if (cell.start === true) { var symStart = null - if (puzzle.symmetry != null) { + if (puzzle.symType != SYM_TYPE_NONE) { var sym = puzzle.getSymmetricalPos(x, y) window.drawSymbolWithSvg(svg, { 'type': 'start', diff --git a/app/assets/javascripts/wittle/puzzle.js b/app/assets/javascripts/wittle/puzzle.js index 4d6b0fb..cb0b20a 100644 --- a/app/assets/javascripts/wittle/puzzle.js +++ b/app/assets/javascripts/wittle/puzzle.js @@ -123,6 +123,7 @@ window.Puzzle = class { } puzzle.pillar = parsed.pillar puzzle.symmetry = parsed.symmetry + puzzle.symType = parsed.symType puzzle.largezero = puzzle.width * puzzle.height return puzzle } @@ -185,36 +186,63 @@ window.Puzzle = class { } getSymmetricalDir(dir) { - if (this.symmetry != null) { - if (this.symmetry.x === true) { - if (dir === 'left') return 'right' - if (dir === 'right') return 'left' - } - if (this.symmetry.y === true) { - if (dir === 'top') return 'bottom' - if (dir === 'bottom') return 'top' - } + if (this.symType == SYM_TYPE_VERTICAL || this.symType == SYM_TYPE_ROTATIONAL || this.symType == SYM_TYPE_PARALLEL_H_FLIP) { + if (dir === 'left') return 'right' + if (dir === 'right') return 'left' + } + if (this.symType == SYM_TYPE_HORIZONTAL || this.symType == SYM_TYPE_ROTATIONAL || this.symType == SYM_TYPE_PARALLEL_V_FLIP) { + if (dir === 'top') return 'bottom' + if (dir === 'bottom') return 'top' + } + if (this.symType == SYM_TYPE_ROTATE_LEFT || this.symType == SYM_TYPE_FLIP_NEG_XY) { + if (dir === 'left') return 'bottom' + if (dir === 'right') return 'top' + } + if (this.symType == SYM_TYPE_ROTATE_RIGHT || this.symType == SYM_TYPE_FLIP_NEG_XY) { + if (dir === 'top') return 'right' + if (dir === 'bottom') return 'left' + } + if (this.symType == SYM_TYPE_ROTATE_LEFT || this.symType == SYM_TYPE_FLIP_XY) { + if (dir === 'top') return 'left' + if (dir === 'bottom') return 'right' + } + if (this.symType == SYM_TYPE_ROTATE_RIGHT || this.symType == SYM_TYPE_FLIP_XY) { + if (dir === 'right') return 'bottom' + if (dir === 'left') return 'top' } return dir } // The resulting position is guaranteed to be gridsafe. getSymmetricalPos(x, y) { - if (this.symmetry != null) { - if (this.pillar === true) { - x += this.width/2 - if (this.symmetry.x === true) { - x = this.width - x - } - } else { - if (this.symmetry.x === true) { - x = (this.width - 1) - x - } - } - if (this.symmetry.y === true) { - y = (this.height - 1) - y - } + var origx = x + var origy = y + + if (this.symType == SYM_TYPE_VERTICAL || this.symType == SYM_TYPE_ROTATIONAL || this.symType == SYM_TYPE_PARALLEL_H_FLIP) { + x = (this.width - 1) - origx + } + if (this.symType == SYM_TYPE_HORIZONTAL || this.symType == SYM_TYPE_ROTATIONAL || this.symType == SYM_TYPE_PARALLEL_V_FLIP) { + y = (this.height - 1) - origy + } + if (this.symType == SYM_TYPE_ROTATE_LEFT || this.symType == SYM_TYPE_FLIP_XY) { + x = origy + } + if (this.symType == SYM_TYPE_ROTATE_RIGHT || this.symType == SYM_TYPE_FLIP_XY) { + y = origx } + if (this.symType == SYM_TYPE_ROTATE_LEFT || this.symType == SYM_TYPE_FLIP_NEG_XY) { + y = (this.width - 1) - origx + } + if (this.symType == SYM_TYPE_ROTATE_RIGHT || this.symType == SYM_TYPE_FLIP_NEG_XY) { + x = (this.height - 1) - origy + } + if (this.symType == SYM_TYPE_PARALLEL_H || this.symType == SYM_TYPE_PARALLEL_H_FLIP) { + y = (origy == this.height / 2) ? (this.height / 2) : ((origy + (this.height + 1) / 2) % (this.height + 1)) + } + if (this.symType == SYM_TYPE_PARALLEL_V || this.symType == SYM_TYPE_PARALLEL_V_FLIP) { + x = (origx == this.width / 2) ? (this.width / 2) : ((origx + (this.width + 1) / 2) % (this.width + 1)) + } + return {'x':this._mod(x), 'y':y} } diff --git a/app/assets/javascripts/wittle/serializer.js b/app/assets/javascripts/wittle/serializer.js index 1598d9b..70c7f0f 100644 --- a/app/assets/javascripts/wittle/serializer.js +++ b/app/assets/javascripts/wittle/serializer.js @@ -46,6 +46,8 @@ window.serializePuzzle = function(puzzle) { if (puzzle.settings.INVISIBLE_SYMMETRY) settingsFlags |= SETTINGS_FLAG_IS s.writeByte(settingsFlags) + s.writeByte(puzzle.symType) + return s.str() } @@ -64,10 +66,16 @@ window.deserializePuzzle = function(data) { var genericFlags = s.readByte() puzzle.autoSolved = genericFlags & GENERIC_FLAG_AUTOSOLVED + puzzle.symType = SYM_TYPE_NONE if ((genericFlags & GENERIC_FLAG_SYMMETRICAL) != 0) { - puzzle.symmetry = { - 'x': ((genericFlags & GENERIC_FLAG_SYMMETRY_X) != 0), - 'y': ((genericFlags & GENERIC_FLAG_SYMMETRY_Y) != 0), + if ((genericFlags & GENERIC_FLAG_SYMMETRY_X) != 0) { + if ((genericFlags & GENERIC_FLAG_SYMMETRY_Y) != 0) { + puzzle.symType = SYM_TYPE_ROTATIONAL + } else { + puzzle.symType = SYM_TYPE_VERTICAL + } + } else if ((genericFlags & GENERIC_FLAG_SYMMETRY_Y) != 0) { + puzzle.symType = SYM_TYPE_HORIZONTAL } } puzzle.pillar = (genericFlags & GENERIC_FLAG_PILLAR) != 0 @@ -97,6 +105,10 @@ window.deserializePuzzle = function(data) { INVISIBLE_SYMMETRY: (settingsFlags & SETTINGS_FLAG_IS) != 0, } + if (s.hasLeft(1)) { + puzzle.symType = s.readByte() + } + s.destroy() return puzzle } @@ -138,6 +150,10 @@ class Serializer { if (this.data.length < numBytes) throw Error('Cannot read ' + numBytes + ' bytes from a stream with only '+ this.data.length + ' bytes') } + hasLeft(numBytes = 1) { + return ((this.data.length - this.index) >= numBytes) + } + readByte() { this._checkRead() return this.data.charCodeAt(this.index++) diff --git a/app/assets/javascripts/wittle/solve.js b/app/assets/javascripts/wittle/solve.js index 13b9650..8695291 100644 --- a/app/assets/javascripts/wittle/solve.js +++ b/app/assets/javascripts/wittle/solve.js @@ -28,7 +28,7 @@ function countNodes(x, y, depth) { if (cell.gap > window.GAP_NONE) return if (cell.line !== window.LINE_NONE) return - if (puzzle.symmetry == null) { + if (puzzle.symType == SYM_TYPE_NONE) { puzzle.updateCell2(x, y, 'line', window.LINE_BLACK) } else { var sym = puzzle.getSymmetricalPos(x, y) @@ -84,7 +84,7 @@ window.solve = function(p, partialCallback, finalCallback) { // Puzzles which are small enough should be solved synchronously, since the cost of asynchronizing // is greater than the cost of the puzzle. SOLVE_SYNC = false - if (puzzle.symmetry != null) { // 5x5 is the max for symmetry puzzles + if (puzzle.symType != SYM_TYPE_NONE) { // 5x5 is the max for symmetry puzzles if (puzzle.width * puzzle.height <= 121) SOLVE_SYNC = true } else if (puzzle.pillar === true) { // 4x5 is the max for non-symmetry, pillar puzzles if (puzzle.width * puzzle.height <= 108) SOLVE_SYNC = true @@ -207,7 +207,7 @@ function taskLoop(partialCallback, finalCallback) { function tailRecurse(x, y) { // Tail recursion: Back out of this cell puzzle.updateCell2(x, y, 'line', window.LINE_NONE) - if (puzzle.symmetry != null) { + if (puzzle.symType != SYM_TYPE_NONE) { var sym = puzzle.getSymmetricalPos(x, y) puzzle.updateCell2(sym.x, sym.y, 'line', window.LINE_NONE) } @@ -227,7 +227,7 @@ function solveLoop(x, y, numEndpoints, earlyExitData) { if (cell.gap > window.GAP_NONE) return if (cell.line !== window.LINE_NONE) return - if (puzzle.symmetry == null) { + if (puzzle.symType == SYM_TYPE_NONE) { puzzle.updateCell2(x, y, 'line', window.LINE_BLACK) } else { var sym = puzzle.getSymmetricalPos(x, y) @@ -379,7 +379,7 @@ window.drawPathNoUI = function(puzzle, path) { x += dx y += dy // Set the cell color - if (puzzle.symmetry == null) { + if (puzzle.symType == SYM_TYPE_NONE) { cell.line = window.LINE_BLACK } else { cell.line = window.LINE_BLUE @@ -457,7 +457,7 @@ window.drawPath = function(puzzle, path, target='puzzle') { // Unflag the cell, move into it, and reflag it cell.line = window.LINE_NONE window.onMove(41 * dx, 41 * dy) - if (puzzle.symmetry == null) { + if (puzzle.symType == SYM_TYPE_NONE) { cell.line = window.LINE_BLACK } else { cell.line = window.LINE_BLUE diff --git a/app/assets/javascripts/wittle/trace2.js b/app/assets/javascripts/wittle/trace2.js index 7a77564..9602a41 100644 --- a/app/assets/javascripts/wittle/trace2.js +++ b/app/assets/javascripts/wittle/trace2.js @@ -15,7 +15,7 @@ class BoundingBox { data.svg.appendChild(this.debug) this.debug.setAttribute('opacity', 0.5) this.debug.setAttribute('style', 'pointer-events: none;') - if (data.puzzle.symmetry == null) { + if (data.puzzle.symType == SYM_TYPE_NONE) { this.debug.setAttribute('fill', 'white') } else { if (this.sym !== true) { @@ -120,7 +120,7 @@ class PathSegment { } } - if (data.puzzle.symmetry == null) { + if (data.puzzle.symType == SYM_TYPE_NONE) { this.poly1.setAttribute('class', 'line-1 ' + data.svg.id) this.circ.setAttribute('class', 'line-1 ' + data.svg.id) this.poly2.setAttribute('class', 'line-1 ' + data.svg.id) @@ -174,7 +174,7 @@ class PathSegment { if (this.dir === MOVE_NONE) { // Start point this.circ.setAttribute('r', 24) this.circ.setAttribute('class', this.circ.getAttribute('class') + ' start') - if (data.puzzle.symmetry != null) { + if (data.puzzle.symType != SYM_TYPE_NONE) { this.symCirc.setAttribute('r', 24) this.symCirc.setAttribute('class', this.symCirc.getAttribute('class') + ' start') } @@ -182,7 +182,7 @@ class PathSegment { // Only insert poly1 in non-startpoints data.svg.insertBefore(this.poly1, data.cursor) this.circ.setAttribute('r', 12) - if (data.puzzle.symmetry != null) { + if (data.puzzle.symType != SYM_TYPE_NONE) { data.svg.insertBefore(this.symPoly1, data.cursor) this.symCirc.setAttribute('r', 12) } @@ -194,7 +194,7 @@ class PathSegment { data.svg.removeChild(this.circ) data.svg.removeChild(this.poly2) data.svg.removeChild(this.pillarCirc) - if (data.puzzle.symmetry != null) { + if (data.puzzle.symType != SYM_TYPE_NONE) { data.svg.removeChild(this.symPoly1) data.svg.removeChild(this.symCirc) data.svg.removeChild(this.symPoly2) @@ -208,19 +208,19 @@ class PathSegment { var y = clamp(data.y, data.bbox.y1, data.bbox.y2) data.cursor.setAttribute('cx', x) data.cursor.setAttribute('cy', y) - if (data.puzzle.symmetry != null) { - data.symcursor.setAttribute('cx', this._reflX(x)) - data.symcursor.setAttribute('cy', this._reflY(y)) + if (data.puzzle.symType != SYM_TYPE_NONE) { + data.symcursor.setAttribute('cx', this._reflX(x,y)) + data.symcursor.setAttribute('cy', this._reflY(x,y)) } if (data.puzzle.pillar === true) { if (this.pillarCirc.getAttribute('static') == null) { this.pillarCirc.setAttribute('cx', x) this.pillarCirc.setAttribute('cy', y) } - if (data.puzzle.symmetry != null) { + if (data.puzzle.symType != SYM_TYPE_NONE) { if (this.symPillarCirc.getAttribute('static') == null) { - this.symPillarCirc.setAttribute('cx', this._reflX(x)) - this.symPillarCirc.setAttribute('cy', this._reflY(y)) + this.symPillarCirc.setAttribute('cx', this._reflX(x,y)) + this.symPillarCirc.setAttribute('cy', this._reflY(x,y)) } } } @@ -296,19 +296,19 @@ class PathSegment { } // Draw the symmetrical path based on the original one - if (data.puzzle.symmetry != null) { + if (data.puzzle.symType != SYM_TYPE_NONE) { this.symPoly1.setAttribute('points', - this._reflX(points1.x2) + ' ' + this._reflY(points1.y2) + ',' + - this._reflX(points1.x2) + ' ' + this._reflY(points1.y1) + ',' + - this._reflX(points1.x1) + ' ' + this._reflY(points1.y1) + ',' + - this._reflX(points1.x1) + ' ' + this._reflY(points1.y2) + this._reflX(points1.x2, points1.y2) + ' ' + this._reflY(points1.x2, points1.y2) + ',' + + this._reflX(points1.x2, points1.y2) + ' ' + this._reflY(points1.x1, points1.y1) + ',' + + this._reflX(points1.x1, points1.y1) + ' ' + this._reflY(points1.x1, points1.y1) + ',' + + this._reflX(points1.x1, points1.y1) + ' ' + this._reflY(points1.x2, points1.y2) ) this.symPoly2.setAttribute('points', - this._reflX(points2.x2) + ' ' + this._reflY(points2.y2) + ',' + - this._reflX(points2.x2) + ' ' + this._reflY(points2.y1) + ',' + - this._reflX(points2.x1) + ' ' + this._reflY(points2.y1) + ',' + - this._reflX(points2.x1) + ' ' + this._reflY(points2.y2) + this._reflX(points2.x2, points2.y2) + ' ' + this._reflY(points2.x2, points2.y2) + ',' + + this._reflX(points2.x2, points2.y2) + ' ' + this._reflY(points2.x1, points2.y1) + ',' + + this._reflX(points2.x1, points2.y1) + ' ' + this._reflY(points2.x1, points2.y1) + ',' + + this._reflX(points2.x1, points2.y1) + ' ' + this._reflY(points2.x2, points2.y2) ) this.symCirc.setAttribute('opacity', this.circ.getAttribute('opacity')) @@ -316,24 +316,46 @@ class PathSegment { } } - _reflX(x) { - if (data.puzzle.symmetry == null) return x - if (data.puzzle.symmetry.x === true) { + _reflX(x,y) { + if (data.puzzle.symType == SYM_TYPE_NONE) return x + + if (data.puzzle.symType == SYM_TYPE_VERTICAL || data.puzzle.symType == SYM_TYPE_ROTATIONAL || data.puzzle.symType == SYM_TYPE_PARALLEL_H_FLIP) { // Mirror position inside the bounding box return (data.bbox.middle.x - x) + data.symbbox.middle.x } - // Copy position inside the bounding box - return (x - data.bbox.middle.x) + data.symbbox.middle.x + if (data.puzzle.symType == SYM_TYPE_HORIZONTAL || data.puzzle.symType == SYM_TYPE_PARALLEL_H || data.puzzle.symType == SYM_TYPE_PARALLEL_V || data.puzzle.symType == SYM_TYPE_PARALLEL_V_FLIP) { + // Copy position inside the bounding box + return (x - data.bbox.middle.x) + data.symbbox.middle.x + } + if (data.puzzle.symType == SYM_TYPE_ROTATE_LEFT || data.puzzle.symType == SYM_TYPE_FLIP_XY) { + // Rotate position left inside the bounding box + return (y - data.bbox.middle.y) + data.symbbox.middle.x + } + if (data.puzzle.symType == SYM_TYPE_ROTATE_RIGHT || data.puzzle.symType == SYM_TYPE_FLIP_NEG_XY) { + // Rotate position right inside the bounding box + return (data.bbox.middle.y - y) + data.symbbox.middle.x + } } - _reflY(y) { - if (data.puzzle.symmetry == null) return y - if (data.puzzle.symmetry.y === true) { + _reflY(x,y) { + if (data.puzzle.symType == SYM_TYPE_NONE) return y + + if (data.puzzle.symType == SYM_TYPE_HORIZONTAL || data.puzzle.symType == SYM_TYPE_ROTATIONAL || data.puzzle.symType == SYM_TYPE_PARALLEL_V_FLIP) { // Mirror position inside the bounding box return (data.bbox.middle.y - y) + data.symbbox.middle.y } - // Copy position inside the bounding box - return (y - data.bbox.middle.y) + data.symbbox.middle.y + if (data.puzzle.symType == SYM_TYPE_VERTICAL || data.puzzle.symType == SYM_TYPE_PARALLEL_V || data.puzzle.symType == SYM_TYPE_PARALLEL_H || data.puzzle.symType == SYM_TYPE_PARALLEL_H_FLIP) { + // Copy position inside the bounding box + return (y - data.bbox.middle.y) + data.symbbox.middle.y + } + if (data.puzzle.symType == SYM_TYPE_ROTATE_RIGHT || data.puzzle.symType == SYM_TYPE_FLIP_XY) { + // Rotate position left inside the bounding box + return (x - data.bbox.middle.x) + data.symbbox.middle.y + } + if (data.puzzle.symType == SYM_TYPE_ROTATE_LEFT || data.puzzle.symType == SYM_TYPE_FLIP_NEG_XY) { + // Rotate position right inside the bounding box + return (data.bbox.middle.x - x) + data.symbbox.middle.y + } } } @@ -359,15 +381,29 @@ function clearGrid(svg, puzzle) { // This copy is an exact copy of puzzle.getSymmetricalDir, except that it uses MOVE_* values instead of strings function getSymmetricalDir(puzzle, dir) { - if (puzzle.symmetry != null) { - if (puzzle.symmetry.x === true) { - if (dir === MOVE_LEFT) return MOVE_RIGHT - if (dir === MOVE_RIGHT) return MOVE_LEFT - } - if (puzzle.symmetry.y === true) { - if (dir === MOVE_TOP) return MOVE_BOTTOM - if (dir === MOVE_BOTTOM) return MOVE_TOP - } + if (puzzle.symType == SYM_TYPE_VERTICAL || puzzle.symType == SYM_TYPE_ROTATIONAL || puzzle.symType == SYM_TYPE_PARALLEL_H_FLIP) { + if (dir === MOVE_LEFT) return MOVE_RIGHT + if (dir === MOVE_RIGHT) return MOVE_LEFT + } + if (puzzle.symType == SYM_TYPE_HORIZONTAL || puzzle.symType == SYM_TYPE_ROTATIONAL || puzzle.symType == SYM_TYPE_PARALLEL_V_FLIP) { + if (dir === MOVE_TOP) return MOVE_BOTTOM + if (dir === MOVE_BOTTOM) return MOVE_TOP + } + if (puzzle.symType == SYM_TYPE_ROTATE_LEFT || puzzle.symType == SYM_TYPE_FLIP_NEG_XY) { + if (dir === MOVE_LEFT) return MOVE_BOTTOM + if (dir === MOVE_RIGHT) return MOVE_TOP + } + if (puzzle.symType == SYM_TYPE_ROTATE_RIGHT || puzzle.symType == SYM_TYPE_FLIP_NEG_XY) { + if (dir === MOVE_TOP) return MOVE_RIGHT + if (dir === MOVE_BOTTOM) return MOVE_LEFT + } + if (puzzle.symType == SYM_TYPE_ROTATE_LEFT || puzzle.symType == SYM_TYPE_FLIP_XY) { + if (dir === MOVE_TOP) return MOVE_LEFT + if (dir === MOVE_BOTTOM) return MOVE_RIGHT + } + if (puzzle.symType == SYM_TYPE_ROTATE_RIGHT || puzzle.symType == SYM_TYPE_FLIP_XY) { + if (dir === MOVE_RIGHT) return MOVE_BOTTOM + if (dir === MOVE_LEFT) return MOVE_TOP } return dir } @@ -495,7 +531,7 @@ window.onTraceStart = function(puzzle, pos, svg, start, symStart=null) { clearAnimations() // Add initial line segments + secondary symmetry cursor, if needed - if (puzzle.symmetry == null) { + if (puzzle.symType == SYM_TYPE_NONE) { data.puzzle.updateCell2(data.pos.x, data.pos.y, 'type', 'line') data.puzzle.updateCell2(data.pos.x, data.pos.y, 'line', window.LINE_BLACK) } else { @@ -641,7 +677,7 @@ window.onMove = function(dx, dy) { || (moveDir === MOVE_TOP && lastDir === MOVE_BOTTOM) || (moveDir === MOVE_BOTTOM && lastDir === MOVE_TOP)) - if (data.puzzle.symmetry != null) { + if (data.puzzle.symType != SYM_TYPE_NONE) { var symMoveDir = getSymmetricalDir(data.puzzle, moveDir) } @@ -649,21 +685,21 @@ window.onMove = function(dx, dy) { if (backedUp) { data.path.pop().destroy() data.puzzle.updateCell2(data.pos.x, data.pos.y, 'line', window.LINE_NONE) - if (data.puzzle.symmetry != null) { + if (data.puzzle.symType != SYM_TYPE_NONE) { data.puzzle.updateCell2(data.sym.x, data.sym.y, 'line', window.LINE_NONE) } } // Move to the next cell changePos(data.bbox, data.pos, moveDir) - if (data.puzzle.symmetry != null) { + if (data.puzzle.symType != SYM_TYPE_NONE) { changePos(data.symbbox, data.sym, symMoveDir) } // If we didn't back up, add a path segment and mark the new cell as visited if (!backedUp) { data.path.push(new PathSegment(moveDir)) - if (data.puzzle.symmetry == null) { + if (data.puzzle.symType == SYM_TYPE_NONE) { data.puzzle.updateCell2(data.pos.x, data.pos.y, 'line', window.LINE_BLACK) } else { data.puzzle.updateCell2(data.pos.x, data.pos.y, 'line', window.LINE_BLUE) @@ -849,7 +885,7 @@ function hardCollision() { } } - if (data.puzzle.symmetry != null) { + if (data.puzzle.symType != SYM_TYPE_NONE) { if (data.sym.x === data.pos.x && data.sym.y === data.pos.y) { console.spam('Collided with our symmetrical line') gapSize = 13 @@ -885,7 +921,7 @@ function move() { } else if (cell.line > window.LINE_NONE && lastDir !== MOVE_RIGHT) { console.spam('Collided with other line', cell.line) data.x = data.bbox.x1 + 12 - } else if (data.puzzle.symmetry != null) { + } else if (data.puzzle.symType != SYM_TYPE_NONE) { var symCell = data.puzzle.getSymmetricalCell(data.pos.x - 1, data.pos.y) if (symCell == null || symCell.type !== 'line' || symCell.gap === window.GAP_FULL) { console.spam('Collided with symmetrical outside / gap-2', cell) @@ -903,7 +939,7 @@ function move() { } else if (cell.line > window.LINE_NONE && lastDir !== MOVE_LEFT) { console.spam('Collided with other line', cell.line) data.x = data.bbox.x2 - 12 - } else if (data.puzzle.symmetry != null) { + } else if (data.puzzle.symType != SYM_TYPE_NONE) { var symCell = data.puzzle.getSymmetricalCell(data.pos.x + 1, data.pos.y) if (symCell == null || symCell.type !== 'line' || symCell.gap === window.GAP_FULL) { console.spam('Collided with symmetrical outside / gap-2', cell) @@ -921,7 +957,7 @@ function move() { } else if (cell.line > window.LINE_NONE && lastDir !== MOVE_BOTTOM) { console.spam('Collided with other line', cell.line) data.y = data.bbox.y1 + 12 - } else if (data.puzzle.symmetry != null) { + } else if (data.puzzle.symType != SYM_TYPE_NONE) { var symCell = data.puzzle.getSymmetricalCell(data.pos.x, data.pos.y - 1) if (symCell == null || symCell.type !== 'line' || symCell.gap === window.GAP_FULL) { console.spam('Collided with symmetrical outside / gap-2', cell) @@ -939,7 +975,7 @@ function move() { } else if (cell.line > window.LINE_NONE && lastDir !== MOVE_TOP) { console.spam('Collided with other line', cell.line) data.y = data.bbox.y2 - 12 - } else if (data.puzzle.symmetry != null) { + } else if (data.puzzle.symType != SYM_TYPE_NONE) { var symCell = data.puzzle.getSymmetricalCell(data.pos.x, data.pos.y + 1) if (symCell == null || symCell.type !== 'line' || symCell.gap === window.GAP_FULL) { console.spam('Collided with symmetrical outside / gap-2', cell) diff --git a/app/assets/javascripts/wittle/validate.js b/app/assets/javascripts/wittle/validate.js index 333d2e1..d6e6484 100644 --- a/app/assets/javascripts/wittle/validate.js +++ b/app/assets/javascripts/wittle/validate.js @@ -41,7 +41,7 @@ window.validateUserData = function(puzzle, path) { if (cell.start === true) { puzzleHasStart = true - if (puzzle.symmetry != null) { + if (puzzle.symType != SYM_TYPE_NONE) { var symCell = puzzle.getSymmetricalCell(x, y) if (symCell == null || symCell.start !== true) { throw Error('Startpoint at ' + x + ' ' + y + ' does not have a symmetrical startpoint') @@ -50,7 +50,7 @@ window.validateUserData = function(puzzle, path) { } if (cell.end != null) { puzzleHasEnd = true - if (puzzle.symmetry != null) { + if (puzzle.symType != SYM_TYPE_NONE) { var symCell = puzzle.getSymmetricalCell(x, y) if (symCell == null || symCell.end == null || symCell.end != puzzle.getSymmetricalDir(cell.end)) { throw Error('Endpoint at ' + x + ' ' + y + ' does not have a symmetrical endpoint') -- cgit 1.4.1