diff --git a/README.md b/README.md index 7b7cd35..daa3020 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,5 @@ Rubik Helper tools [RubikHelper test page](http://fabiodimonte.github.io/RubikHelper/) + +[RubikHelper wiki pages](https://github.com/FabioDiMonte/RubikHelper/wiki) diff --git a/bower.json b/bower.json index 1c74378..9069cc1 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "RubikHelper", - "version": "0.1.0", + "version": "0.1.1", "homepage": "https://github.com/FabioDiMonte/RubikHelper", "authors": [ "Fabio Di Monte " diff --git a/package.json b/package.json index b03dc7f..e33afcf 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "rubikhelper", "title": "RubikHelper", "description": "Rubik Helper tools", - "version": "0.1.0", + "version": "0.1.1", "author": { "name": "FabioDiMonte" }, diff --git a/public/0.1.1/rubikhelper-0.1.1.min.js b/public/0.1.1/rubikhelper-0.1.1.min.js new file mode 100644 index 0000000..7fdd3f7 --- /dev/null +++ b/public/0.1.1/rubikhelper-0.1.1.min.js @@ -0,0 +1,4 @@ +/*! RubikHelper - v0.1.1 - 2015-05-04 */ +var RubikHelper=function(){var a=function(){var a=function(){function a(){this._attributes={}}return a.prototype={set:function(a,b){return this._attributes[a]=b,this},get:function(a){return this._attributes[a]},_extend:function(a,b){if(b)for(var c in b)b.hasOwnProperty(c)&&(a[c]&&a[c]instanceof Object&&!(a[c]instanceof Array)?this._extend(a[c],b[c]):a[c]=b[c])}},a}(),b=function(){function a(a,b,c){this.x=parseFloat(a)||0,this.y=parseFloat(b)||0,this.z=parseFloat(c)||0}return a.prototype={toOrtho:function(){return new a(this.x-this.y,(this.x+this.y)/2-1.25*this.z,0)},toIso:function(){return new a(this.y+this.x/2,this.y-this.x/2,0)},toString:function(){return"{x:"+this.x+", y:"+this.y+", z:"+this.z+"}"},toObject:function(){return{x:this.x,y:this.y,z:this.z}},toArray:function(){return[this.x,this.y,this.z]},add:function(b){return new a(this.x+b.x,this.y+b.y,this.z+b.z)},subtract:function(b){return new a(this.x-b.x,this.y-b.y,this.z-b.z)},multiply:function(b){return new a(this.x*b.x,this.y*b.y,this.z*b.z)},distance:function(a){var b=Math.abs(this.x-a.x),c=Math.abs(this.y-a.y),d=Math.abs(this.z-a.z),e=Math.sqrt(Math.pow(b,2)+Math.pow(c,2));return Math.sqrt(Math.pow(e,2)+Math.pow(d,2))}},a}(),c=function(){function a(a){this._stepCallback=null,this._animation=null,this._startTime=0,a&&this.setCallback(a),window.requestAnimFrame=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(a){return window.setTimeout(a,1e3/60)}}(),window.cancelRequestAnimFrame=function(){return window.cancelAnimationFrame||window.cancelRequestAnimationFrame||window.webkitCancelRequestAnimationFrame||window.mozCancelRequestAnimationFrame||window.oCancelRequestAnimationFrame||window.msCancelRequestAnimationFrame||clearTimeout}()}return a.prototype={setCallback:function(a){this._stepCallback=a},start:function(a){this._startTime=(new Date).getTime(),this._animate(),a&&setTimeout(function(){this.stop()}.bind(this),a)},stop:function(){cancelRequestAnimFrame(this._animation),this._animation=null},_animate:function(){this._stepRender(),this._animation=requestAnimFrame(this._animate.bind(this))},_stepRender:function(){var a=(new Date).getTime()-this._startTime;this._stepCallback&&this._stepCallback(a)}},a}(),d=function(){function a(a){this.context=a,this.message=null,this.messageOrigin={x:0,y:0},this.isPath=!1,this.isStroke=!1}return a.prototype={setup:function(a){a||(a={});var b=null==a.fillColor?null:this.castToColor(a.fillColor),c=null==a.strokeColor?null:this.castToColor(a.strokeColor),d=a.strokeSize;this.context.restore(),this.context.fillStyle=b,this.context.strokeStyle=c,this.context.lineWidth=d,this.context.globalAlpha=a.alpha||1,this.context.font=a.font||"20px Open Sans",this.context.save(),this.isStroke=null!=c,this.isPath=null!=b,this.isPath&&this.context.beginPath()},render:function(){this.message&&(this.isPath&&this.context.fillText(this.message,this.messageOrigin.x,this.messageOrigin.y),this.isStroke&&this.context.strokeText(this.message,this.messageOrigin.x,this.messageOrigin.y),this.message=null),this.isPath&&this.context.closePath(),this.isPath&&this.context.fill(),this.isPath=!1,this.isStroke&&this.context.stroke(),this.isStroke=!1},moveTo:function(a,b){var c=this.isPath||this.isStroke;return c&&this.context.moveTo(a,b),c},lineTo:function(a,b){var c=this.isPath||this.isStroke;return c&&this.context.lineTo(a,b),c},text:function(a,b){if(!a)return[];b||(b=[0,0]),b=this.castToPoint(b),this.messageOrigin=b,this.message=a;var c=this.context.measureText(a),d=this.context.font,e=Math.ceil(c.width),f=parseInt(d);return isNaN(f)&&(d=d.substr(d.indexOf(" ")),f=parseInt(d)),[b.add([0,0]),b.add([e,0]),b.add([e,-f]),b.add([0,-f])]},line:function(a,b,c){return a&&b?(a=this.castToPoint(a),b=this.castToPoint(b),c&&(a=a.toOrtho(),b=b.toOrtho()),this.moveTo(a.x,a.y)&&this.lineTo(b.x,b.y)):!1},polygon:function(a,b,c){if(!a)return[];b||(b=[0,0,0]),b=this.castToPoint(b),a=a.map(function(a){return this.castToPoint(a)}.bind(this)),c&&(b=b.toOrtho()),c&&(a=a.map(function(a){return a.toOrtho()}));var d,e,f=b.add(a[0]),g=[];for(this.moveTo(f.x,f.y)&&g.push(f),d=1;d1&&a.length<4&&(c=new b(parseFloat(a[0]),parseFloat(a[1]),parseFloat(a[2]))),c}},a}(),e=function(a,b){function c(c){if(!c)throw new Error('no "name" provided for this displayObject:',this);if(a.call(this),this._name=c,this._parent=null,this._zIndex=0,this._position=new b,this._shape=null,this._info={stepCallback:null,renderMethod:null,renderInfo:null},this._options={strokeColor:0,fillColor:0,strokeSize:1,alpha:1,font:"14px Arial"},this[c])throw new Error('property "%s" already exists on',c,this)}return c.prototype=Object.create(a.prototype),c.prototype.setOptions=function(a){return a?(this._extend(this._options,a),!0):!1},c.prototype.setRenderInfo=function(a,b){b&&this.setOptions(b),this._info.renderInfo=a},c.prototype.setAnimationStep=function(a){this._info.stepCallback=a.bind(this)},c.prototype._addTo=function(a,b){this._zIndex=b||0,this._parent=a},c.prototype._remove=function(){delete this},c.prototype._render=function(a,b){if(!this._info.renderMethod)throw new Error("no renderMethod set for this instance of DisplayObject: ",this);return this._info.renderInfo?(a._info.draw.setup(this._options),this._shape=a._info.draw[this._info.renderMethod](this._info.renderInfo,this._position,b),a._info.draw.render(),!0):!1},c.prototype._step=function(a){return this._info.stepCallback&&this._info.stepCallback(a),!0},c}(a,b),f=function(a){function b(b){a.call(this,b),this._info.renderMethod="image"}return b.prototype=Object.create(a.prototype),b.prototype.render=function(){},b}(e),g=function(a){function b(b){a.call(this,b),this._options.font=this.getFont("Verdana",14),this._options.fillColor=0,this._options.strokeColor=null,this._info.renderMethod="text"}return b.prototype=Object.create(a.prototype),b.prototype.getFont=function(a,b,c){return a?(c||(c=""),b||(b=""),"number"==typeof b&&(b+="px"),[c,b,a].join(" ")):""},b.prototype.setFont=function(a,b,c){return a?(this._options.font=this.getFont(a,b,c),!0):!1},b}(e),h=function(a){function b(b){a.call(this,b),this._options.fillColor=null,this._options.strokeColor=0,this._info.renderMethod="polygon"}return b.prototype=Object.create(a.prototype),b}(e),i=function(a){function b(b){a.call(this,b),this._children={},this._childrenLength=function(){var a=0;return c(this,function(){a++}),a}.bind(this._children),this._childrenArray=function(){var a=[];return c(this,function(b){a.push(b)}),a.sort(function(a,b){return a._zIndex-b._zIndex})}.bind(this._children)}function c(a,b){if(a&&b)for(var c in a)a.hasOwnProperty(c)&&b(a[c])}return b.prototype=Object.create(a.prototype),b.prototype._render=function(a,b){this._childrenArray().forEach(function(c){c._render(a,b)})},b.prototype._step=function(b){return this._childrenArray().forEach(function(a){a._step(b)}),a.prototype._step.call(this,b),!0},b.prototype.addChild=function(b,c){if(!(b instanceof a))throw new Error("adding child with unsupported type:",typeof b);if(this[b._name])throw new Error('property "',b._name,'" already exists on',this);return c||(c=this._childrenLength()),this._children[b._name]=b,this[b._name]=b,b._addTo(this,c),this._reorderChildren(),b},b.prototype.removeChild=function(b){b instanceof String&&(b=this[b]),b&&this[b._name]&&this[b._name]instanceof a&&(delete this._children[b._name],delete this[b._name],b._remove())},b.prototype._reorderChildren=function(){this._childrenArray().forEach(function(a,b){a._info.index=b})},b.prototype._getShapes=function(){for(var a,c=[],d=0;d").addClass("iso-layer").css({position:"absolute",top:0,left:0}).append(this._info.canvas)}return e.prototype=Object.create(b.prototype),e.prototype._render=function(){this.clear(),b.prototype._render.call(this,this,this._info.mode==this._info.modes.ISOMETRIC)},e.prototype._remove=function(){this.$el.remove()},e.prototype._addTo=function(a){if(a){var b=a.worldSize();this.setSize(b.w,b.h),this.$el.appendTo(a.$el),this._engine=a}},e.prototype.toggleMode=function(a){this._info.modes[a]&&this.mode!=a&&(this.mode=a,this._render())},e.prototype.clear=function(){this._info.context.clearRect(-this._info.size.w/2,-this._info.size.h/2,this._info.size.w,this._info.size.h)},e.prototype.getCanvas=function(){return this._info.canvas},e.prototype.renderTime=function(a){this._step(a)&&this._render()},e.prototype.startAnimation=function(a){this._info.animator.start(a)},e.prototype.stopAnimation=function(){this._info.animator.stop()},e.prototype.setSize=function(a,b){this._info.size={w:a,h:b},this._info.canvas.width=a.toString(),this._info.canvas.height=b.toString(),this._info.context.translate(a/2,b/2)},e.prototype.setShadow=function(a,b,c,d){this._info.context.shadowColor=a||"#999",this._info.context.shadowBlur=b||20,this._info.context.shadowOffsetX=c||15,this._info.context.shadowOffsetY=d||c||15},e}(jQuery,i),k=function(a){function b(b){a.call(this,b)}return b.prototype=Object.create(a.prototype),b}(i),l=function(a,b){function c(){this.$el=a("
"),this.layers={},this.fpsInterval=null,this.fpsLogInterval=null,this.utils={worldSizeWidth:400,worldSizeHeight:400}}function d(a,b){for(var c=!1,d=-1,e=a.length,f=e-1;++d-1),c&&"string"==typeof c&&(d=!(1==c.length&&c==a.charAt(0))),c&&c instanceof Array&&(d=-1==c.indexOf(a)),d}},service:{targetOf:function(a){var c,d,e,f,g,h=a.toUpperCase();return null==b.pieces.cube[h]&&(c=h.indexOf("U"),d=h.indexOf("D"),e=h.indexOf("F"),f=h.indexOf("B"),g=c>-1?c:d>-1?d:e>-1?e:f>-1?f:null,g&&(h=h.substr(g)+h.substr(0,g))),h},moveCounter:function(a,b){var c=0;for(var d in a)a.hasOwnProperty(d)&&(c+=Number(a[d]==b));return c},cloneCube:function(a){var c,d={};for(c in b.pieces.cube)b.pieces.cube.hasOwnProperty(c)&&(d[c]=a&&a[c]?a[c]:b.pieces.cube[c]);return d},getPieceFromStickers:function(a,c){var d,e;for(d in c)if(c.hasOwnProperty(d)&&(c[d]==a||c[d]==b.service.rotate(a,-1)||c[d]==b.service.rotate(a,1)))return e=b.service.getRotation(c[d]),b.service.rotate(d,e);return!1},getStickersFromPiece:function(a,c,d){var e,f,g=b.service.targetOf(a),h=c[g],i=[];if(a==g||!d&&b.is.median(a))return h;for(e=0;e=1){-1==d.x.indexOf(a[0])?c=d.x:-1==d.y.indexOf(a[0])?c=d.y:-1==d.z.indexOf(a[0])&&(c=d.z);for(var g in e)e.hasOwnProperty(g)&&-1==c.indexOf(g)&&f.push(g)}if(a.length>=2){var h="U"==a[0]||"F"==a[0]||"L"==a[0]?1:"D"==a[0]||"B"==a[0]||"R"==a[0]?-1:0,i=c.indexOf(a[1]),j=i+2,k=i+h+2*h;j>=c.length&&(j-=c.length),k>=c.length&&(k-=c.length),0>k&&(k=c.length+k),f.push(a[1]),f.push(c[j]),f.push(c[k])}return 3==a.length&&f.push(a[2]),f}},math:{multiply:function(a,b){var c,d=[];for(c=0;b>c;c++)d=d.concat(a);return d},negative:function(a){var c,d,e=a;return b.canbe.negative(a)&&(c=a.charAt(0),d=1==a.length?"+":a.charAt(1),d=b.math.signInverse(d),e=c+d),e},inverse:function(a){var c=a;return b.canbe.negative(a)&&(c=b.math.negative(a)),c},mirror:function(a,c){c||(c="M");var d,e,f=a;return b.canbe.mirror(a)&&(d=a.charAt(0),d="M"==c?"L"==d?"R":"R"==d?"L":d:d,d="E"==c?"U"==d?"D":"D"==d?"U":d:d,d="S"==c?"F"==d?"B":"B"==d?"F":d:d,e=1==a.length?"+":a.charAt(1),f=b.math.negative(d+e)),f},negativePattern:function(a,c,d){var e,f=[];for(e=0;e=0?r[s]:p).push(a)}function g(a){s>-1?r[s]=r[s].concat(a):p=p.concat(a)}function h(){if("("==j&&(r[++s]=[]),")"==j&&(n=r[s],l==Number(l)?n=b.math.multiply(n,Number(l)):"-"==l||"'"==l?n=b.math.negativePattern(n):"m"==l.toLowerCase()?n=b.math.mirrorPattern(n):"i"==l.toLowerCase()&&(n=b.math.inversePattern(n)),s--,g(n),("m"==l.toLowerCase()||"i"==l.toLowerCase())&&(l="")&&(j="")),"["!=j||o||(o=[]),"]"==j&&o){if(o=o.join("").toUpperCase(),b.is.piece(o)||b.is.pattern(o)){var a=b.is.piece(o)?"s_":b.is.pattern(o)?"p_":"",d=b.patterns[a+o];d&&g(b.parse.moves(d))}o=!1}o&&"["!=j?f(j):j&&b.is.move(j)&&(m="2"==l?c?"+":l:"+"==l||"-"==l?l:"i"==l||"'"==l?"-":"+",k=(e&&!o?j:b.clear.adjustCase(j))+m,c&&"2"==l&&f(k),f(k),o||e||j!=j.toLowerCase()||(k=!1,"u"==j?k="E"+m:"d"==j?k="E"+b.math.signInverse(m):"f"==j?k="S"+m:"b"==j?k="S"+b.math.signInverse(m):"l"==j?k="M"+m:"r"==j&&(k="M"+b.math.signInverse(m)),k&&f(k))),j=l}for(var i,j,k,l,m,n,o,p=[],q=b.clear.all(a).split(""),r=[],s=-1,t=0;t0&&c==e&&(i.pop(),d==f?"2"==d?h=!1:d="2":(d=b.math.signSum(f,d),d||(h=!1))),h&&i.push(c+d),e=0==i.length?"":i[i.length-1].charAt(0),f=0==i.length?"":i[i.length-1].charAt(1);return i},uncollapseSequence:function(a){var b,c,d,e=[];for(d=0;da.expand.piece(i,!0).length),h&&(e?k.push(i):k=i)}return k},opposite:function(b,d){var e=d?"buffers":"normals",f=a.pieces.opposites[e].edges.indexOf(b),g=a.pieces.opposites[e].corners.indexOf(b),h=[b],i=0;return f>-1&&(i=f+2,h=a.pieces.opposites[e].edges),g>-1&&(i=g+3,h=a.pieces.opposites[e].corners),i>=h.length&&(i-=h.length),f>-1&&(d||c.explainCallback("PIECES_CYCLE_OPPOSITE_MEDIAN_EDGES",[b,h[i]])),g>-1&&(d||c.explainCallback("PIECES_CYCLE_OPPOSITE_RIGHT_CORNERS",[b,h[i]])),h[i]}},solve:{explain:function(a){return c.explainArray=[],c.solveArray=c.solve.full(a,0),{s:c.solveArray,e:c.explainArray}},full:function(b,d){if((!d||0>d||d>3)&&(d=0),!c.check.orientedCube(b))return[];if(!c.check.correctPieces(b))return[];c.explainCallback("BEGIN");var e=c.solve.edgesUnoriented(b);e=e.concat(c.solve.pieces(b,a.pieces.buffers.edge,a.pieces.M2));var f=c.solve.pieces(b,a.pieces.buffers.corner,a.pieces.R2),g=Boolean(a.service.moveCounter(e,a.pieces.M2)%2),h=Boolean(a.service.moveCounter(f,a.pieces.R2)%2);g!=h&&console.warn("WARNING: this case is not handled!! parity happened only on edges or corners..",b);var i=e.concat(f);c.explainCallback("END",[i.toString()]);var j=a.expand.pattern(i),k=a.clear.collapseSequence(j),l=a.clear.uncollapseSequence(j),m=a.math.inversePattern(k);return 0==d?i:1==d?l:2==d?k:3==d?m:[]},pieces:function(b,d,e){function f(e,f,g){var h=a.service.targetOf(e);if(a.is.median(e)&&(g||h!=d)){var i=a.service.getPieceFromStickers(e,b);c.explainCallback("PIECES_EDGES_BEGIN",e);var j=i!=a.service.targetOf(i);j||c.explainCallback("PIECES_EDGES_FLIPPED_STATE",[e,j]);var k=f&&a.service.getRotation(f)&&!a.is.median(f);k&&(j=!j),g&&(j=r),k&&c.explainCallback("PIECES_EDGES_PREVIOUS_FLIPPED",[e,f]),g&&r&&c.explainCallback("PIECES_EDGES_BUFFER_FLIPPED",e),j&&-1==n.indexOf(h)&&(n.push(h),c.explainCallback("PIECES_EDGES_ADD_TO_FLIPPED",[e,n.toString()])),c.explainCallback("END_VOID")}}function g(b){var d=q?c.service.opposite(j):j;b?(u=h,c.explainCallback("MEMORIZE_PLACEHOLDER",h)):c.explainCallback("MEMORIZE_PIECE",d),m.push(d),k=a.service.getStickersFromPiece(j,i),q=!q,i[h]=h,j!=k&&(c.explainCallback("PIECES_CYCLE_CHECK_NEXT_PIECE",[j,k]),o&&f.call(this,k,j))}var h,i=a.service.cloneCube(b),j=d,k=i[d],l=!k,m=[],n=[],o=a.is.edge(d),p=a.is.corner(d);c.explainCallback("PIECES_BEGIN",(o?"edges":p?"corners":"").toUpperCase());var q=!1,r=!1,s=!1,t=!1,u=!1;for(c.explainCallback("PIECES_CYCLE_BEGIN"),c.explainCallback("PIECES_CYCLE_EXAMINE_BUFFER",d),c.explainCallback("PIECES_CYCLE_CHECK_BUFFER_POSITION",k),o&&f.call(this,k),c.explainCallback("END_VOID");!l;){if(c.explainCallback("PIECES_CYCLE_EXAMINE_PIECE",k),j=k,h=a.service.targetOf(j),t=a.is.buffer(j),t&&c.explainCallback("PIECES_CYCLE_BUFFER_FOUND",[j,j!=h]),r=t?j!=h:h!=u||j==h||a.is.median(j)?r:!r,t||h!=u||(u=!1,t=!0,c.explainCallback("PIECES_CYCLE_PLACEHOLDER_FOUND",[j,j!=h&&!a.is.median(j)]),o&&j!=h&&c.explainCallback("PIECES_CYCLE_EDGE_IS_FLIPPED",[j,a.is.median(j)]),g.call(this)),t)if(s=c.service.freeTarget(i,j.length),c.explainCallback("PIECES_CYCLE_CHECK_FREE_TARGET",s.toString()),s!==!1)j=s,h=s,g.call(this,!0);else{if(c.explainCallback("PIECES_CYCLE_ALL_IS_OK"),o&&f.call(this,d,!1,!0),q){if(c.explainCallback("PIECES_PARITY_BEGIN"),c.explainCallback("MEMORIZE_MIDDLE",[o?"M-slice":"R-face",e]),m=m.concat(e),o){if(n.length>0){for(var v in n)n[v]=c.service.opposite(n[v],!0);c.explainCallback("PIECES_PARITY_SWITCH_FLIPPED_MEDIANS",n.toString())}}else c.explainCallback("MEMORIZE_PARITY","PAR"),m=m.concat(["PAR"]);c.explainCallback("END_VOID")}if(o){var w=c.solve.mEdgesUnoriented(n);m=m.concat(w),w.length>0&&c.explainCallback("MEMORIZE_ORIENT_EDGES",w.toString())}l=!0}else g.call(this);c.explainCallback("END_VOID")}return c.explainCallback("END_VOID"),c.explainCallback("PIECES_END",[(o?"edges":p?"corners":"").toUpperCase(),m.toString()]),m},edgesUnoriented:function(){c.explainCallback("UNORIENTED_BEGIN");var a=[];return c.explainCallback("UNORIENTED_WIP"),c.explainCallback("UNORIENTED_END",[a.toString()]),a},mEdgesUnoriented:function(a){var b,c,d,e,f,g,h=[];return(1==a.length||3==a.length||a.length>4)&&console.error("ERROR: wrong array of flipped M-edges: ",a),4==a.length&&(h=["O2U","O2D"]),2==a.length&&(d=a[0].charAt(0),e=a[0].charAt(1),a[1].indexOf(d)>-1&&(c=d),a[1].indexOf(e)>-1&&(c=e),c?h=["O2"+c]:(f=a[0].indexOf("D"),g=a[1].indexOf("D"),f>-1&&(b=Number(!f),c=a[0].charAt(b)),g>-1&&(b=Number(!g),c=a[1].charAt(b)),c&&(h=[c+"2","O2U",c+"2"]))),h}}}}(b),d=function(){var a={TITLE:{p:0,g:0,m:"* SOLVE PROCESS *"},BEGIN:{p:0,g:1,m:"begin memorizing"},END:{p:0,g:-1,m:"end memorizing [%s]"},BEGIN_VOID:{p:3,g:1,m:""},END_VOID:{p:3,g:-1,m:""},UNORIENTED_BEGIN:{p:3,g:1,m:"solve unoriented edges"},UNORIENTED_END:{p:3,g:-1,m:"unoriented pieces: [%s]"},UNORIENTED_WIP:{p:3,g:0,m:"method not yet implemented. will return an empty array."},PIECES_BEGIN:{p:3,g:1,m:"solve unpermuted/unoriented %s"},PIECES_END:{p:1,g:-1,m:"done with %s: [%s]"},PIECES_CYCLE_BEGIN:{p:3,g:1,m:"piece-finding cycle"},PIECES_CYCLE_EXAMINE_BUFFER:{p:3,g:1,m:"examine the buffer [%s]"},PIECES_CYCLE_EXAMINE_PIECE:{p:3,g:1,m:"examine the piece [%s]"},PIECES_CYCLE_CHECK_BUFFER:{p:1,g:0,m:"first thing first: examine the buffer piece: [%s]"},PIECES_CYCLE_BUFFER_FOUND:{p:2,g:0,m:"the piece [%s] is the buffer - flipState: %s"},PIECES_CYCLE_PLACEHOLDER_FOUND:{p:2,g:0,m:"the piece in [%s] position is the buffer - should invert flipState? %s"},PIECES_CYCLE_CHECK_FREE_TARGET:{p:1,g:0,m:"check for the first target to be solved: [%s]"},PIECES_CYCLE_ALL_IS_OK:{p:2,g:0,m:"all pieces are correctly permuted"},PIECES_CYCLE_CHECK_BUFFER_FLIP:{p:1,g:0,m:"check if edge buffer is flipped after all iterations"},PIECES_CYCLE_EDGE_IS_FLIPPED:{p:2,g:0,m:"note that the edge [%s] is flipped - is median? %s"},PIECES_CYCLE_BUFFER_FLIP_STATE:{p:1,g:0,m:"remember to %s the flip state of buffer piece when edges are finished"},PIECES_CYCLE_OPPOSITE_MEDIAN_EDGES:{p:2,g:0,m:"the M-slice is rotated, so switch DB with UF or viceversa: [%s] -> [%s]"},PIECES_CYCLE_OPPOSITE_RIGHT_CORNERS:{p:2,g:0,m:"the R-face is rotated, so switch DRB with URF or viceversa: [%s] -> [%s]"},PIECES_CYCLE_CHECK_NEXT_PIECE:{p:2,g:0,m:"look at the piece in [%s] position: [%s]"},PIECES_CYCLE_CHECK_BUFFER_POSITION:{p:2,g:0,m:"look at the piece in buffer position: [%s]"},PIECES_EDGES_BEGIN:{p:3,g:1,m:"check for flipped median edge [%s]"},PIECES_EDGES_FLIPPED_STATE:{p:2,g:0,m:"flipped state of piece [%s] : %s"},PIECES_EDGES_PREVIOUS_FLIPPED:{p:1,g:0,m:"invert flipped state of [%s] because previous piece [%s] was unoriented"},PIECES_EDGES_BUFFER_FLIPPED:{p:2,g:0,m:"invert flipped state of buffer [%s]"},PIECES_EDGES_ADD_TO_FLIPPED:{p:1,g:0,m:"edge [%s] is flipped, add it to the flipped edge list: [%s]"},PIECES_EDGES_DONT_CHECK_BUFFER:{p:2,g:0,m:"is not the time to check the buffer [%s] flip state"},PIECES_EDGES_IS_MEDIAN:{p:2,g:0,m:"the piece [%s] is part of median slice"},PIECES_EDGES_CHECK_ONLY_MEDIAN:{p:2,g:0,m:"the piece [%s] is not part of median slice"},PIECES_PARITY_BEGIN:{p:3,g:1,m:"parity occurred!"},PIECES_PARITY_SWITCH_FLIPPED_MEDIANS:{p:2,g:0,m:"switch DF with UB and viceversa in the list of flipped edges: [%s]"},MEMORIZE_MIDDLE:{p:0,g:0,m:"** the %s is rotated, for now rotate it back with [%s]"},MEMORIZE_PARITY:{p:0,g:0,m:"** finally do the parity pattern: [%s]"},MEMORIZE_PIECE:{p:0,g:0,m:"** memorize the piece: [%s]"},MEMORIZE_PLACEHOLDER:{p:0,g:0,m:"** memorize the buffer placeholder position: [%s]"},MEMORIZE_ORIENT_EDGES:{p:0,g:0,m:"** memorize the sequence for correctly orient the median edges: [%s]"}};return{constants:a,explain:function(a,b){var c=0,d=0,e=a,f=this.constants[a]; + +f&&(c=f.p,d=f.g,e=f.m);var g,h,i;if(e){if(g=e,b)if("string"==typeof b)g=e.replace(/%s/g,b);else{i=e.split("%s");for(h in i)i.hasOwnProperty(h)&&null!=b[h]&&(i[h]=i[h]+b[h]);g=i.join("")}}else d=-1;return{m:g,g:d,p:c}},explainAll:function(a,b){for(var c,d=[],e=0;e=c)){var d=!0,e=d?console.groupCollapsed:console.group;b>0&&a&&e(a),0>=b&&a&&console.log(a),0>b&&console.groupEnd()}}}}(),e=function(a,b){function c(c,d){if(this.$el=a("#"+c),0==this.$el.length)throw new Error("rubik cube not drawn: given ID does not exists in dom");this._options={pieceSize:30,showAxis:!1},this._currentCube=b.service.cloneCube(b.pieces.cube),a.extend(this._options,d)}function d(){return b.service.cloneCube(this._currentCube)}function e(a){this._currentCube=b.service.cloneCube(a),this.render()}function f(b,c){function f(b){a.extend(i,k.rotatedPieces(b)),e.call(k,i)}function g(){b.length>0&&setTimeout(function(){f(b[j++]),j0||f>0||g>0?"+":0>e||0>f||0>g?"-":c;return h+i},rotatedPieces:function(a){var c={};if(a){var d,e,f,g=a.charAt(0),h=null;!h&&null!=b.pieces.axis[g]&&(h=b.pieces.pieces),!h&&null!=b.pieces.slices[g]&&(h=b.pieces.slices[g]),!h&&null!=b.pieces.faces[g]&&(h=b.pieces.faces[g]);for(d in h)h.hasOwnProperty(d)&&(e=b.service.targetOf(h[d]),f=this.orientedPiece(e,a),c[e]=b.service.getStickersFromPiece(f,this._currentCube,!0))}return c},orientedPiece:function(a,c){var d,e,f,g,h=this.axisRotation(c),i=b.pieces.axis[h.charAt(0)],j="-"==h.charAt(1)?-1:1,k=a.split(""),l=[];for(d=0;df?i.length-1:f>=i.length?0:f,l.push(i[f]));return l.join("")}},c}(jQuery,b),f=function(a,b,c){function d(a,c){b.call(this,a,c),this._renderOptions={order:["DBL","DB","DRB","DL","D","DR","DLF","DF","DFR","BL","B","BR","L","R","FL","F","FR","ULB","UB","UBR","UL","U","UR","UFL","UF","URF"],backfaces:!1,highlights:[],highlightColored:!1},this.iso={container:this.$el,engine:new l},this.iso.engine.init(this.iso.container,{worldSizeWidth:400,worldSizeHeight:300}),this.iso.layer=this.iso.engine.addLayer("cube",!0),this.iso.console=this.iso.engine.addLayer("console");var d=this.iso.console.addChild(new p("cubeletInfo"));d._position=new m(-200,120),d.setFont("Open Sans",20),this.render()}function e(a){this._renderOptions.backfaces=null!=a?a:!this._renderOptions.backfaces,this.render()}function f(b){var c=[];b&&b.forEach(function(b){c.push(a.service.targetOf(b))}.bind(this)),this._renderOptions.highlights=c,this.render()}function g(b,c,d,e){c||(c=b);for(var f,g,j=this._options.pieceSize,k=new m(-j/2,-j/2,-j/2),l=[],n=[b.indexOf("U"),b.indexOf("R"),b.indexOf("F"),b.indexOf("D"),b.indexOf("B"),b.indexOf("L")],o=0;o=3)&&(g={name:f,color:f?d?a.colors[c]:a.colors[f]:null}),l.push(g);var p=-1!=b.indexOf("D")?-1:-1!=b.indexOf("U")?1:0,q=-1!=b.indexOf("F")?1:-1!=b.indexOf("B")?-1:0,r=-1!=b.indexOf("L")?-1:-1!=b.indexOf("R")?1:0,s=!0;this.iso.layer._children["_piece_"+b]||h.call(this,b,k.add(new m(j*r,j*q,j*p)),j,s),i.call(this,b,c,j,{fills:l,stroke:a.colors.core},s)}function h(a,b,c,d){var e=new n("_piece_"+a);e.set("position",a),d&&(e.addChild(new o("_face_D")).set("position","D")._position=b.add(new m(0,0,0)),e.addChild(new o("_face_B")).set("position","B")._position=b.add(new m(0,0,0)),e.addChild(new o("_face_L")).set("position","L")._position=b.add(new m(0,0,0))),e.addChild(new o("_face_U")).set("position","U")._position=b.add(new m(0,0,c)),e.addChild(new o("_face_R")).set("position","R")._position=b.add(new m(c,0,0)),e.addChild(new o("_face_F")).set("position","F")._position=b.add(new m(0,c,0)),this.iso.layer.addChild(e)}function i(a,b,c,d,e){var f=this.iso.layer._children["_piece_"+a];if(f){f.set("sticker",b);var g=d.fills.map(function(a){return a&&a.name}),h={fills:d.fills.map(function(a){return a&&a.color}),color:d.stroke};e&&h.fills&&6==h.fills.length&&(j.call(this,f._children._face_D,k(g,3),"get3DPolygonSquare",c,h.fills?k(h.fills,3):null,h.color),j.call(this,f._children._face_B,k(g,4),"get3DPolygonSquareLeft",c,h.fills?k(h.fills,4):null,h.color),j.call(this,f._children._face_L,k(g,5),"get3DPolygonSquareRight",c,h.fills?k(h.fills,5):null,h.color)),j.call(this,f._children._face_U,k(g,0),"get3DPolygonSquare",c,h.fills?k(h.fills,0):null,h.color),j.call(this,f._children._face_R,k(g,1),"get3DPolygonSquareRight",c,h.fills?k(h.fills,1):null,h.color),j.call(this,f._children._face_F,k(g,2),"get3DPolygonSquareLeft",c,h.fills?k(h.fills,2):null,h.color)}}function j(a,b,c,d,e,f){e?a.setRenderInfo(this.iso.engine.drawUtils[c](d),{strokeColor:null==e?null:f,fillColor:e,strokeSize:1}):a.setRenderInfo(null),a.set("sticker",b)}function k(a,b){return a.length>b?a[b]:a[a.length-1]}var l=c.core.Engine,m=c.core.Point,n=c.display.Sprite,o=c.display.Shape,p=c.display.Text;return d.prototype=Object.create(b.prototype),d.prototype.willRender=function(){},d.prototype.didRender=function(){this.iso.layer._render(),this._options.showAxis&&this.iso.engine.drawUtils.axis(this.iso.layer,200)},d.prototype.render=function(a){var b,c=this._renderOptions.highlights,d=this._renderOptions.highlightColored;return this.willRender(),this._renderOptions.order.forEach(function(e){0==c.length?(b=this._currentCube[e],(!a||a.indexOf(e)>-1)&&g.call(this,e,b,!1,this._renderOptions.backfaces)):(b=c.indexOf(e)>-1?d?this._currentCube[e]:"light":"grey",g.call(this,e,b,"grey"==b||"light"==b,this._renderOptions.backfaces))}.bind(this)),this.didRender(),!0},d.prototype.getImage=function(){return this.iso.layer.getCanvas().toDataURL()},d.prototype.backfaceState=function(){return this._renderOptions.backfaces},d.prototype.backfaceToggle=function(a){e.call(this,a)},d.prototype.highlight=function(a){f.call(this,a)},d.prototype.highlightColor=function(a){this._renderOptions.highlightColored=a,this.render()},d}(b,e,a),g=function(a,b,c,d,e){var f={};return f.cube={},f.cube.RubikCube=a,f.cube.RubikCubeIso=b,f["static"]={},f["static"].RubikSolver=c,f["static"].RubikTeacher=d,f["static"].RubikUtils=e,f}(e,f,c,d,b);return g}(); \ No newline at end of file diff --git a/public/0.1.1/tools/RubikCube-0.1.1.min.js b/public/0.1.1/tools/RubikCube-0.1.1.min.js new file mode 100644 index 0000000..8718b53 --- /dev/null +++ b/public/0.1.1/tools/RubikCube-0.1.1.min.js @@ -0,0 +1,2 @@ +/*! RubikCube - v0.1.1 - 2015-05-04 */ +var RubikCube=function(){var a=function(){return{colors:{U:"#ffff00",D:"#ffffff",F:"#ff0000",B:"#ffaa00",L:"#0000ff",R:"#008800",light:"#ffff00",grey:"#cccccc",core:"#222222"},patterns:{p_O4U:" (M'U)4 (MU)4 ",p_O4D:" (M'D)4 (MD)4 ",p_O4F:" (M'F)4 (MF)4 ",p_O4B:" (M'B)4 (MB)4 ",p_O2U:" (M'U)3 U (MU)3 U ",p_O2D:" (M'D)3 D (MD)3 D ",p_O2F:" (M'F)3 F (MF)3 F ",p_O2B:" (M'B)3 B (MB)3 B ",p_O6L:" (R'FRU)5 ",p_O6R:" ([O6L])m ",p_CW2:" (U'RU) R' (U'RU) ",p_CC2:" ([CW2])i ",p_CW3:" ((UR)'UR)2 ",p_CC3:" ([CW3])i ",p_PTJ:" (L'U2) LU (L'U2) (RU') L (RU')i ",p_PTN:" ((L'UR') U2 (L'UR')')2 U ",p_PAR:" (U'F2) [PTJ] (U'F2)i ",p_PRN:" (F2y) [PTN] (F2y)i",s_UB:" ",s_UF:" (U2 M')2 ",s_DB:" ([UF])i ",s_UR:" R'U RU' ",s_DR:" U R RU' ",s_FR:" URU' ",s_BR:" ([FR])i ",s_UL:" ([UR])m ",s_DL:" ([DR])m ",s_FL:" ([FR])m ",s_BL:" ([BR])m ",s_BU:" [UB] ",s_FU:" [UF] ",s_BD:" [DB] ",s_RU:" x' ([BR])' ",s_RD:" x' ([FR])' ",s_RF:" x' ([DR])' ",s_RB:" x' ([UR])' ",s_LU:" x' (([BR])')m ",s_LD:" x' (([FR])')m ",s_LF:" x' (([DR])')m ",s_LB:" x' (([UR])')m ",s_UBR:" ",s_URF:" U' (R F' RM' U R2 U') (MR' F R U R2') ",s_DRB:" ([URF])i ",s_ULB:" (LU)' (LU)",s_UFL:" L U'L' U [ULB] ",s_DLF:" U' L2 U ",s_DBL:" [DLF] [ULB] ",s_BRU:" (U'L'U) L (U'L'U) ",s_RUB:" ([BRU])i ",s_RFU:" (F'R) (UR2U') R' (FR) (UR2U') R ",s_FUR:" R2 U' RM'x L2M2 (ULU') R' (UL'U') L'R'U ",s_RBD:" R'UR2U'R'F'RUR2U'R'F ",s_BDR:" RUR' DL2 x2 U'RU L2x2 U'D'R ",s_LBU:" (U'L'U) ",s_BUL:" y RUR2U'R' y' ",s_FLU:" R' (ULU') ",s_LUF:" L' (U'L'U) ",s_LFD:" L2 (U'L'U) ",s_FDL:" (U'L'U) L' (U'LU)",s_BLD:" (U'LU) ",s_LDB:" L (U'L'U) "},pieces:{M2:["M2"],R2:["R2"],opposites:{buffers:{edges:["DF","FD","UB","BU"],corners:["DFR","RDF","FRD","UBR","RUB","BRU"]},normals:{edges:["UF","FU","DB","BD"],corners:["URF","FUR","RFU","DRB","BDR","RBD"]}},buffers:{edge:"DF",corner:"DFR"},cube:{U:"U",D:"D",F:"F",B:"B",L:"L",R:"R",DF:"DF",DR:"DR",DB:"DB",DL:"DL",UF:"UF",UR:"UR",UB:"UB",UL:"UL",FR:"FR",BR:"BR",FL:"FL",BL:"BL",DFR:"DFR",DRB:"DRB",DBL:"DBL",DLF:"DLF",URF:"URF",UBR:"UBR",ULB:"ULB",UFL:"UFL"},pieces:["U","D","F","B","L","R","DF","DR","DB","DL","UF","UR","UB","UL","FR","BR","FL","BL","DFR","DRB","DBL","DLF","URF","UBR","ULB","UFL"],faces:{U:["ULB","UB","UBR","UL","U","UR","UFL","UF","URF"],D:["DLF","DF","DFR","DL","D","DR","DBL","DB","DRB"],F:["FLU","FU","FUR","FL","F","FR","FDL","FD","FRD"],B:["BRU","BU","BUL","BR","B","BL","BDR","BD","BLD"],L:["LBU","LU","LUF","LB","L","LF","LDB","LD","LFD"],R:["RFU","RU","RUB","RF","R","RB","RDF","RD","RBD"]},slices:{M:["F","U","B","D","UF","UB","DB","DF"],E:["F","R","B","L","FL","FR","BL","BR"],S:["U","R","D","L","UL","UR","DR","DL"]},axis:{x:["U","F","D","B"],y:["F","L","B","R"],z:["U","R","D","L"]},noUnsetup:["UF","DB","FU","BD","DRB","RBD","BDR","URF","RFU","FUR"]},is:{face:function(a){return/^[udfblr]$/i.test(a)},slice:function(a){return/^[mes]$/i.test(a)},axis:function(a){return/^[xyz]$/i.test(a)},move:function(b){return a.is.face(b)||a.is.slice(b)||a.is.axis(b)},modifier:function(a){return/^[2i'\-\+]$/.test(a)},rotation:function(a){return/^[udfblrmesxyz][2i'\-\+]?$/i.test(a)},median:function(a){return/^([ud][fb]|[fb][ud])$/i.test(a)},pattern:function(a){return/^(o[24][udfb]|o6[lr]|c[cw][23]|pt[jn]|par|prn)$/i.test(a)},piece:function(a){return/^(?:([udfblr])(?!.*\1)){2,3}$/i.test(a)},edge:function(b){return 2==b.length&&a.is.piece(b)},corner:function(b){return 3==b.length&&a.is.piece(b)},buffer:function(b){return a.is.edge(b)&&a.service.targetOf(b)==a.pieces.buffers.edge||a.is.corner(b)&&a.service.targetOf(b)==a.pieces.buffers.corner}},canbe:{negative:function(a){return 1==a.length||"+"==a.charAt(1)||"-"==a.charAt(1)},mirror:function(b){return a.canbe.negative(b)||"2"==b.charAt(1)},accepted:function(a,b,c){var d=!b&&!c||""==b&&""==c;return b&&"string"==typeof b&&(d=1==b.length&&b==a.charAt(0)),b&&b instanceof Array&&(d=b.indexOf(a)>-1),c&&"string"==typeof c&&(d=!(1==c.length&&c==a.charAt(0))),c&&c instanceof Array&&(d=-1==c.indexOf(a)),d}},service:{targetOf:function(b){var c,d,e,f,g,h=b.toUpperCase();return null==a.pieces.cube[h]&&(c=h.indexOf("U"),d=h.indexOf("D"),e=h.indexOf("F"),f=h.indexOf("B"),g=c>-1?c:d>-1?d:e>-1?e:f>-1?f:null,g&&(h=h.substr(g)+h.substr(0,g))),h},moveCounter:function(a,b){var c=0;for(var d in a)a.hasOwnProperty(d)&&(c+=Number(a[d]==b));return c},cloneCube:function(b){var c,d={};for(c in a.pieces.cube)a.pieces.cube.hasOwnProperty(c)&&(d[c]=b&&b[c]?b[c]:a.pieces.cube[c]);return d},getPieceFromStickers:function(b,c){var d,e;for(d in c)if(c.hasOwnProperty(d)&&(c[d]==b||c[d]==a.service.rotate(b,-1)||c[d]==a.service.rotate(b,1)))return e=a.service.getRotation(c[d]),a.service.rotate(d,e);return!1},getStickersFromPiece:function(b,c,d){var e,f,g=a.service.targetOf(b),h=c[g],i=[];if(b==g||!d&&a.is.median(b))return h;for(e=0;e=1){-1==d.x.indexOf(b[0])?c=d.x:-1==d.y.indexOf(b[0])?c=d.y:-1==d.z.indexOf(b[0])&&(c=d.z);for(var g in e)e.hasOwnProperty(g)&&-1==c.indexOf(g)&&f.push(g)}if(b.length>=2){var h="U"==b[0]||"F"==b[0]||"L"==b[0]?1:"D"==b[0]||"B"==b[0]||"R"==b[0]?-1:0,i=c.indexOf(b[1]),j=i+2,k=i+h+2*h;j>=c.length&&(j-=c.length),k>=c.length&&(k-=c.length),0>k&&(k=c.length+k),f.push(b[1]),f.push(c[j]),f.push(c[k])}return 3==b.length&&f.push(b[2]),f}},math:{multiply:function(a,b){var c,d=[];for(c=0;b>c;c++)d=d.concat(a);return d},negative:function(b){var c,d,e=b;return a.canbe.negative(b)&&(c=b.charAt(0),d=1==b.length?"+":b.charAt(1),d=a.math.signInverse(d),e=c+d),e},inverse:function(b){var c=b;return a.canbe.negative(b)&&(c=a.math.negative(b)),c},mirror:function(b,c){c||(c="M");var d,e,f=b;return a.canbe.mirror(b)&&(d=b.charAt(0),d="M"==c?"L"==d?"R":"R"==d?"L":d:d,d="E"==c?"U"==d?"D":"D"==d?"U":d:d,d="S"==c?"F"==d?"B":"B"==d?"F":d:d,e=1==b.length?"+":b.charAt(1),f=a.math.negative(d+e)),f},negativePattern:function(b,c,d){var e,f=[];for(e=0;e=0?r[s]:p).push(a)}function g(a){s>-1?r[s]=r[s].concat(a):p=p.concat(a)}function h(){if("("==j&&(r[++s]=[]),")"==j&&(n=r[s],l==Number(l)?n=a.math.multiply(n,Number(l)):"-"==l||"'"==l?n=a.math.negativePattern(n):"m"==l.toLowerCase()?n=a.math.mirrorPattern(n):"i"==l.toLowerCase()&&(n=a.math.inversePattern(n)),s--,g(n),("m"==l.toLowerCase()||"i"==l.toLowerCase())&&(l="")&&(j="")),"["!=j||o||(o=[]),"]"==j&&o){if(o=o.join("").toUpperCase(),a.is.piece(o)||a.is.pattern(o)){var b=a.is.piece(o)?"s_":a.is.pattern(o)?"p_":"",d=a.patterns[b+o];d&&g(a.parse.moves(d))}o=!1}o&&"["!=j?f(j):j&&a.is.move(j)&&(m="2"==l?c?"+":l:"+"==l||"-"==l?l:"i"==l||"'"==l?"-":"+",k=(e&&!o?j:a.clear.adjustCase(j))+m,c&&"2"==l&&f(k),f(k),o||e||j!=j.toLowerCase()||(k=!1,"u"==j?k="E"+m:"d"==j?k="E"+a.math.signInverse(m):"f"==j?k="S"+m:"b"==j?k="S"+a.math.signInverse(m):"l"==j?k="M"+m:"r"==j&&(k="M"+a.math.signInverse(m)),k&&f(k))),j=l}for(var i,j,k,l,m,n,o,p=[],q=a.clear.all(b).split(""),r=[],s=-1,t=0;t0&&c==e&&(i.pop(),d==f?"2"==d?h=!1:d="2":(d=a.math.signSum(f,d),d||(h=!1))),h&&i.push(c+d),e=0==i.length?"":i[i.length-1].charAt(0),f=0==i.length?"":i[i.length-1].charAt(1);return i},uncollapseSequence:function(a){var b,c,d,e=[];for(d=0;d0&&setTimeout(function(){f(b[j++]),j0||f>0||g>0?"+":0>e||0>f||0>g?"-":c;return h+i},rotatedPieces:function(a){var c={};if(a){var d,e,f,g=a.charAt(0),h=null;!h&&null!=b.pieces.axis[g]&&(h=b.pieces.pieces),!h&&null!=b.pieces.slices[g]&&(h=b.pieces.slices[g]),!h&&null!=b.pieces.faces[g]&&(h=b.pieces.faces[g]);for(d in h)h.hasOwnProperty(d)&&(e=b.service.targetOf(h[d]),f=this.orientedPiece(e,a),c[e]=b.service.getStickersFromPiece(f,this._currentCube,!0))}return c},orientedPiece:function(a,c){var d,e,f,g,h=this.axisRotation(c),i=b.pieces.axis[h.charAt(0)],j="-"==h.charAt(1)?-1:1,k=a.split(""),l=[];for(d=0;df?i.length-1:f>=i.length?0:f,l.push(i[f]));return l.join("")}},c}(jQuery,a);return b}(); \ No newline at end of file diff --git a/public/0.1.1/tools/RubikCubeIso-0.1.1.min.js b/public/0.1.1/tools/RubikCubeIso-0.1.1.min.js new file mode 100644 index 0000000..31f82b0 --- /dev/null +++ b/public/0.1.1/tools/RubikCubeIso-0.1.1.min.js @@ -0,0 +1,2 @@ +/*! RubikCubeIso - v0.1.1 - 2015-05-04 */ +var RubikCubeIso=function(){var a=function(){var a=function(){function a(){this._attributes={}}return a.prototype={set:function(a,b){return this._attributes[a]=b,this},get:function(a){return this._attributes[a]},_extend:function(a,b){if(b)for(var c in b)b.hasOwnProperty(c)&&(a[c]&&a[c]instanceof Object&&!(a[c]instanceof Array)?this._extend(a[c],b[c]):a[c]=b[c])}},a}(),b=function(){function a(a,b,c){this.x=parseFloat(a)||0,this.y=parseFloat(b)||0,this.z=parseFloat(c)||0}return a.prototype={toOrtho:function(){return new a(this.x-this.y,(this.x+this.y)/2-1.25*this.z,0)},toIso:function(){return new a(this.y+this.x/2,this.y-this.x/2,0)},toString:function(){return"{x:"+this.x+", y:"+this.y+", z:"+this.z+"}"},toObject:function(){return{x:this.x,y:this.y,z:this.z}},toArray:function(){return[this.x,this.y,this.z]},add:function(b){return new a(this.x+b.x,this.y+b.y,this.z+b.z)},subtract:function(b){return new a(this.x-b.x,this.y-b.y,this.z-b.z)},multiply:function(b){return new a(this.x*b.x,this.y*b.y,this.z*b.z)},distance:function(a){var b=Math.abs(this.x-a.x),c=Math.abs(this.y-a.y),d=Math.abs(this.z-a.z),e=Math.sqrt(Math.pow(b,2)+Math.pow(c,2));return Math.sqrt(Math.pow(e,2)+Math.pow(d,2))}},a}(),c=function(){function a(a){this._stepCallback=null,this._animation=null,this._startTime=0,a&&this.setCallback(a),window.requestAnimFrame=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(a){return window.setTimeout(a,1e3/60)}}(),window.cancelRequestAnimFrame=function(){return window.cancelAnimationFrame||window.cancelRequestAnimationFrame||window.webkitCancelRequestAnimationFrame||window.mozCancelRequestAnimationFrame||window.oCancelRequestAnimationFrame||window.msCancelRequestAnimationFrame||clearTimeout}()}return a.prototype={setCallback:function(a){this._stepCallback=a},start:function(a){this._startTime=(new Date).getTime(),this._animate(),a&&setTimeout(function(){this.stop()}.bind(this),a)},stop:function(){cancelRequestAnimFrame(this._animation),this._animation=null},_animate:function(){this._stepRender(),this._animation=requestAnimFrame(this._animate.bind(this))},_stepRender:function(){var a=(new Date).getTime()-this._startTime;this._stepCallback&&this._stepCallback(a)}},a}(),d=function(){function a(a){this.context=a,this.message=null,this.messageOrigin={x:0,y:0},this.isPath=!1,this.isStroke=!1}return a.prototype={setup:function(a){a||(a={});var b=null==a.fillColor?null:this.castToColor(a.fillColor),c=null==a.strokeColor?null:this.castToColor(a.strokeColor),d=a.strokeSize;this.context.restore(),this.context.fillStyle=b,this.context.strokeStyle=c,this.context.lineWidth=d,this.context.globalAlpha=a.alpha||1,this.context.font=a.font||"20px Open Sans",this.context.save(),this.isStroke=null!=c,this.isPath=null!=b,this.isPath&&this.context.beginPath()},render:function(){this.message&&(this.isPath&&this.context.fillText(this.message,this.messageOrigin.x,this.messageOrigin.y),this.isStroke&&this.context.strokeText(this.message,this.messageOrigin.x,this.messageOrigin.y),this.message=null),this.isPath&&this.context.closePath(),this.isPath&&this.context.fill(),this.isPath=!1,this.isStroke&&this.context.stroke(),this.isStroke=!1},moveTo:function(a,b){var c=this.isPath||this.isStroke;return c&&this.context.moveTo(a,b),c},lineTo:function(a,b){var c=this.isPath||this.isStroke;return c&&this.context.lineTo(a,b),c},text:function(a,b){if(!a)return[];b||(b=[0,0]),b=this.castToPoint(b),this.messageOrigin=b,this.message=a;var c=this.context.measureText(a),d=this.context.font,e=Math.ceil(c.width),f=parseInt(d);return isNaN(f)&&(d=d.substr(d.indexOf(" ")),f=parseInt(d)),[b.add([0,0]),b.add([e,0]),b.add([e,-f]),b.add([0,-f])]},line:function(a,b,c){return a&&b?(a=this.castToPoint(a),b=this.castToPoint(b),c&&(a=a.toOrtho(),b=b.toOrtho()),this.moveTo(a.x,a.y)&&this.lineTo(b.x,b.y)):!1},polygon:function(a,b,c){if(!a)return[];b||(b=[0,0,0]),b=this.castToPoint(b),a=a.map(function(a){return this.castToPoint(a)}.bind(this)),c&&(b=b.toOrtho()),c&&(a=a.map(function(a){return a.toOrtho()}));var d,e,f=b.add(a[0]),g=[];for(this.moveTo(f.x,f.y)&&g.push(f),d=1;d1&&a.length<4&&(c=new b(parseFloat(a[0]),parseFloat(a[1]),parseFloat(a[2]))),c}},a}(),e=function(a,b){function c(c){if(!c)throw new Error('no "name" provided for this displayObject:',this);if(a.call(this),this._name=c,this._parent=null,this._zIndex=0,this._position=new b,this._shape=null,this._info={stepCallback:null,renderMethod:null,renderInfo:null},this._options={strokeColor:0,fillColor:0,strokeSize:1,alpha:1,font:"14px Arial"},this[c])throw new Error('property "%s" already exists on',c,this)}return c.prototype=Object.create(a.prototype),c.prototype.setOptions=function(a){return a?(this._extend(this._options,a),!0):!1},c.prototype.setRenderInfo=function(a,b){b&&this.setOptions(b),this._info.renderInfo=a},c.prototype.setAnimationStep=function(a){this._info.stepCallback=a.bind(this)},c.prototype._addTo=function(a,b){this._zIndex=b||0,this._parent=a},c.prototype._remove=function(){delete this},c.prototype._render=function(a,b){if(!this._info.renderMethod)throw new Error("no renderMethod set for this instance of DisplayObject: ",this);return this._info.renderInfo?(a._info.draw.setup(this._options),this._shape=a._info.draw[this._info.renderMethod](this._info.renderInfo,this._position,b),a._info.draw.render(),!0):!1},c.prototype._step=function(a){return this._info.stepCallback&&this._info.stepCallback(a),!0},c}(a,b),f=function(a){function b(b){a.call(this,b),this._info.renderMethod="image"}return b.prototype=Object.create(a.prototype),b.prototype.render=function(){},b}(e),g=function(a){function b(b){a.call(this,b),this._options.font=this.getFont("Verdana",14),this._options.fillColor=0,this._options.strokeColor=null,this._info.renderMethod="text"}return b.prototype=Object.create(a.prototype),b.prototype.getFont=function(a,b,c){return a?(c||(c=""),b||(b=""),"number"==typeof b&&(b+="px"),[c,b,a].join(" ")):""},b.prototype.setFont=function(a,b,c){return a?(this._options.font=this.getFont(a,b,c),!0):!1},b}(e),h=function(a){function b(b){a.call(this,b),this._options.fillColor=null,this._options.strokeColor=0,this._info.renderMethod="polygon"}return b.prototype=Object.create(a.prototype),b}(e),i=function(a){function b(b){a.call(this,b),this._children={},this._childrenLength=function(){var a=0;return c(this,function(){a++}),a}.bind(this._children),this._childrenArray=function(){var a=[];return c(this,function(b){a.push(b)}),a.sort(function(a,b){return a._zIndex-b._zIndex})}.bind(this._children)}function c(a,b){if(a&&b)for(var c in a)a.hasOwnProperty(c)&&b(a[c])}return b.prototype=Object.create(a.prototype),b.prototype._render=function(a,b){this._childrenArray().forEach(function(c){c._render(a,b)})},b.prototype._step=function(b){return this._childrenArray().forEach(function(a){a._step(b)}),a.prototype._step.call(this,b),!0},b.prototype.addChild=function(b,c){if(!(b instanceof a))throw new Error("adding child with unsupported type:",typeof b);if(this[b._name])throw new Error('property "',b._name,'" already exists on',this);return c||(c=this._childrenLength()),this._children[b._name]=b,this[b._name]=b,b._addTo(this,c),this._reorderChildren(),b},b.prototype.removeChild=function(b){b instanceof String&&(b=this[b]),b&&this[b._name]&&this[b._name]instanceof a&&(delete this._children[b._name],delete this[b._name],b._remove())},b.prototype._reorderChildren=function(){this._childrenArray().forEach(function(a,b){a._info.index=b})},b.prototype._getShapes=function(){for(var a,c=[],d=0;d").addClass("iso-layer").css({position:"absolute",top:0,left:0}).append(this._info.canvas)}return e.prototype=Object.create(b.prototype),e.prototype._render=function(){this.clear(),b.prototype._render.call(this,this,this._info.mode==this._info.modes.ISOMETRIC)},e.prototype._remove=function(){this.$el.remove()},e.prototype._addTo=function(a){if(a){var b=a.worldSize();this.setSize(b.w,b.h),this.$el.appendTo(a.$el),this._engine=a}},e.prototype.toggleMode=function(a){this._info.modes[a]&&this.mode!=a&&(this.mode=a,this._render())},e.prototype.clear=function(){this._info.context.clearRect(-this._info.size.w/2,-this._info.size.h/2,this._info.size.w,this._info.size.h)},e.prototype.getCanvas=function(){return this._info.canvas},e.prototype.renderTime=function(a){this._step(a)&&this._render()},e.prototype.startAnimation=function(a){this._info.animator.start(a)},e.prototype.stopAnimation=function(){this._info.animator.stop()},e.prototype.setSize=function(a,b){this._info.size={w:a,h:b},this._info.canvas.width=a.toString(),this._info.canvas.height=b.toString(),this._info.context.translate(a/2,b/2)},e.prototype.setShadow=function(a,b,c,d){this._info.context.shadowColor=a||"#999",this._info.context.shadowBlur=b||20,this._info.context.shadowOffsetX=c||15,this._info.context.shadowOffsetY=d||c||15},e}(jQuery,i),k=function(a){function b(b){a.call(this,b)}return b.prototype=Object.create(a.prototype),b}(i),l=function(a,b){function c(){this.$el=a("
"),this.layers={},this.fpsInterval=null,this.fpsLogInterval=null,this.utils={worldSizeWidth:400,worldSizeHeight:400}}function d(a,b){for(var c=!1,d=-1,e=a.length,f=e-1;++d-1),c&&"string"==typeof c&&(d=!(1==c.length&&c==a.charAt(0))),c&&c instanceof Array&&(d=-1==c.indexOf(a)),d}},service:{targetOf:function(a){var c,d,e,f,g,h=a.toUpperCase();return null==b.pieces.cube[h]&&(c=h.indexOf("U"),d=h.indexOf("D"),e=h.indexOf("F"),f=h.indexOf("B"),g=c>-1?c:d>-1?d:e>-1?e:f>-1?f:null,g&&(h=h.substr(g)+h.substr(0,g))),h},moveCounter:function(a,b){var c=0;for(var d in a)a.hasOwnProperty(d)&&(c+=Number(a[d]==b));return c},cloneCube:function(a){var c,d={};for(c in b.pieces.cube)b.pieces.cube.hasOwnProperty(c)&&(d[c]=a&&a[c]?a[c]:b.pieces.cube[c]);return d},getPieceFromStickers:function(a,c){var d,e;for(d in c)if(c.hasOwnProperty(d)&&(c[d]==a||c[d]==b.service.rotate(a,-1)||c[d]==b.service.rotate(a,1)))return e=b.service.getRotation(c[d]),b.service.rotate(d,e);return!1},getStickersFromPiece:function(a,c,d){var e,f,g=b.service.targetOf(a),h=c[g],i=[];if(a==g||!d&&b.is.median(a))return h;for(e=0;e=1){-1==d.x.indexOf(a[0])?c=d.x:-1==d.y.indexOf(a[0])?c=d.y:-1==d.z.indexOf(a[0])&&(c=d.z);for(var g in e)e.hasOwnProperty(g)&&-1==c.indexOf(g)&&f.push(g)}if(a.length>=2){var h="U"==a[0]||"F"==a[0]||"L"==a[0]?1:"D"==a[0]||"B"==a[0]||"R"==a[0]?-1:0,i=c.indexOf(a[1]),j=i+2,k=i+h+2*h;j>=c.length&&(j-=c.length),k>=c.length&&(k-=c.length),0>k&&(k=c.length+k),f.push(a[1]),f.push(c[j]),f.push(c[k])}return 3==a.length&&f.push(a[2]),f}},math:{multiply:function(a,b){var c,d=[];for(c=0;b>c;c++)d=d.concat(a);return d},negative:function(a){var c,d,e=a;return b.canbe.negative(a)&&(c=a.charAt(0),d=1==a.length?"+":a.charAt(1),d=b.math.signInverse(d),e=c+d),e},inverse:function(a){var c=a;return b.canbe.negative(a)&&(c=b.math.negative(a)),c},mirror:function(a,c){c||(c="M");var d,e,f=a;return b.canbe.mirror(a)&&(d=a.charAt(0),d="M"==c?"L"==d?"R":"R"==d?"L":d:d,d="E"==c?"U"==d?"D":"D"==d?"U":d:d,d="S"==c?"F"==d?"B":"B"==d?"F":d:d,e=1==a.length?"+":a.charAt(1),f=b.math.negative(d+e)),f},negativePattern:function(a,c,d){var e,f=[];for(e=0;e=0?r[s]:p).push(a)}function g(a){s>-1?r[s]=r[s].concat(a):p=p.concat(a)}function h(){if("("==j&&(r[++s]=[]),")"==j&&(n=r[s],l==Number(l)?n=b.math.multiply(n,Number(l)):"-"==l||"'"==l?n=b.math.negativePattern(n):"m"==l.toLowerCase()?n=b.math.mirrorPattern(n):"i"==l.toLowerCase()&&(n=b.math.inversePattern(n)),s--,g(n),("m"==l.toLowerCase()||"i"==l.toLowerCase())&&(l="")&&(j="")),"["!=j||o||(o=[]),"]"==j&&o){if(o=o.join("").toUpperCase(),b.is.piece(o)||b.is.pattern(o)){var a=b.is.piece(o)?"s_":b.is.pattern(o)?"p_":"",d=b.patterns[a+o];d&&g(b.parse.moves(d))}o=!1}o&&"["!=j?f(j):j&&b.is.move(j)&&(m="2"==l?c?"+":l:"+"==l||"-"==l?l:"i"==l||"'"==l?"-":"+",k=(e&&!o?j:b.clear.adjustCase(j))+m,c&&"2"==l&&f(k),f(k),o||e||j!=j.toLowerCase()||(k=!1,"u"==j?k="E"+m:"d"==j?k="E"+b.math.signInverse(m):"f"==j?k="S"+m:"b"==j?k="S"+b.math.signInverse(m):"l"==j?k="M"+m:"r"==j&&(k="M"+b.math.signInverse(m)),k&&f(k))),j=l}for(var i,j,k,l,m,n,o,p=[],q=b.clear.all(a).split(""),r=[],s=-1,t=0;t0&&c==e&&(i.pop(),d==f?"2"==d?h=!1:d="2":(d=b.math.signSum(f,d),d||(h=!1))),h&&i.push(c+d),e=0==i.length?"":i[i.length-1].charAt(0),f=0==i.length?"":i[i.length-1].charAt(1);return i},uncollapseSequence:function(a){var b,c,d,e=[];for(d=0;d0&&setTimeout(function(){f(b[j++]),j0||f>0||g>0?"+":0>e||0>f||0>g?"-":c;return h+i},rotatedPieces:function(a){var c={};if(a){var d,e,f,g=a.charAt(0),h=null;!h&&null!=b.pieces.axis[g]&&(h=b.pieces.pieces),!h&&null!=b.pieces.slices[g]&&(h=b.pieces.slices[g]),!h&&null!=b.pieces.faces[g]&&(h=b.pieces.faces[g]);for(d in h)h.hasOwnProperty(d)&&(e=b.service.targetOf(h[d]),f=this.orientedPiece(e,a),c[e]=b.service.getStickersFromPiece(f,this._currentCube,!0))}return c},orientedPiece:function(a,c){var d,e,f,g,h=this.axisRotation(c),i=b.pieces.axis[h.charAt(0)],j="-"==h.charAt(1)?-1:1,k=a.split(""),l=[];for(d=0;df?i.length-1:f>=i.length?0:f,l.push(i[f]));return l.join("")}},c}(jQuery,b),d=function(a,b,c){function d(a,c){b.call(this,a,c),this._renderOptions={order:["DBL","DB","DRB","DL","D","DR","DLF","DF","DFR","BL","B","BR","L","R","FL","F","FR","ULB","UB","UBR","UL","U","UR","UFL","UF","URF"],backfaces:!1,highlights:[],highlightColored:!1},this.iso={container:this.$el,engine:new l},this.iso.engine.init(this.iso.container,{worldSizeWidth:400,worldSizeHeight:300}),this.iso.layer=this.iso.engine.addLayer("cube",!0),this.iso.console=this.iso.engine.addLayer("console");var d=this.iso.console.addChild(new p("cubeletInfo"));d._position=new m(-200,120),d.setFont("Open Sans",20),this.render()}function e(a){this._renderOptions.backfaces=null!=a?a:!this._renderOptions.backfaces,this.render()}function f(b){var c=[];b&&b.forEach(function(b){c.push(a.service.targetOf(b))}.bind(this)),this._renderOptions.highlights=c,this.render()}function g(b,c,d,e){c||(c=b);for(var f,g,j=this._options.pieceSize,k=new m(-j/2,-j/2,-j/2),l=[],n=[b.indexOf("U"),b.indexOf("R"),b.indexOf("F"),b.indexOf("D"),b.indexOf("B"),b.indexOf("L")],o=0;o=3)&&(g={name:f,color:f?d?a.colors[c]:a.colors[f]:null}),l.push(g);var p=-1!=b.indexOf("D")?-1:-1!=b.indexOf("U")?1:0,q=-1!=b.indexOf("F")?1:-1!=b.indexOf("B")?-1:0,r=-1!=b.indexOf("L")?-1:-1!=b.indexOf("R")?1:0,s=!0;this.iso.layer._children["_piece_"+b]||h.call(this,b,k.add(new m(j*r,j*q,j*p)),j,s),i.call(this,b,c,j,{fills:l,stroke:a.colors.core},s)}function h(a,b,c,d){var e=new n("_piece_"+a);e.set("position",a),d&&(e.addChild(new o("_face_D")).set("position","D")._position=b.add(new m(0,0,0)),e.addChild(new o("_face_B")).set("position","B")._position=b.add(new m(0,0,0)),e.addChild(new o("_face_L")).set("position","L")._position=b.add(new m(0,0,0))),e.addChild(new o("_face_U")).set("position","U")._position=b.add(new m(0,0,c)),e.addChild(new o("_face_R")).set("position","R")._position=b.add(new m(c,0,0)),e.addChild(new o("_face_F")).set("position","F")._position=b.add(new m(0,c,0)),this.iso.layer.addChild(e)}function i(a,b,c,d,e){var f=this.iso.layer._children["_piece_"+a];if(f){f.set("sticker",b);var g=d.fills.map(function(a){return a&&a.name}),h={fills:d.fills.map(function(a){return a&&a.color}),color:d.stroke};e&&h.fills&&6==h.fills.length&&(j.call(this,f._children._face_D,k(g,3),"get3DPolygonSquare",c,h.fills?k(h.fills,3):null,h.color),j.call(this,f._children._face_B,k(g,4),"get3DPolygonSquareLeft",c,h.fills?k(h.fills,4):null,h.color),j.call(this,f._children._face_L,k(g,5),"get3DPolygonSquareRight",c,h.fills?k(h.fills,5):null,h.color)),j.call(this,f._children._face_U,k(g,0),"get3DPolygonSquare",c,h.fills?k(h.fills,0):null,h.color),j.call(this,f._children._face_R,k(g,1),"get3DPolygonSquareRight",c,h.fills?k(h.fills,1):null,h.color),j.call(this,f._children._face_F,k(g,2),"get3DPolygonSquareLeft",c,h.fills?k(h.fills,2):null,h.color)}}function j(a,b,c,d,e,f){e?a.setRenderInfo(this.iso.engine.drawUtils[c](d),{strokeColor:null==e?null:f,fillColor:e,strokeSize:1}):a.setRenderInfo(null),a.set("sticker",b)}function k(a,b){return a.length>b?a[b]:a[a.length-1]}var l=c.core.Engine,m=c.core.Point,n=c.display.Sprite,o=c.display.Shape,p=c.display.Text;return d.prototype=Object.create(b.prototype),d.prototype.willRender=function(){},d.prototype.didRender=function(){this.iso.layer._render(),this._options.showAxis&&this.iso.engine.drawUtils.axis(this.iso.layer,200)},d.prototype.render=function(a){var b,c=this._renderOptions.highlights,d=this._renderOptions.highlightColored;return this.willRender(),this._renderOptions.order.forEach(function(e){0==c.length?(b=this._currentCube[e],(!a||a.indexOf(e)>-1)&&g.call(this,e,b,!1,this._renderOptions.backfaces)):(b=c.indexOf(e)>-1?d?this._currentCube[e]:"light":"grey",g.call(this,e,b,"grey"==b||"light"==b,this._renderOptions.backfaces))}.bind(this)),this.didRender(),!0},d.prototype.getImage=function(){return this.iso.layer.getCanvas().toDataURL()},d.prototype.backfaceState=function(){return this._renderOptions.backfaces},d.prototype.backfaceToggle=function(a){e.call(this,a)},d.prototype.highlight=function(a){f.call(this,a)},d.prototype.highlightColor=function(a){this._renderOptions.highlightColored=a,this.render()},d}(b,c,a);return d}(); \ No newline at end of file diff --git a/public/0.1.1/tools/RubikSolver-0.1.1.min.js b/public/0.1.1/tools/RubikSolver-0.1.1.min.js new file mode 100644 index 0000000..aed5cf6 --- /dev/null +++ b/public/0.1.1/tools/RubikSolver-0.1.1.min.js @@ -0,0 +1,2 @@ +/*! RubikSolver - v0.1.1 - 2015-05-04 */ +var RubikSolver=function(){var a=function(){return{colors:{U:"#ffff00",D:"#ffffff",F:"#ff0000",B:"#ffaa00",L:"#0000ff",R:"#008800",light:"#ffff00",grey:"#cccccc",core:"#222222"},patterns:{p_O4U:" (M'U)4 (MU)4 ",p_O4D:" (M'D)4 (MD)4 ",p_O4F:" (M'F)4 (MF)4 ",p_O4B:" (M'B)4 (MB)4 ",p_O2U:" (M'U)3 U (MU)3 U ",p_O2D:" (M'D)3 D (MD)3 D ",p_O2F:" (M'F)3 F (MF)3 F ",p_O2B:" (M'B)3 B (MB)3 B ",p_O6L:" (R'FRU)5 ",p_O6R:" ([O6L])m ",p_CW2:" (U'RU) R' (U'RU) ",p_CC2:" ([CW2])i ",p_CW3:" ((UR)'UR)2 ",p_CC3:" ([CW3])i ",p_PTJ:" (L'U2) LU (L'U2) (RU') L (RU')i ",p_PTN:" ((L'UR') U2 (L'UR')')2 U ",p_PAR:" (U'F2) [PTJ] (U'F2)i ",p_PRN:" (F2y) [PTN] (F2y)i",s_UB:" ",s_UF:" (U2 M')2 ",s_DB:" ([UF])i ",s_UR:" R'U RU' ",s_DR:" U R RU' ",s_FR:" URU' ",s_BR:" ([FR])i ",s_UL:" ([UR])m ",s_DL:" ([DR])m ",s_FL:" ([FR])m ",s_BL:" ([BR])m ",s_BU:" [UB] ",s_FU:" [UF] ",s_BD:" [DB] ",s_RU:" x' ([BR])' ",s_RD:" x' ([FR])' ",s_RF:" x' ([DR])' ",s_RB:" x' ([UR])' ",s_LU:" x' (([BR])')m ",s_LD:" x' (([FR])')m ",s_LF:" x' (([DR])')m ",s_LB:" x' (([UR])')m ",s_UBR:" ",s_URF:" U' (R F' RM' U R2 U') (MR' F R U R2') ",s_DRB:" ([URF])i ",s_ULB:" (LU)' (LU)",s_UFL:" L U'L' U [ULB] ",s_DLF:" U' L2 U ",s_DBL:" [DLF] [ULB] ",s_BRU:" (U'L'U) L (U'L'U) ",s_RUB:" ([BRU])i ",s_RFU:" (F'R) (UR2U') R' (FR) (UR2U') R ",s_FUR:" R2 U' RM'x L2M2 (ULU') R' (UL'U') L'R'U ",s_RBD:" R'UR2U'R'F'RUR2U'R'F ",s_BDR:" RUR' DL2 x2 U'RU L2x2 U'D'R ",s_LBU:" (U'L'U) ",s_BUL:" y RUR2U'R' y' ",s_FLU:" R' (ULU') ",s_LUF:" L' (U'L'U) ",s_LFD:" L2 (U'L'U) ",s_FDL:" (U'L'U) L' (U'LU)",s_BLD:" (U'LU) ",s_LDB:" L (U'L'U) "},pieces:{M2:["M2"],R2:["R2"],opposites:{buffers:{edges:["DF","FD","UB","BU"],corners:["DFR","RDF","FRD","UBR","RUB","BRU"]},normals:{edges:["UF","FU","DB","BD"],corners:["URF","FUR","RFU","DRB","BDR","RBD"]}},buffers:{edge:"DF",corner:"DFR"},cube:{U:"U",D:"D",F:"F",B:"B",L:"L",R:"R",DF:"DF",DR:"DR",DB:"DB",DL:"DL",UF:"UF",UR:"UR",UB:"UB",UL:"UL",FR:"FR",BR:"BR",FL:"FL",BL:"BL",DFR:"DFR",DRB:"DRB",DBL:"DBL",DLF:"DLF",URF:"URF",UBR:"UBR",ULB:"ULB",UFL:"UFL"},pieces:["U","D","F","B","L","R","DF","DR","DB","DL","UF","UR","UB","UL","FR","BR","FL","BL","DFR","DRB","DBL","DLF","URF","UBR","ULB","UFL"],faces:{U:["ULB","UB","UBR","UL","U","UR","UFL","UF","URF"],D:["DLF","DF","DFR","DL","D","DR","DBL","DB","DRB"],F:["FLU","FU","FUR","FL","F","FR","FDL","FD","FRD"],B:["BRU","BU","BUL","BR","B","BL","BDR","BD","BLD"],L:["LBU","LU","LUF","LB","L","LF","LDB","LD","LFD"],R:["RFU","RU","RUB","RF","R","RB","RDF","RD","RBD"]},slices:{M:["F","U","B","D","UF","UB","DB","DF"],E:["F","R","B","L","FL","FR","BL","BR"],S:["U","R","D","L","UL","UR","DR","DL"]},axis:{x:["U","F","D","B"],y:["F","L","B","R"],z:["U","R","D","L"]},noUnsetup:["UF","DB","FU","BD","DRB","RBD","BDR","URF","RFU","FUR"]},is:{face:function(a){return/^[udfblr]$/i.test(a)},slice:function(a){return/^[mes]$/i.test(a)},axis:function(a){return/^[xyz]$/i.test(a)},move:function(b){return a.is.face(b)||a.is.slice(b)||a.is.axis(b)},modifier:function(a){return/^[2i'\-\+]$/.test(a)},rotation:function(a){return/^[udfblrmesxyz][2i'\-\+]?$/i.test(a)},median:function(a){return/^([ud][fb]|[fb][ud])$/i.test(a)},pattern:function(a){return/^(o[24][udfb]|o6[lr]|c[cw][23]|pt[jn]|par|prn)$/i.test(a)},piece:function(a){return/^(?:([udfblr])(?!.*\1)){2,3}$/i.test(a)},edge:function(b){return 2==b.length&&a.is.piece(b)},corner:function(b){return 3==b.length&&a.is.piece(b)},buffer:function(b){return a.is.edge(b)&&a.service.targetOf(b)==a.pieces.buffers.edge||a.is.corner(b)&&a.service.targetOf(b)==a.pieces.buffers.corner}},canbe:{negative:function(a){return 1==a.length||"+"==a.charAt(1)||"-"==a.charAt(1)},mirror:function(b){return a.canbe.negative(b)||"2"==b.charAt(1)},accepted:function(a,b,c){var d=!b&&!c||""==b&&""==c;return b&&"string"==typeof b&&(d=1==b.length&&b==a.charAt(0)),b&&b instanceof Array&&(d=b.indexOf(a)>-1),c&&"string"==typeof c&&(d=!(1==c.length&&c==a.charAt(0))),c&&c instanceof Array&&(d=-1==c.indexOf(a)),d}},service:{targetOf:function(b){var c,d,e,f,g,h=b.toUpperCase();return null==a.pieces.cube[h]&&(c=h.indexOf("U"),d=h.indexOf("D"),e=h.indexOf("F"),f=h.indexOf("B"),g=c>-1?c:d>-1?d:e>-1?e:f>-1?f:null,g&&(h=h.substr(g)+h.substr(0,g))),h},moveCounter:function(a,b){var c=0;for(var d in a)a.hasOwnProperty(d)&&(c+=Number(a[d]==b));return c},cloneCube:function(b){var c,d={};for(c in a.pieces.cube)a.pieces.cube.hasOwnProperty(c)&&(d[c]=b&&b[c]?b[c]:a.pieces.cube[c]);return d},getPieceFromStickers:function(b,c){var d,e;for(d in c)if(c.hasOwnProperty(d)&&(c[d]==b||c[d]==a.service.rotate(b,-1)||c[d]==a.service.rotate(b,1)))return e=a.service.getRotation(c[d]),a.service.rotate(d,e);return!1},getStickersFromPiece:function(b,c,d){var e,f,g=a.service.targetOf(b),h=c[g],i=[];if(b==g||!d&&a.is.median(b))return h;for(e=0;e=1){-1==d.x.indexOf(b[0])?c=d.x:-1==d.y.indexOf(b[0])?c=d.y:-1==d.z.indexOf(b[0])&&(c=d.z);for(var g in e)e.hasOwnProperty(g)&&-1==c.indexOf(g)&&f.push(g)}if(b.length>=2){var h="U"==b[0]||"F"==b[0]||"L"==b[0]?1:"D"==b[0]||"B"==b[0]||"R"==b[0]?-1:0,i=c.indexOf(b[1]),j=i+2,k=i+h+2*h;j>=c.length&&(j-=c.length),k>=c.length&&(k-=c.length),0>k&&(k=c.length+k),f.push(b[1]),f.push(c[j]),f.push(c[k])}return 3==b.length&&f.push(b[2]),f}},math:{multiply:function(a,b){var c,d=[];for(c=0;b>c;c++)d=d.concat(a);return d},negative:function(b){var c,d,e=b;return a.canbe.negative(b)&&(c=b.charAt(0),d=1==b.length?"+":b.charAt(1),d=a.math.signInverse(d),e=c+d),e},inverse:function(b){var c=b;return a.canbe.negative(b)&&(c=a.math.negative(b)),c},mirror:function(b,c){c||(c="M");var d,e,f=b;return a.canbe.mirror(b)&&(d=b.charAt(0),d="M"==c?"L"==d?"R":"R"==d?"L":d:d,d="E"==c?"U"==d?"D":"D"==d?"U":d:d,d="S"==c?"F"==d?"B":"B"==d?"F":d:d,e=1==b.length?"+":b.charAt(1),f=a.math.negative(d+e)),f},negativePattern:function(b,c,d){var e,f=[];for(e=0;e=0?r[s]:p).push(a)}function g(a){s>-1?r[s]=r[s].concat(a):p=p.concat(a)}function h(){if("("==j&&(r[++s]=[]),")"==j&&(n=r[s],l==Number(l)?n=a.math.multiply(n,Number(l)):"-"==l||"'"==l?n=a.math.negativePattern(n):"m"==l.toLowerCase()?n=a.math.mirrorPattern(n):"i"==l.toLowerCase()&&(n=a.math.inversePattern(n)),s--,g(n),("m"==l.toLowerCase()||"i"==l.toLowerCase())&&(l="")&&(j="")),"["!=j||o||(o=[]),"]"==j&&o){if(o=o.join("").toUpperCase(),a.is.piece(o)||a.is.pattern(o)){var b=a.is.piece(o)?"s_":a.is.pattern(o)?"p_":"",d=a.patterns[b+o];d&&g(a.parse.moves(d))}o=!1}o&&"["!=j?f(j):j&&a.is.move(j)&&(m="2"==l?c?"+":l:"+"==l||"-"==l?l:"i"==l||"'"==l?"-":"+",k=(e&&!o?j:a.clear.adjustCase(j))+m,c&&"2"==l&&f(k),f(k),o||e||j!=j.toLowerCase()||(k=!1,"u"==j?k="E"+m:"d"==j?k="E"+a.math.signInverse(m):"f"==j?k="S"+m:"b"==j?k="S"+a.math.signInverse(m):"l"==j?k="M"+m:"r"==j&&(k="M"+a.math.signInverse(m)),k&&f(k))),j=l}for(var i,j,k,l,m,n,o,p=[],q=a.clear.all(b).split(""),r=[],s=-1,t=0;t0&&c==e&&(i.pop(),d==f?"2"==d?h=!1:d="2":(d=a.math.signSum(f,d),d||(h=!1))),h&&i.push(c+d),e=0==i.length?"":i[i.length-1].charAt(0),f=0==i.length?"":i[i.length-1].charAt(1);return i},uncollapseSequence:function(a){var b,c,d,e=[];for(d=0;da.expand.piece(i,!0).length),h&&(e?k.push(i):k=i)}return k},opposite:function(c,d){var e=d?"buffers":"normals",f=a.pieces.opposites[e].edges.indexOf(c),g=a.pieces.opposites[e].corners.indexOf(c),h=[c],i=0;return f>-1&&(i=f+2,h=a.pieces.opposites[e].edges),g>-1&&(i=g+3,h=a.pieces.opposites[e].corners),i>=h.length&&(i-=h.length),f>-1&&(d||b.explainCallback("PIECES_CYCLE_OPPOSITE_MEDIAN_EDGES",[c,h[i]])),g>-1&&(d||b.explainCallback("PIECES_CYCLE_OPPOSITE_RIGHT_CORNERS",[c,h[i]])),h[i]}},solve:{explain:function(a){return b.explainArray=[],b.solveArray=b.solve.full(a,0),{s:b.solveArray,e:b.explainArray}},full:function(c,d){if((!d||0>d||d>3)&&(d=0),!b.check.orientedCube(c))return[];if(!b.check.correctPieces(c))return[];b.explainCallback("BEGIN");var e=b.solve.edgesUnoriented(c);e=e.concat(b.solve.pieces(c,a.pieces.buffers.edge,a.pieces.M2));var f=b.solve.pieces(c,a.pieces.buffers.corner,a.pieces.R2),g=Boolean(a.service.moveCounter(e,a.pieces.M2)%2),h=Boolean(a.service.moveCounter(f,a.pieces.R2)%2);g!=h&&console.warn("WARNING: this case is not handled!! parity happened only on edges or corners..",c);var i=e.concat(f);b.explainCallback("END",[i.toString()]);var j=a.expand.pattern(i),k=a.clear.collapseSequence(j),l=a.clear.uncollapseSequence(j),m=a.math.inversePattern(k);return 0==d?i:1==d?l:2==d?k:3==d?m:[]},pieces:function(c,d,e){function f(e,f,g){var h=a.service.targetOf(e);if(a.is.median(e)&&(g||h!=d)){var i=a.service.getPieceFromStickers(e,c);b.explainCallback("PIECES_EDGES_BEGIN",e);var j=i!=a.service.targetOf(i);j||b.explainCallback("PIECES_EDGES_FLIPPED_STATE",[e,j]);var k=f&&a.service.getRotation(f)&&!a.is.median(f);k&&(j=!j),g&&(j=r),k&&b.explainCallback("PIECES_EDGES_PREVIOUS_FLIPPED",[e,f]),g&&r&&b.explainCallback("PIECES_EDGES_BUFFER_FLIPPED",e),j&&-1==n.indexOf(h)&&(n.push(h),b.explainCallback("PIECES_EDGES_ADD_TO_FLIPPED",[e,n.toString()])),b.explainCallback("END_VOID")}}function g(c){var d=q?b.service.opposite(j):j;c?(u=h,b.explainCallback("MEMORIZE_PLACEHOLDER",h)):b.explainCallback("MEMORIZE_PIECE",d),m.push(d),k=a.service.getStickersFromPiece(j,i),q=!q,i[h]=h,j!=k&&(b.explainCallback("PIECES_CYCLE_CHECK_NEXT_PIECE",[j,k]),o&&f.call(this,k,j))}var h,i=a.service.cloneCube(c),j=d,k=i[d],l=!k,m=[],n=[],o=a.is.edge(d),p=a.is.corner(d);b.explainCallback("PIECES_BEGIN",(o?"edges":p?"corners":"").toUpperCase());var q=!1,r=!1,s=!1,t=!1,u=!1;for(b.explainCallback("PIECES_CYCLE_BEGIN"),b.explainCallback("PIECES_CYCLE_EXAMINE_BUFFER",d),b.explainCallback("PIECES_CYCLE_CHECK_BUFFER_POSITION",k),o&&f.call(this,k),b.explainCallback("END_VOID");!l;){if(b.explainCallback("PIECES_CYCLE_EXAMINE_PIECE",k),j=k,h=a.service.targetOf(j),t=a.is.buffer(j),t&&b.explainCallback("PIECES_CYCLE_BUFFER_FOUND",[j,j!=h]),r=t?j!=h:h!=u||j==h||a.is.median(j)?r:!r,t||h!=u||(u=!1,t=!0,b.explainCallback("PIECES_CYCLE_PLACEHOLDER_FOUND",[j,j!=h&&!a.is.median(j)]),o&&j!=h&&b.explainCallback("PIECES_CYCLE_EDGE_IS_FLIPPED",[j,a.is.median(j)]),g.call(this)),t)if(s=b.service.freeTarget(i,j.length),b.explainCallback("PIECES_CYCLE_CHECK_FREE_TARGET",s.toString()),s!==!1)j=s,h=s,g.call(this,!0);else{if(b.explainCallback("PIECES_CYCLE_ALL_IS_OK"),o&&f.call(this,d,!1,!0),q){if(b.explainCallback("PIECES_PARITY_BEGIN"),b.explainCallback("MEMORIZE_MIDDLE",[o?"M-slice":"R-face",e]),m=m.concat(e),o){if(n.length>0){for(var v in n)n[v]=b.service.opposite(n[v],!0);b.explainCallback("PIECES_PARITY_SWITCH_FLIPPED_MEDIANS",n.toString())}}else b.explainCallback("MEMORIZE_PARITY","PAR"),m=m.concat(["PAR"]);b.explainCallback("END_VOID")}if(o){var w=b.solve.mEdgesUnoriented(n);m=m.concat(w),w.length>0&&b.explainCallback("MEMORIZE_ORIENT_EDGES",w.toString())}l=!0}else g.call(this);b.explainCallback("END_VOID")}return b.explainCallback("END_VOID"),b.explainCallback("PIECES_END",[(o?"edges":p?"corners":"").toUpperCase(),m.toString()]),m},edgesUnoriented:function(){b.explainCallback("UNORIENTED_BEGIN");var a=[];return b.explainCallback("UNORIENTED_WIP"),b.explainCallback("UNORIENTED_END",[a.toString()]),a},mEdgesUnoriented:function(a){var b,c,d,e,f,g,h=[];return(1==a.length||3==a.length||a.length>4)&&console.error("ERROR: wrong array of flipped M-edges: ",a),4==a.length&&(h=["O2U","O2D"]),2==a.length&&(d=a[0].charAt(0),e=a[0].charAt(1),a[1].indexOf(d)>-1&&(c=d),a[1].indexOf(e)>-1&&(c=e),c?h=["O2"+c]:(f=a[0].indexOf("D"),g=a[1].indexOf("D"),f>-1&&(b=Number(!f),c=a[0].charAt(b)),g>-1&&(b=Number(!g),c=a[1].charAt(b)),c&&(h=[c+"2","O2U",c+"2"]))),h}}}}(a);return b}(); \ No newline at end of file diff --git a/public/0.1.1/tools/RubikTeacher-0.1.1.min.js b/public/0.1.1/tools/RubikTeacher-0.1.1.min.js new file mode 100644 index 0000000..4aea61c --- /dev/null +++ b/public/0.1.1/tools/RubikTeacher-0.1.1.min.js @@ -0,0 +1,2 @@ +/*! RubikTeacher - v0.1.1 - 2015-05-04 */ +var RubikTeacher=function(){var a=function(){var a={TITLE:{p:0,g:0,m:"* SOLVE PROCESS *"},BEGIN:{p:0,g:1,m:"begin memorizing"},END:{p:0,g:-1,m:"end memorizing [%s]"},BEGIN_VOID:{p:3,g:1,m:""},END_VOID:{p:3,g:-1,m:""},UNORIENTED_BEGIN:{p:3,g:1,m:"solve unoriented edges"},UNORIENTED_END:{p:3,g:-1,m:"unoriented pieces: [%s]"},UNORIENTED_WIP:{p:3,g:0,m:"method not yet implemented. will return an empty array."},PIECES_BEGIN:{p:3,g:1,m:"solve unpermuted/unoriented %s"},PIECES_END:{p:1,g:-1,m:"done with %s: [%s]"},PIECES_CYCLE_BEGIN:{p:3,g:1,m:"piece-finding cycle"},PIECES_CYCLE_EXAMINE_BUFFER:{p:3,g:1,m:"examine the buffer [%s]"},PIECES_CYCLE_EXAMINE_PIECE:{p:3,g:1,m:"examine the piece [%s]"},PIECES_CYCLE_CHECK_BUFFER:{p:1,g:0,m:"first thing first: examine the buffer piece: [%s]"},PIECES_CYCLE_BUFFER_FOUND:{p:2,g:0,m:"the piece [%s] is the buffer - flipState: %s"},PIECES_CYCLE_PLACEHOLDER_FOUND:{p:2,g:0,m:"the piece in [%s] position is the buffer - should invert flipState? %s"},PIECES_CYCLE_CHECK_FREE_TARGET:{p:1,g:0,m:"check for the first target to be solved: [%s]"},PIECES_CYCLE_ALL_IS_OK:{p:2,g:0,m:"all pieces are correctly permuted"},PIECES_CYCLE_CHECK_BUFFER_FLIP:{p:1,g:0,m:"check if edge buffer is flipped after all iterations"},PIECES_CYCLE_EDGE_IS_FLIPPED:{p:2,g:0,m:"note that the edge [%s] is flipped - is median? %s"},PIECES_CYCLE_BUFFER_FLIP_STATE:{p:1,g:0,m:"remember to %s the flip state of buffer piece when edges are finished"},PIECES_CYCLE_OPPOSITE_MEDIAN_EDGES:{p:2,g:0,m:"the M-slice is rotated, so switch DB with UF or viceversa: [%s] -> [%s]"},PIECES_CYCLE_OPPOSITE_RIGHT_CORNERS:{p:2,g:0,m:"the R-face is rotated, so switch DRB with URF or viceversa: [%s] -> [%s]"},PIECES_CYCLE_CHECK_NEXT_PIECE:{p:2,g:0,m:"look at the piece in [%s] position: [%s]"},PIECES_CYCLE_CHECK_BUFFER_POSITION:{p:2,g:0,m:"look at the piece in buffer position: [%s]"},PIECES_EDGES_BEGIN:{p:3,g:1,m:"check for flipped median edge [%s]"},PIECES_EDGES_FLIPPED_STATE:{p:2,g:0,m:"flipped state of piece [%s] : %s"},PIECES_EDGES_PREVIOUS_FLIPPED:{p:1,g:0,m:"invert flipped state of [%s] because previous piece [%s] was unoriented"},PIECES_EDGES_BUFFER_FLIPPED:{p:2,g:0,m:"invert flipped state of buffer [%s]"},PIECES_EDGES_ADD_TO_FLIPPED:{p:1,g:0,m:"edge [%s] is flipped, add it to the flipped edge list: [%s]"},PIECES_EDGES_DONT_CHECK_BUFFER:{p:2,g:0,m:"is not the time to check the buffer [%s] flip state"},PIECES_EDGES_IS_MEDIAN:{p:2,g:0,m:"the piece [%s] is part of median slice"},PIECES_EDGES_CHECK_ONLY_MEDIAN:{p:2,g:0,m:"the piece [%s] is not part of median slice"},PIECES_PARITY_BEGIN:{p:3,g:1,m:"parity occurred!"},PIECES_PARITY_SWITCH_FLIPPED_MEDIANS:{p:2,g:0,m:"switch DF with UB and viceversa in the list of flipped edges: [%s]"},MEMORIZE_MIDDLE:{p:0,g:0,m:"** the %s is rotated, for now rotate it back with [%s]"},MEMORIZE_PARITY:{p:0,g:0,m:"** finally do the parity pattern: [%s]"},MEMORIZE_PIECE:{p:0,g:0,m:"** memorize the piece: [%s]"},MEMORIZE_PLACEHOLDER:{p:0,g:0,m:"** memorize the buffer placeholder position: [%s]"},MEMORIZE_ORIENT_EDGES:{p:0,g:0,m:"** memorize the sequence for correctly orient the median edges: [%s]"}};return{constants:a,explain:function(a,b){var c=0,d=0,e=a,f=this.constants[a];f&&(c=f.p,d=f.g,e=f.m);var g,h,i;if(e){if(g=e,b)if("string"==typeof b)g=e.replace(/%s/g,b);else{i=e.split("%s");for(h in i)i.hasOwnProperty(h)&&null!=b[h]&&(i[h]=i[h]+b[h]);g=i.join("")}}else d=-1;return{m:g,g:d,p:c}},explainAll:function(a,b){for(var c,d=[],e=0;e=c)){var d=!0,e=d?console.groupCollapsed:console.group;b>0&&a&&e(a),0>=b&&a&&console.log(a),0>b&&console.groupEnd()}}}}();return a}(); \ No newline at end of file diff --git a/public/0.1.1/tools/RubikUtils-0.1.1.min.js b/public/0.1.1/tools/RubikUtils-0.1.1.min.js new file mode 100644 index 0000000..e056615 --- /dev/null +++ b/public/0.1.1/tools/RubikUtils-0.1.1.min.js @@ -0,0 +1,2 @@ +/*! RubikUtils - v0.1.1 - 2015-05-04 */ +var RubikUtils=function(){var a=function(){return{colors:{U:"#ffff00",D:"#ffffff",F:"#ff0000",B:"#ffaa00",L:"#0000ff",R:"#008800",light:"#ffff00",grey:"#cccccc",core:"#222222"},patterns:{p_O4U:" (M'U)4 (MU)4 ",p_O4D:" (M'D)4 (MD)4 ",p_O4F:" (M'F)4 (MF)4 ",p_O4B:" (M'B)4 (MB)4 ",p_O2U:" (M'U)3 U (MU)3 U ",p_O2D:" (M'D)3 D (MD)3 D ",p_O2F:" (M'F)3 F (MF)3 F ",p_O2B:" (M'B)3 B (MB)3 B ",p_O6L:" (R'FRU)5 ",p_O6R:" ([O6L])m ",p_CW2:" (U'RU) R' (U'RU) ",p_CC2:" ([CW2])i ",p_CW3:" ((UR)'UR)2 ",p_CC3:" ([CW3])i ",p_PTJ:" (L'U2) LU (L'U2) (RU') L (RU')i ",p_PTN:" ((L'UR') U2 (L'UR')')2 U ",p_PAR:" (U'F2) [PTJ] (U'F2)i ",p_PRN:" (F2y) [PTN] (F2y)i",s_UB:" ",s_UF:" (U2 M')2 ",s_DB:" ([UF])i ",s_UR:" R'U RU' ",s_DR:" U R RU' ",s_FR:" URU' ",s_BR:" ([FR])i ",s_UL:" ([UR])m ",s_DL:" ([DR])m ",s_FL:" ([FR])m ",s_BL:" ([BR])m ",s_BU:" [UB] ",s_FU:" [UF] ",s_BD:" [DB] ",s_RU:" x' ([BR])' ",s_RD:" x' ([FR])' ",s_RF:" x' ([DR])' ",s_RB:" x' ([UR])' ",s_LU:" x' (([BR])')m ",s_LD:" x' (([FR])')m ",s_LF:" x' (([DR])')m ",s_LB:" x' (([UR])')m ",s_UBR:" ",s_URF:" U' (R F' RM' U R2 U') (MR' F R U R2') ",s_DRB:" ([URF])i ",s_ULB:" (LU)' (LU)",s_UFL:" L U'L' U [ULB] ",s_DLF:" U' L2 U ",s_DBL:" [DLF] [ULB] ",s_BRU:" (U'L'U) L (U'L'U) ",s_RUB:" ([BRU])i ",s_RFU:" (F'R) (UR2U') R' (FR) (UR2U') R ",s_FUR:" R2 U' RM'x L2M2 (ULU') R' (UL'U') L'R'U ",s_RBD:" R'UR2U'R'F'RUR2U'R'F ",s_BDR:" RUR' DL2 x2 U'RU L2x2 U'D'R ",s_LBU:" (U'L'U) ",s_BUL:" y RUR2U'R' y' ",s_FLU:" R' (ULU') ",s_LUF:" L' (U'L'U) ",s_LFD:" L2 (U'L'U) ",s_FDL:" (U'L'U) L' (U'LU)",s_BLD:" (U'LU) ",s_LDB:" L (U'L'U) "},pieces:{M2:["M2"],R2:["R2"],opposites:{buffers:{edges:["DF","FD","UB","BU"],corners:["DFR","RDF","FRD","UBR","RUB","BRU"]},normals:{edges:["UF","FU","DB","BD"],corners:["URF","FUR","RFU","DRB","BDR","RBD"]}},buffers:{edge:"DF",corner:"DFR"},cube:{U:"U",D:"D",F:"F",B:"B",L:"L",R:"R",DF:"DF",DR:"DR",DB:"DB",DL:"DL",UF:"UF",UR:"UR",UB:"UB",UL:"UL",FR:"FR",BR:"BR",FL:"FL",BL:"BL",DFR:"DFR",DRB:"DRB",DBL:"DBL",DLF:"DLF",URF:"URF",UBR:"UBR",ULB:"ULB",UFL:"UFL"},pieces:["U","D","F","B","L","R","DF","DR","DB","DL","UF","UR","UB","UL","FR","BR","FL","BL","DFR","DRB","DBL","DLF","URF","UBR","ULB","UFL"],faces:{U:["ULB","UB","UBR","UL","U","UR","UFL","UF","URF"],D:["DLF","DF","DFR","DL","D","DR","DBL","DB","DRB"],F:["FLU","FU","FUR","FL","F","FR","FDL","FD","FRD"],B:["BRU","BU","BUL","BR","B","BL","BDR","BD","BLD"],L:["LBU","LU","LUF","LB","L","LF","LDB","LD","LFD"],R:["RFU","RU","RUB","RF","R","RB","RDF","RD","RBD"]},slices:{M:["F","U","B","D","UF","UB","DB","DF"],E:["F","R","B","L","FL","FR","BL","BR"],S:["U","R","D","L","UL","UR","DR","DL"]},axis:{x:["U","F","D","B"],y:["F","L","B","R"],z:["U","R","D","L"]},noUnsetup:["UF","DB","FU","BD","DRB","RBD","BDR","URF","RFU","FUR"]},is:{face:function(a){return/^[udfblr]$/i.test(a)},slice:function(a){return/^[mes]$/i.test(a)},axis:function(a){return/^[xyz]$/i.test(a)},move:function(b){return a.is.face(b)||a.is.slice(b)||a.is.axis(b)},modifier:function(a){return/^[2i'\-\+]$/.test(a)},rotation:function(a){return/^[udfblrmesxyz][2i'\-\+]?$/i.test(a)},median:function(a){return/^([ud][fb]|[fb][ud])$/i.test(a)},pattern:function(a){return/^(o[24][udfb]|o6[lr]|c[cw][23]|pt[jn]|par|prn)$/i.test(a)},piece:function(a){return/^(?:([udfblr])(?!.*\1)){2,3}$/i.test(a)},edge:function(b){return 2==b.length&&a.is.piece(b)},corner:function(b){return 3==b.length&&a.is.piece(b)},buffer:function(b){return a.is.edge(b)&&a.service.targetOf(b)==a.pieces.buffers.edge||a.is.corner(b)&&a.service.targetOf(b)==a.pieces.buffers.corner}},canbe:{negative:function(a){return 1==a.length||"+"==a.charAt(1)||"-"==a.charAt(1)},mirror:function(b){return a.canbe.negative(b)||"2"==b.charAt(1)},accepted:function(a,b,c){var d=!b&&!c||""==b&&""==c;return b&&"string"==typeof b&&(d=1==b.length&&b==a.charAt(0)),b&&b instanceof Array&&(d=b.indexOf(a)>-1),c&&"string"==typeof c&&(d=!(1==c.length&&c==a.charAt(0))),c&&c instanceof Array&&(d=-1==c.indexOf(a)),d}},service:{targetOf:function(b){var c,d,e,f,g,h=b.toUpperCase();return null==a.pieces.cube[h]&&(c=h.indexOf("U"),d=h.indexOf("D"),e=h.indexOf("F"),f=h.indexOf("B"),g=c>-1?c:d>-1?d:e>-1?e:f>-1?f:null,g&&(h=h.substr(g)+h.substr(0,g))),h},moveCounter:function(a,b){var c=0;for(var d in a)a.hasOwnProperty(d)&&(c+=Number(a[d]==b));return c},cloneCube:function(b){var c,d={};for(c in a.pieces.cube)a.pieces.cube.hasOwnProperty(c)&&(d[c]=b&&b[c]?b[c]:a.pieces.cube[c]);return d},getPieceFromStickers:function(b,c){var d,e;for(d in c)if(c.hasOwnProperty(d)&&(c[d]==b||c[d]==a.service.rotate(b,-1)||c[d]==a.service.rotate(b,1)))return e=a.service.getRotation(c[d]),a.service.rotate(d,e);return!1},getStickersFromPiece:function(b,c,d){var e,f,g=a.service.targetOf(b),h=c[g],i=[];if(b==g||!d&&a.is.median(b))return h;for(e=0;e=1){-1==d.x.indexOf(b[0])?c=d.x:-1==d.y.indexOf(b[0])?c=d.y:-1==d.z.indexOf(b[0])&&(c=d.z);for(var g in e)e.hasOwnProperty(g)&&-1==c.indexOf(g)&&f.push(g)}if(b.length>=2){var h="U"==b[0]||"F"==b[0]||"L"==b[0]?1:"D"==b[0]||"B"==b[0]||"R"==b[0]?-1:0,i=c.indexOf(b[1]),j=i+2,k=i+h+2*h;j>=c.length&&(j-=c.length),k>=c.length&&(k-=c.length),0>k&&(k=c.length+k),f.push(b[1]),f.push(c[j]),f.push(c[k])}return 3==b.length&&f.push(b[2]),f}},math:{multiply:function(a,b){var c,d=[];for(c=0;b>c;c++)d=d.concat(a);return d},negative:function(b){var c,d,e=b;return a.canbe.negative(b)&&(c=b.charAt(0),d=1==b.length?"+":b.charAt(1),d=a.math.signInverse(d),e=c+d),e},inverse:function(b){var c=b;return a.canbe.negative(b)&&(c=a.math.negative(b)),c},mirror:function(b,c){c||(c="M");var d,e,f=b;return a.canbe.mirror(b)&&(d=b.charAt(0),d="M"==c?"L"==d?"R":"R"==d?"L":d:d,d="E"==c?"U"==d?"D":"D"==d?"U":d:d,d="S"==c?"F"==d?"B":"B"==d?"F":d:d,e=1==b.length?"+":b.charAt(1),f=a.math.negative(d+e)),f},negativePattern:function(b,c,d){var e,f=[];for(e=0;e=0?r[s]:p).push(a)}function g(a){s>-1?r[s]=r[s].concat(a):p=p.concat(a)}function h(){if("("==j&&(r[++s]=[]),")"==j&&(n=r[s],l==Number(l)?n=a.math.multiply(n,Number(l)):"-"==l||"'"==l?n=a.math.negativePattern(n):"m"==l.toLowerCase()?n=a.math.mirrorPattern(n):"i"==l.toLowerCase()&&(n=a.math.inversePattern(n)),s--,g(n),("m"==l.toLowerCase()||"i"==l.toLowerCase())&&(l="")&&(j="")),"["!=j||o||(o=[]),"]"==j&&o){if(o=o.join("").toUpperCase(),a.is.piece(o)||a.is.pattern(o)){var b=a.is.piece(o)?"s_":a.is.pattern(o)?"p_":"",d=a.patterns[b+o];d&&g(a.parse.moves(d))}o=!1}o&&"["!=j?f(j):j&&a.is.move(j)&&(m="2"==l?c?"+":l:"+"==l||"-"==l?l:"i"==l||"'"==l?"-":"+",k=(e&&!o?j:a.clear.adjustCase(j))+m,c&&"2"==l&&f(k),f(k),o||e||j!=j.toLowerCase()||(k=!1,"u"==j?k="E"+m:"d"==j?k="E"+a.math.signInverse(m):"f"==j?k="S"+m:"b"==j?k="S"+a.math.signInverse(m):"l"==j?k="M"+m:"r"==j&&(k="M"+a.math.signInverse(m)),k&&f(k))),j=l}for(var i,j,k,l,m,n,o,p=[],q=a.clear.all(b).split(""),r=[],s=-1,t=0;t0&&c==e&&(i.pop(),d==f?"2"==d?h=!1:d="2":(d=a.math.signSum(f,d),d||(h=!1))),h&&i.push(c+d),e=0==i.length?"":i[i.length-1].charAt(0),f=0==i.length?"":i[i.length-1].charAt(1);return i},uncollapseSequence:function(a){var b,c,d,e=[];for(d=0;d1&&a.length<4&&(c=new b(parseFloat(a[0]),parseFloat(a[1]),parseFloat(a[2]))),c}},a}(),e=function(a,b){function c(c){if(!c)throw new Error('no "name" provided for this displayObject:',this);if(a.call(this),this._name=c,this._parent=null,this._zIndex=0,this._position=new b,this._shape=null,this._info={stepCallback:null,renderMethod:null,renderInfo:null},this._options={strokeColor:0,fillColor:0,strokeSize:1,alpha:1,font:"14px Arial"},this[c])throw new Error('property "%s" already exists on',c,this)}return c.prototype=Object.create(a.prototype),c.prototype.setOptions=function(a){return a?(this._extend(this._options,a),!0):!1},c.prototype.setRenderInfo=function(a,b){b&&this.setOptions(b),this._info.renderInfo=a},c.prototype.setAnimationStep=function(a){this._info.stepCallback=a.bind(this)},c.prototype._addTo=function(a,b){this._zIndex=b||0,this._parent=a},c.prototype._remove=function(){delete this},c.prototype._render=function(a,b){if(!this._info.renderMethod)throw new Error("no renderMethod set for this instance of DisplayObject: ",this);return this._info.renderInfo?(a._info.draw.setup(this._options),this._shape=a._info.draw[this._info.renderMethod](this._info.renderInfo,this._position,b),a._info.draw.render(),!0):!1},c.prototype._step=function(a){return this._info.stepCallback&&this._info.stepCallback(a),!0},c}(a,b),f=function(a){function b(b){a.call(this,b),this._info.renderMethod="image"}return b.prototype=Object.create(a.prototype),b.prototype.render=function(){},b}(e),g=function(a){function b(b){a.call(this,b),this._options.font=this.getFont("Verdana",14),this._options.fillColor=0,this._options.strokeColor=null,this._info.renderMethod="text"}return b.prototype=Object.create(a.prototype),b.prototype.getFont=function(a,b,c){return a?(c||(c=""),b||(b=""),"number"==typeof b&&(b+="px"),[c,b,a].join(" ")):""},b.prototype.setFont=function(a,b,c){return a?(this._options.font=this.getFont(a,b,c),!0):!1},b}(e),h=function(a){function b(b){a.call(this,b),this._options.fillColor=null,this._options.strokeColor=0,this._info.renderMethod="polygon"}return b.prototype=Object.create(a.prototype),b}(e),i=function(a){function b(b){a.call(this,b),this._children={},this._childrenLength=function(){var a=0;return c(this,function(){a++}),a}.bind(this._children),this._childrenArray=function(){var a=[];return c(this,function(b){a.push(b)}),a.sort(function(a,b){return a._zIndex-b._zIndex})}.bind(this._children)}function c(a,b){if(a&&b)for(var c in a)a.hasOwnProperty(c)&&b(a[c])}return b.prototype=Object.create(a.prototype),b.prototype._render=function(a,b){this._childrenArray().forEach(function(c){c._render(a,b)})},b.prototype._step=function(b){return this._childrenArray().forEach(function(a){a._step(b)}),a.prototype._step.call(this,b),!0},b.prototype.addChild=function(b,c){if(!(b instanceof a))throw new Error("adding child with unsupported type:",typeof b);if(this[b._name])throw new Error('property "',b._name,'" already exists on',this);return c||(c=this._childrenLength()),this._children[b._name]=b,this[b._name]=b,b._addTo(this,c),this._reorderChildren(),b},b.prototype.removeChild=function(b){b instanceof String&&(b=this[b]),b&&this[b._name]&&this[b._name]instanceof a&&(delete this._children[b._name],delete this[b._name],b._remove())},b.prototype._reorderChildren=function(){this._childrenArray().forEach(function(a,b){a._info.index=b})},b.prototype._getShapes=function(){for(var a,c=[],d=0;d").addClass("iso-layer").css({position:"absolute",top:0,left:0}).append(this._info.canvas)}return e.prototype=Object.create(b.prototype),e.prototype._render=function(){this.clear(),b.prototype._render.call(this,this,this._info.mode==this._info.modes.ISOMETRIC)},e.prototype._remove=function(){this.$el.remove()},e.prototype._addTo=function(a){if(a){var b=a.worldSize();this.setSize(b.w,b.h),this.$el.appendTo(a.$el),this._engine=a}},e.prototype.toggleMode=function(a){this._info.modes[a]&&this.mode!=a&&(this.mode=a,this._render())},e.prototype.clear=function(){this._info.context.clearRect(-this._info.size.w/2,-this._info.size.h/2,this._info.size.w,this._info.size.h)},e.prototype.getCanvas=function(){return this._info.canvas},e.prototype.renderTime=function(a){this._step(a)&&this._render()},e.prototype.startAnimation=function(a){this._info.animator.start(a)},e.prototype.stopAnimation=function(){this._info.animator.stop()},e.prototype.setSize=function(a,b){this._info.size={w:a,h:b},this._info.canvas.width=a.toString(),this._info.canvas.height=b.toString(),this._info.context.translate(a/2,b/2)},e.prototype.setShadow=function(a,b,c,d){this._info.context.shadowColor=a||"#999",this._info.context.shadowBlur=b||20,this._info.context.shadowOffsetX=c||15,this._info.context.shadowOffsetY=d||c||15},e}(jQuery,i),k=function(a){function b(b){a.call(this,b)}return b.prototype=Object.create(a.prototype),b}(i),l=function(a,b){function c(){this.$el=a("
"),this.layers={},this.fpsInterval=null,this.fpsLogInterval=null,this.utils={worldSizeWidth:400,worldSizeHeight:400}}function d(a,b){for(var c=!1,d=-1,e=a.length,f=e-1;++d-1),b&&"string"==typeof b&&(d=!(1==b.length&&b==a.charAt(0))),b&&b instanceof Array&&(d=-1==b.indexOf(a)),d}},service:{targetOf:function(a){var c,d,e,f,g,h=a.toUpperCase();return null==b.pieces.cube[h]&&(c=h.indexOf("U"),d=h.indexOf("D"),e=h.indexOf("F"),f=h.indexOf("B"),g=c>-1?c:d>-1?d:e>-1?e:f>-1?f:null,g&&(h=h.substr(g)+h.substr(0,g))),h},moveCounter:function(a,b){var c=0;for(var d in a)a.hasOwnProperty(d)&&(c+=Number(a[d]==b));return c},cloneCube:function(a){var c,d={};for(c in b.pieces.cube)b.pieces.cube.hasOwnProperty(c)&&(d[c]=a&&a[c]?a[c]:b.pieces.cube[c]);return d},getPieceFromStickers:function(a,c){var d,e;for(d in c)if(c.hasOwnProperty(d)&&(c[d]==a||c[d]==b.service.rotate(a,-1)||c[d]==b.service.rotate(a,1)))return e=b.service.getRotation(c[d]),b.service.rotate(d,e);return!1},getStickersFromPiece:function(a,c,d){var e,f,g=b.service.targetOf(a),h=c[g],i=[];if(a==g||!d&&b.is.median(a))return h;for(e=0;e=1){-1==d.x.indexOf(a[0])?c=d.x:-1==d.y.indexOf(a[0])?c=d.y:-1==d.z.indexOf(a[0])&&(c=d.z);for(var g in e)e.hasOwnProperty(g)&&-1==c.indexOf(g)&&f.push(g)}if(a.length>=2){var h="U"==a[0]||"F"==a[0]||"L"==a[0]?1:"D"==a[0]||"B"==a[0]||"R"==a[0]?-1:0,i=c.indexOf(a[1]),j=i+2,k=i+h+2*h;j>=c.length&&(j-=c.length),k>=c.length&&(k-=c.length),0>k&&(k=c.length+k),f.push(a[1]),f.push(c[j]),f.push(c[k])}return 3==a.length&&f.push(a[2]),f}},math:{multiply:function(a,b){var c,d=[];for(c=0;b>c;c++)d=d.concat(a);return d},negative:function(a){var c,d,e=a;return b.canbe.negative(a)&&(c=a.charAt(0),d=1==a.length?"+":a.charAt(1),d=b.math.signInverse(d),e=c+d),e},inverse:function(a){var c=a;return b.canbe.negative(a)&&(c=b.math.negative(a)),c},mirror:function(a,c){c||(c="M");var d,e,f=a;return b.canbe.mirror(a)&&(d=a.charAt(0),d="M"==c?"L"==d?"R":"R"==d?"L":d:d,d="E"==c?"U"==d?"D":"D"==d?"U":d:d,d="S"==c?"F"==d?"B":"B"==d?"F":d:d,e=1==a.length?"+":a.charAt(1),f=b.math.negative(d+e)),f},negativePattern:function(a,c,d){var e,f=[];for(e=0;e=0?r[s]:p).push(a)}function g(a){s>-1?r[s]=r[s].concat(a):p=p.concat(a)}function h(){if("("==j&&(r[++s]=[]),")"==j&&(n=r[s],l==Number(l)?n=b.math.multiply(n,Number(l)):"-"==l||"'"==l?n=b.math.negativePattern(n):"m"==l.toLowerCase()?n=b.math.mirrorPattern(n):"i"==l.toLowerCase()&&(n=b.math.inversePattern(n)),s--,g(n),("m"==l.toLowerCase()||"i"==l.toLowerCase())&&(l="")&&(j="")),"["!=j||o||(o=[]),"]"==j&&o){if(o=o.join("").toUpperCase(),b.is.piece(o)||b.is.pattern(o)){var a=b.is.piece(o)?"s_":b.is.pattern(o)?"p_":"",d=b.patterns[a+o];d&&g(b.parse.moves(d))}o=!1}o&&"["!=j?f(j):j&&b.is.move(j)&&(m="2"==l?c?"+":l:"+"==l||"-"==l?l:"i"==l||"'"==l?"-":"+",k=(e&&!o?j:b.clear.adjustCase(j))+m,c&&"2"==l&&f(k),f(k),o||e||j!=j.toLowerCase()||(k=!1,"u"==j?k="E"+m:"d"==j?k="E"+b.math.signInverse(m):"f"==j?k="S"+m:"b"==j?k="S"+b.math.signInverse(m):"l"==j?k="M"+m:"r"==j&&(k="M"+b.math.signInverse(m)),k&&f(k))),j=l}for(var i,j,k,l,m,n,o,p=[],q=b.clear.all(a).split(""),r=[],s=-1,t=0;t0&&c==e&&(i.pop(),d==f?"2"==d?h=!1:d="2":(d=b.math.signSum(f,d),d||(h=!1))),h&&i.push(c+d),e=0==i.length?"":i[i.length-1].charAt(0),f=0==i.length?"":i[i.length-1].charAt(1);return i},uncollapseSequence:function(a){var b,c,d,e=[];for(d=0;da.expand.piece(i,!0).length),h&&(e?k.push(i):k=i)}return k},opposite:function(b,d){var e=d?"buffers":"normals",f=a.pieces.opposites[e].edges.indexOf(b),g=a.pieces.opposites[e].corners.indexOf(b),h=[b],i=0;return f>-1&&(i=f+2,h=a.pieces.opposites[e].edges),g>-1&&(i=g+3,h=a.pieces.opposites[e].corners),i>=h.length&&(i-=h.length),f>-1&&(d||c.explainCallback("PIECES_CYCLE_OPPOSITE_MEDIAN_EDGES",[b,h[i]])),g>-1&&(d||c.explainCallback("PIECES_CYCLE_OPPOSITE_RIGHT_CORNERS",[b,h[i]])),h[i]}},solve:{explain:function(a){return c.explainArray=[],c.solveArray=c.solve.full(a,0),{s:c.solveArray,e:c.explainArray}},full:function(b,d){if((!d||0>d||d>3)&&(d=0),!c.check.orientedCube(b))return[];if(!c.check.correctPieces(b))return[];c.explainCallback("BEGIN");var e=c.solve.edgesUnoriented(b);e=e.concat(c.solve.pieces(b,a.pieces.buffers.edge,a.pieces.M2));var f=c.solve.pieces(b,a.pieces.buffers.corner,a.pieces.R2),g=Boolean(a.service.moveCounter(e,a.pieces.M2)%2),h=Boolean(a.service.moveCounter(f,a.pieces.R2)%2);g!=h&&console.warn("WARNING: this case is not handled!! parity happened only on edges or corners..",b);var i=e.concat(f);c.explainCallback("END",[i.toString()]);var j=a.expand.pattern(i),k=a.clear.collapseSequence(j),l=a.clear.uncollapseSequence(j),m=a.math.inversePattern(k);return 0==d?i:1==d?l:2==d?k:3==d?m:[]},pieces:function(b,d,e){function f(e,f,g){var h=a.service.targetOf(e);if(a.is.median(e)&&(g||h!=d)){var i=a.service.getPieceFromStickers(e,b);c.explainCallback("PIECES_EDGES_BEGIN",e);var j=i!=a.service.targetOf(i);j||c.explainCallback("PIECES_EDGES_FLIPPED_STATE",[e,j]);var k=f&&a.service.getRotation(f)&&!a.is.median(f);k&&(j=!j),g&&(j=r),k&&c.explainCallback("PIECES_EDGES_PREVIOUS_FLIPPED",[e,f]),g&&r&&c.explainCallback("PIECES_EDGES_BUFFER_FLIPPED",e),j&&-1==n.indexOf(h)&&(n.push(h),c.explainCallback("PIECES_EDGES_ADD_TO_FLIPPED",[e,n.toString()])),c.explainCallback("END_VOID")}}function g(b){var d=q?c.service.opposite(j):j;b?(u=h,c.explainCallback("MEMORIZE_PLACEHOLDER",h)):c.explainCallback("MEMORIZE_PIECE",d),m.push(d),k=a.service.getStickersFromPiece(j,i),q=!q,i[h]=h,j!=k&&(c.explainCallback("PIECES_CYCLE_CHECK_NEXT_PIECE",[j,k]),o&&f.call(this,k,j))}var h,i=a.service.cloneCube(b),j=d,k=i[d],l=!k,m=[],n=[],o=a.is.edge(d),p=a.is.corner(d);c.explainCallback("PIECES_BEGIN",(o?"edges":p?"corners":"").toUpperCase());var q=!1,r=!1,s=!1,t=!1,u=!1;for(c.explainCallback("PIECES_CYCLE_BEGIN"),c.explainCallback("PIECES_CYCLE_EXAMINE_BUFFER",d),c.explainCallback("PIECES_CYCLE_CHECK_BUFFER_POSITION",k),o&&f.call(this,k),c.explainCallback("END_VOID");!l;){if(c.explainCallback("PIECES_CYCLE_EXAMINE_PIECE",k),j=k,h=a.service.targetOf(j),t=a.is.buffer(j),t&&c.explainCallback("PIECES_CYCLE_BUFFER_FOUND",[j,j!=h]),r=t?j!=h:h!=u||j==h||a.is.median(j)?r:!r,t||h!=u||(u=!1,t=!0,c.explainCallback("PIECES_CYCLE_PLACEHOLDER_FOUND",[j,j!=h&&!a.is.median(j)]),o&&j!=h&&c.explainCallback("PIECES_CYCLE_EDGE_IS_FLIPPED",[j,a.is.median(j)]),g.call(this)),t)if(s=c.service.freeTarget(i,j.length),c.explainCallback("PIECES_CYCLE_CHECK_FREE_TARGET",s.toString()),s!==!1)j=s,h=s,g.call(this,!0);else{if(c.explainCallback("PIECES_CYCLE_ALL_IS_OK"),o&&f.call(this,d,!1,!0),q){if(c.explainCallback("PIECES_PARITY_BEGIN"),c.explainCallback("MEMORIZE_MIDDLE",[o?"M-slice":"R-face",e]),m=m.concat(e),o){if(n.length>0){for(var v in n)n[v]=c.service.opposite(n[v],!0);c.explainCallback("PIECES_PARITY_SWITCH_FLIPPED_MEDIANS",n.toString())}}else c.explainCallback("MEMORIZE_PARITY","PAR"),m=m.concat(["PAR"]);c.explainCallback("END_VOID")}if(o){var w=c.solve.mEdgesUnoriented(n);m=m.concat(w),w.length>0&&c.explainCallback("MEMORIZE_ORIENT_EDGES",w.toString())}l=!0}else g.call(this);c.explainCallback("END_VOID")}return c.explainCallback("END_VOID"),c.explainCallback("PIECES_END",[(o?"edges":p?"corners":"").toUpperCase(),m.toString()]),m},edgesUnoriented:function(){c.explainCallback("UNORIENTED_BEGIN");var a=[];return c.explainCallback("UNORIENTED_WIP"),c.explainCallback("UNORIENTED_END",[a.toString()]),a},mEdgesUnoriented:function(a){var b,c,d,e,f,g,h=[];return(1==a.length||3==a.length||a.length>4)&&console.error("ERROR: wrong array of flipped M-edges: ",a),4==a.length&&(h=["O2U","O2D"]),2==a.length&&(d=a[0].charAt(0),e=a[0].charAt(1),a[1].indexOf(d)>-1&&(c=d),a[1].indexOf(e)>-1&&(c=e),c?h=["O2"+c]:(f=a[0].indexOf("D"),g=a[1].indexOf("D"),f>-1&&(b=Number(!f),c=a[0].charAt(b)),g>-1&&(b=Number(!g),c=a[1].charAt(b)),c&&(h=[c+"2","O2U",c+"2"]))),h}}}}(b),d=function(){var a={TITLE:{p:0,g:0,m:"* SOLVE PROCESS *"},BEGIN:{p:0,g:1,m:"begin memorizing"},END:{p:0,g:-1,m:"end memorizing [%s]"},BEGIN_VOID:{p:3,g:1,m:""},END_VOID:{p:3,g:-1,m:""},UNORIENTED_BEGIN:{p:3,g:1,m:"solve unoriented edges"},UNORIENTED_END:{p:3,g:-1,m:"unoriented pieces: [%s]"},UNORIENTED_WIP:{p:3,g:0,m:"method not yet implemented. will return an empty array."},PIECES_BEGIN:{p:3,g:1,m:"solve unpermuted/unoriented %s"},PIECES_END:{p:1,g:-1,m:"done with %s: [%s]"},PIECES_CYCLE_BEGIN:{p:3,g:1,m:"piece-finding cycle"},PIECES_CYCLE_EXAMINE_BUFFER:{p:3,g:1,m:"examine the buffer [%s]"},PIECES_CYCLE_EXAMINE_PIECE:{p:3,g:1,m:"examine the piece [%s]"},PIECES_CYCLE_CHECK_BUFFER:{p:1,g:0,m:"first thing first: examine the buffer piece: [%s]"},PIECES_CYCLE_BUFFER_FOUND:{p:2,g:0,m:"the piece [%s] is the buffer - flipState: %s"},PIECES_CYCLE_PLACEHOLDER_FOUND:{p:2,g:0,m:"the piece in [%s] position is the buffer - should invert flipState? %s"},PIECES_CYCLE_CHECK_FREE_TARGET:{p:1,g:0,m:"check for the first target to be solved: [%s]"},PIECES_CYCLE_ALL_IS_OK:{p:2,g:0,m:"all pieces are correctly permuted"},PIECES_CYCLE_CHECK_BUFFER_FLIP:{p:1,g:0,m:"check if edge buffer is flipped after all iterations"},PIECES_CYCLE_EDGE_IS_FLIPPED:{p:2,g:0,m:"note that the edge [%s] is flipped - is median? %s"},PIECES_CYCLE_BUFFER_FLIP_STATE:{p:1,g:0,m:"remember to %s the flip state of buffer piece when edges are finished"},PIECES_CYCLE_OPPOSITE_MEDIAN_EDGES:{p:2,g:0,m:"the M-slice is rotated, so switch DB with UF or viceversa: [%s] -> [%s]"},PIECES_CYCLE_OPPOSITE_RIGHT_CORNERS:{p:2,g:0,m:"the R-face is rotated, so switch DRB with URF or viceversa: [%s] -> [%s]"},PIECES_CYCLE_CHECK_NEXT_PIECE:{p:2,g:0,m:"look at the piece in [%s] position: [%s]"},PIECES_CYCLE_CHECK_BUFFER_POSITION:{p:2,g:0,m:"look at the piece in buffer position: [%s]"},PIECES_EDGES_BEGIN:{p:3,g:1,m:"check for flipped median edge [%s]"},PIECES_EDGES_FLIPPED_STATE:{p:2,g:0,m:"flipped state of piece [%s] : %s"},PIECES_EDGES_PREVIOUS_FLIPPED:{p:1,g:0,m:"invert flipped state of [%s] because previous piece [%s] was unoriented"},PIECES_EDGES_BUFFER_FLIPPED:{p:2,g:0,m:"invert flipped state of buffer [%s]"},PIECES_EDGES_ADD_TO_FLIPPED:{p:1,g:0,m:"edge [%s] is flipped, add it to the flipped edge list: [%s]"},PIECES_EDGES_DONT_CHECK_BUFFER:{p:2,g:0,m:"is not the time to check the buffer [%s] flip state"},PIECES_EDGES_IS_MEDIAN:{p:2,g:0,m:"the piece [%s] is part of median slice"},PIECES_EDGES_CHECK_ONLY_MEDIAN:{p:2,g:0,m:"the piece [%s] is not part of median slice"},PIECES_PARITY_BEGIN:{p:3,g:1,m:"parity occurred!"},PIECES_PARITY_SWITCH_FLIPPED_MEDIANS:{p:2,g:0,m:"switch DF with UB and viceversa in the list of flipped edges: [%s]"},MEMORIZE_MIDDLE:{p:0,g:0,m:"** the %s is rotated, for now rotate it back with [%s]"},MEMORIZE_PARITY:{p:0,g:0,m:"** finally do the parity pattern: [%s]"},MEMORIZE_PIECE:{p:0,g:0,m:"** memorize the piece: [%s]"},MEMORIZE_PLACEHOLDER:{p:0,g:0,m:"** memorize the buffer placeholder position: [%s]"},MEMORIZE_ORIENT_EDGES:{p:0,g:0,m:"** memorize the sequence for correctly orient the median edges: [%s]"}};return{constants:a,explain:function(a,b){var c=0,d=0,e=a,f=this.constants[a];f&&(c=f.p,d=f.g,e=f.m);var g,h,i;if(e){if(g=e,b)if("string"==typeof b)g=e.replace(/%s/g,b);else{i=e.split("%s");for(h in i)i.hasOwnProperty(h)&&null!=b[h]&&(i[h]=i[h]+b[h]); +/*! RubikHelper - v0.1.1 - 2015-05-04 */ +var RubikHelper=function(){var a=function(){var a=function(){function a(){this._attributes={}}return a.prototype={set:function(a,b){return this._attributes[a]=b,this},get:function(a){return this._attributes[a]},_extend:function(a,b){if(b)for(var c in b)b.hasOwnProperty(c)&&(a[c]&&a[c]instanceof Object&&!(a[c]instanceof Array)?this._extend(a[c],b[c]):a[c]=b[c])}},a}(),b=function(){function a(a,b,c){this.x=parseFloat(a)||0,this.y=parseFloat(b)||0,this.z=parseFloat(c)||0}return a.prototype={toOrtho:function(){return new a(this.x-this.y,(this.x+this.y)/2-1.25*this.z,0)},toIso:function(){return new a(this.y+this.x/2,this.y-this.x/2,0)},toString:function(){return"{x:"+this.x+", y:"+this.y+", z:"+this.z+"}"},toObject:function(){return{x:this.x,y:this.y,z:this.z}},toArray:function(){return[this.x,this.y,this.z]},add:function(b){return new a(this.x+b.x,this.y+b.y,this.z+b.z)},subtract:function(b){return new a(this.x-b.x,this.y-b.y,this.z-b.z)},multiply:function(b){return new a(this.x*b.x,this.y*b.y,this.z*b.z)},distance:function(a){var b=Math.abs(this.x-a.x),c=Math.abs(this.y-a.y),d=Math.abs(this.z-a.z),e=Math.sqrt(Math.pow(b,2)+Math.pow(c,2));return Math.sqrt(Math.pow(e,2)+Math.pow(d,2))}},a}(),c=function(){function a(a){this._stepCallback=null,this._animation=null,this._startTime=0,a&&this.setCallback(a),window.requestAnimFrame=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(a){return window.setTimeout(a,1e3/60)}}(),window.cancelRequestAnimFrame=function(){return window.cancelAnimationFrame||window.cancelRequestAnimationFrame||window.webkitCancelRequestAnimationFrame||window.mozCancelRequestAnimationFrame||window.oCancelRequestAnimationFrame||window.msCancelRequestAnimationFrame||clearTimeout}()}return a.prototype={setCallback:function(a){this._stepCallback=a},start:function(a){this._startTime=(new Date).getTime(),this._animate(),a&&setTimeout(function(){this.stop()}.bind(this),a)},stop:function(){cancelRequestAnimFrame(this._animation),this._animation=null},_animate:function(){this._stepRender(),this._animation=requestAnimFrame(this._animate.bind(this))},_stepRender:function(){var a=(new Date).getTime()-this._startTime;this._stepCallback&&this._stepCallback(a)}},a}(),d=function(){function a(a){this.context=a,this.message=null,this.messageOrigin={x:0,y:0},this.isPath=!1,this.isStroke=!1}return a.prototype={setup:function(a){a||(a={});var b=null==a.fillColor?null:this.castToColor(a.fillColor),c=null==a.strokeColor?null:this.castToColor(a.strokeColor),d=a.strokeSize;this.context.restore(),this.context.fillStyle=b,this.context.strokeStyle=c,this.context.lineWidth=d,this.context.globalAlpha=a.alpha||1,this.context.font=a.font||"20px Open Sans",this.context.save(),this.isStroke=null!=c,this.isPath=null!=b,this.isPath&&this.context.beginPath()},render:function(){this.message&&(this.isPath&&this.context.fillText(this.message,this.messageOrigin.x,this.messageOrigin.y),this.isStroke&&this.context.strokeText(this.message,this.messageOrigin.x,this.messageOrigin.y),this.message=null),this.isPath&&this.context.closePath(),this.isPath&&this.context.fill(),this.isPath=!1,this.isStroke&&this.context.stroke(),this.isStroke=!1},moveTo:function(a,b){var c=this.isPath||this.isStroke;return c&&this.context.moveTo(a,b),c},lineTo:function(a,b){var c=this.isPath||this.isStroke;return c&&this.context.lineTo(a,b),c},text:function(a,b){if(!a)return[];b||(b=[0,0]),b=this.castToPoint(b),this.messageOrigin=b,this.message=a;var c=this.context.measureText(a),d=this.context.font,e=Math.ceil(c.width),f=parseInt(d);return isNaN(f)&&(d=d.substr(d.indexOf(" ")),f=parseInt(d)),[b.add([0,0]),b.add([e,0]),b.add([e,-f]),b.add([0,-f])]},line:function(a,b,c){return a&&b?(a=this.castToPoint(a),b=this.castToPoint(b),c&&(a=a.toOrtho(),b=b.toOrtho()),this.moveTo(a.x,a.y)&&this.lineTo(b.x,b.y)):!1},polygon:function(a,b,c){if(!a)return[];b||(b=[0,0,0]),b=this.castToPoint(b),a=a.map(function(a){return this.castToPoint(a)}.bind(this)),c&&(b=b.toOrtho()),c&&(a=a.map(function(a){return a.toOrtho()}));var d,e,f=b.add(a[0]),g=[];for(this.moveTo(f.x,f.y)&&g.push(f),d=1;d1&&a.length<4&&(c=new b(parseFloat(a[0]),parseFloat(a[1]),parseFloat(a[2]))),c}},a}(),e=function(a,b){function c(c){if(!c)throw new Error('no "name" provided for this displayObject:',this);if(a.call(this),this._name=c,this._parent=null,this._zIndex=0,this._position=new b,this._shape=null,this._info={stepCallback:null,renderMethod:null,renderInfo:null},this._options={strokeColor:0,fillColor:0,strokeSize:1,alpha:1,font:"14px Arial"},this[c])throw new Error('property "%s" already exists on',c,this)}return c.prototype=Object.create(a.prototype),c.prototype.setOptions=function(a){return a?(this._extend(this._options,a),!0):!1},c.prototype.setRenderInfo=function(a,b){b&&this.setOptions(b),this._info.renderInfo=a},c.prototype.setAnimationStep=function(a){this._info.stepCallback=a.bind(this)},c.prototype._addTo=function(a,b){this._zIndex=b||0,this._parent=a},c.prototype._remove=function(){delete this},c.prototype._render=function(a,b){if(!this._info.renderMethod)throw new Error("no renderMethod set for this instance of DisplayObject: ",this);return this._info.renderInfo?(a._info.draw.setup(this._options),this._shape=a._info.draw[this._info.renderMethod](this._info.renderInfo,this._position,b),a._info.draw.render(),!0):!1},c.prototype._step=function(a){return this._info.stepCallback&&this._info.stepCallback(a),!0},c}(a,b),f=function(a){function b(b){a.call(this,b),this._info.renderMethod="image"}return b.prototype=Object.create(a.prototype),b.prototype.render=function(){},b}(e),g=function(a){function b(b){a.call(this,b),this._options.font=this.getFont("Verdana",14),this._options.fillColor=0,this._options.strokeColor=null,this._info.renderMethod="text"}return b.prototype=Object.create(a.prototype),b.prototype.getFont=function(a,b,c){return a?(c||(c=""),b||(b=""),"number"==typeof b&&(b+="px"),[c,b,a].join(" ")):""},b.prototype.setFont=function(a,b,c){return a?(this._options.font=this.getFont(a,b,c),!0):!1},b}(e),h=function(a){function b(b){a.call(this,b),this._options.fillColor=null,this._options.strokeColor=0,this._info.renderMethod="polygon"}return b.prototype=Object.create(a.prototype),b}(e),i=function(a){function b(b){a.call(this,b),this._children={},this._childrenLength=function(){var a=0;return c(this,function(){a++}),a}.bind(this._children),this._childrenArray=function(){var a=[];return c(this,function(b){a.push(b)}),a.sort(function(a,b){return a._zIndex-b._zIndex})}.bind(this._children)}function c(a,b){if(a&&b)for(var c in a)a.hasOwnProperty(c)&&b(a[c])}return b.prototype=Object.create(a.prototype),b.prototype._render=function(a,b){this._childrenArray().forEach(function(c){c._render(a,b)})},b.prototype._step=function(b){return this._childrenArray().forEach(function(a){a._step(b)}),a.prototype._step.call(this,b),!0},b.prototype.addChild=function(b,c){if(!(b instanceof a))throw new Error("adding child with unsupported type:",typeof b);if(this[b._name])throw new Error('property "',b._name,'" already exists on',this);return c||(c=this._childrenLength()),this._children[b._name]=b,this[b._name]=b,b._addTo(this,c),this._reorderChildren(),b},b.prototype.removeChild=function(b){b instanceof String&&(b=this[b]),b&&this[b._name]&&this[b._name]instanceof a&&(delete this._children[b._name],delete this[b._name],b._remove())},b.prototype._reorderChildren=function(){this._childrenArray().forEach(function(a,b){a._info.index=b})},b.prototype._getShapes=function(){for(var a,c=[],d=0;d").addClass("iso-layer").css({position:"absolute",top:0,left:0}).append(this._info.canvas)}return e.prototype=Object.create(b.prototype),e.prototype._render=function(){this.clear(),b.prototype._render.call(this,this,this._info.mode==this._info.modes.ISOMETRIC)},e.prototype._remove=function(){this.$el.remove()},e.prototype._addTo=function(a){if(a){var b=a.worldSize();this.setSize(b.w,b.h),this.$el.appendTo(a.$el),this._engine=a}},e.prototype.toggleMode=function(a){this._info.modes[a]&&this.mode!=a&&(this.mode=a,this._render())},e.prototype.clear=function(){this._info.context.clearRect(-this._info.size.w/2,-this._info.size.h/2,this._info.size.w,this._info.size.h)},e.prototype.getCanvas=function(){return this._info.canvas},e.prototype.renderTime=function(a){this._step(a)&&this._render()},e.prototype.startAnimation=function(a){this._info.animator.start(a)},e.prototype.stopAnimation=function(){this._info.animator.stop()},e.prototype.setSize=function(a,b){this._info.size={w:a,h:b},this._info.canvas.width=a.toString(),this._info.canvas.height=b.toString(),this._info.context.translate(a/2,b/2)},e.prototype.setShadow=function(a,b,c,d){this._info.context.shadowColor=a||"#999",this._info.context.shadowBlur=b||20,this._info.context.shadowOffsetX=c||15,this._info.context.shadowOffsetY=d||c||15},e}(jQuery,i),k=function(a){function b(b){a.call(this,b)}return b.prototype=Object.create(a.prototype),b}(i),l=function(a,b){function c(){this.$el=a("
"),this.layers={},this.fpsInterval=null,this.fpsLogInterval=null,this.utils={worldSizeWidth:400,worldSizeHeight:400}}function d(a,b){for(var c=!1,d=-1,e=a.length,f=e-1;++d-1),c&&"string"==typeof c&&(d=!(1==c.length&&c==a.charAt(0))),c&&c instanceof Array&&(d=-1==c.indexOf(a)),d}},service:{targetOf:function(a){var c,d,e,f,g,h=a.toUpperCase();return null==b.pieces.cube[h]&&(c=h.indexOf("U"),d=h.indexOf("D"),e=h.indexOf("F"),f=h.indexOf("B"),g=c>-1?c:d>-1?d:e>-1?e:f>-1?f:null,g&&(h=h.substr(g)+h.substr(0,g))),h},moveCounter:function(a,b){var c=0;for(var d in a)a.hasOwnProperty(d)&&(c+=Number(a[d]==b));return c},cloneCube:function(a){var c,d={};for(c in b.pieces.cube)b.pieces.cube.hasOwnProperty(c)&&(d[c]=a&&a[c]?a[c]:b.pieces.cube[c]);return d},getPieceFromStickers:function(a,c){var d,e;for(d in c)if(c.hasOwnProperty(d)&&(c[d]==a||c[d]==b.service.rotate(a,-1)||c[d]==b.service.rotate(a,1)))return e=b.service.getRotation(c[d]),b.service.rotate(d,e);return!1},getStickersFromPiece:function(a,c,d){var e,f,g=b.service.targetOf(a),h=c[g],i=[];if(a==g||!d&&b.is.median(a))return h;for(e=0;e=1){-1==d.x.indexOf(a[0])?c=d.x:-1==d.y.indexOf(a[0])?c=d.y:-1==d.z.indexOf(a[0])&&(c=d.z);for(var g in e)e.hasOwnProperty(g)&&-1==c.indexOf(g)&&f.push(g)}if(a.length>=2){var h="U"==a[0]||"F"==a[0]||"L"==a[0]?1:"D"==a[0]||"B"==a[0]||"R"==a[0]?-1:0,i=c.indexOf(a[1]),j=i+2,k=i+h+2*h;j>=c.length&&(j-=c.length),k>=c.length&&(k-=c.length),0>k&&(k=c.length+k),f.push(a[1]),f.push(c[j]),f.push(c[k])}return 3==a.length&&f.push(a[2]),f}},math:{multiply:function(a,b){var c,d=[];for(c=0;b>c;c++)d=d.concat(a);return d},negative:function(a){var c,d,e=a;return b.canbe.negative(a)&&(c=a.charAt(0),d=1==a.length?"+":a.charAt(1),d=b.math.signInverse(d),e=c+d),e},inverse:function(a){var c=a;return b.canbe.negative(a)&&(c=b.math.negative(a)),c},mirror:function(a,c){c||(c="M");var d,e,f=a;return b.canbe.mirror(a)&&(d=a.charAt(0),d="M"==c?"L"==d?"R":"R"==d?"L":d:d,d="E"==c?"U"==d?"D":"D"==d?"U":d:d,d="S"==c?"F"==d?"B":"B"==d?"F":d:d,e=1==a.length?"+":a.charAt(1),f=b.math.negative(d+e)),f},negativePattern:function(a,c,d){var e,f=[];for(e=0;e=0?r[s]:p).push(a)}function g(a){s>-1?r[s]=r[s].concat(a):p=p.concat(a)}function h(){if("("==j&&(r[++s]=[]),")"==j&&(n=r[s],l==Number(l)?n=b.math.multiply(n,Number(l)):"-"==l||"'"==l?n=b.math.negativePattern(n):"m"==l.toLowerCase()?n=b.math.mirrorPattern(n):"i"==l.toLowerCase()&&(n=b.math.inversePattern(n)),s--,g(n),("m"==l.toLowerCase()||"i"==l.toLowerCase())&&(l="")&&(j="")),"["!=j||o||(o=[]),"]"==j&&o){if(o=o.join("").toUpperCase(),b.is.piece(o)||b.is.pattern(o)){var a=b.is.piece(o)?"s_":b.is.pattern(o)?"p_":"",d=b.patterns[a+o];d&&g(b.parse.moves(d))}o=!1}o&&"["!=j?f(j):j&&b.is.move(j)&&(m="2"==l?c?"+":l:"+"==l||"-"==l?l:"i"==l||"'"==l?"-":"+",k=(e&&!o?j:b.clear.adjustCase(j))+m,c&&"2"==l&&f(k),f(k),o||e||j!=j.toLowerCase()||(k=!1,"u"==j?k="E"+m:"d"==j?k="E"+b.math.signInverse(m):"f"==j?k="S"+m:"b"==j?k="S"+b.math.signInverse(m):"l"==j?k="M"+m:"r"==j&&(k="M"+b.math.signInverse(m)),k&&f(k))),j=l}for(var i,j,k,l,m,n,o,p=[],q=b.clear.all(a).split(""),r=[],s=-1,t=0;t0&&c==e&&(i.pop(),d==f?"2"==d?h=!1:d="2":(d=b.math.signSum(f,d),d||(h=!1))),h&&i.push(c+d),e=0==i.length?"":i[i.length-1].charAt(0),f=0==i.length?"":i[i.length-1].charAt(1);return i},uncollapseSequence:function(a){var b,c,d,e=[];for(d=0;da.expand.piece(i,!0).length),h&&(e?k.push(i):k=i)}return k},opposite:function(b,d){var e=d?"buffers":"normals",f=a.pieces.opposites[e].edges.indexOf(b),g=a.pieces.opposites[e].corners.indexOf(b),h=[b],i=0;return f>-1&&(i=f+2,h=a.pieces.opposites[e].edges),g>-1&&(i=g+3,h=a.pieces.opposites[e].corners),i>=h.length&&(i-=h.length),f>-1&&(d||c.explainCallback("PIECES_CYCLE_OPPOSITE_MEDIAN_EDGES",[b,h[i]])),g>-1&&(d||c.explainCallback("PIECES_CYCLE_OPPOSITE_RIGHT_CORNERS",[b,h[i]])),h[i]}},solve:{explain:function(a){return c.explainArray=[],c.solveArray=c.solve.full(a,0),{s:c.solveArray,e:c.explainArray}},full:function(b,d){if((!d||0>d||d>3)&&(d=0),!c.check.orientedCube(b))return[];if(!c.check.correctPieces(b))return[];c.explainCallback("BEGIN");var e=c.solve.edgesUnoriented(b);e=e.concat(c.solve.pieces(b,a.pieces.buffers.edge,a.pieces.M2));var f=c.solve.pieces(b,a.pieces.buffers.corner,a.pieces.R2),g=Boolean(a.service.moveCounter(e,a.pieces.M2)%2),h=Boolean(a.service.moveCounter(f,a.pieces.R2)%2);g!=h&&console.warn("WARNING: this case is not handled!! parity happened only on edges or corners..",b);var i=e.concat(f);c.explainCallback("END",[i.toString()]);var j=a.expand.pattern(i),k=a.clear.collapseSequence(j),l=a.clear.uncollapseSequence(j),m=a.math.inversePattern(k);return 0==d?i:1==d?l:2==d?k:3==d?m:[]},pieces:function(b,d,e){function f(e,f,g){var h=a.service.targetOf(e);if(a.is.median(e)&&(g||h!=d)){var i=a.service.getPieceFromStickers(e,b);c.explainCallback("PIECES_EDGES_BEGIN",e);var j=i!=a.service.targetOf(i);j||c.explainCallback("PIECES_EDGES_FLIPPED_STATE",[e,j]);var k=f&&a.service.getRotation(f)&&!a.is.median(f);k&&(j=!j),g&&(j=r),k&&c.explainCallback("PIECES_EDGES_PREVIOUS_FLIPPED",[e,f]),g&&r&&c.explainCallback("PIECES_EDGES_BUFFER_FLIPPED",e),j&&-1==n.indexOf(h)&&(n.push(h),c.explainCallback("PIECES_EDGES_ADD_TO_FLIPPED",[e,n.toString()])),c.explainCallback("END_VOID")}}function g(b){var d=q?c.service.opposite(j):j;b?(u=h,c.explainCallback("MEMORIZE_PLACEHOLDER",h)):c.explainCallback("MEMORIZE_PIECE",d),m.push(d),k=a.service.getStickersFromPiece(j,i),q=!q,i[h]=h,j!=k&&(c.explainCallback("PIECES_CYCLE_CHECK_NEXT_PIECE",[j,k]),o&&f.call(this,k,j))}var h,i=a.service.cloneCube(b),j=d,k=i[d],l=!k,m=[],n=[],o=a.is.edge(d),p=a.is.corner(d);c.explainCallback("PIECES_BEGIN",(o?"edges":p?"corners":"").toUpperCase());var q=!1,r=!1,s=!1,t=!1,u=!1;for(c.explainCallback("PIECES_CYCLE_BEGIN"),c.explainCallback("PIECES_CYCLE_EXAMINE_BUFFER",d),c.explainCallback("PIECES_CYCLE_CHECK_BUFFER_POSITION",k),o&&f.call(this,k),c.explainCallback("END_VOID");!l;){if(c.explainCallback("PIECES_CYCLE_EXAMINE_PIECE",k),j=k,h=a.service.targetOf(j),t=a.is.buffer(j),t&&c.explainCallback("PIECES_CYCLE_BUFFER_FOUND",[j,j!=h]),r=t?j!=h:h!=u||j==h||a.is.median(j)?r:!r,t||h!=u||(u=!1,t=!0,c.explainCallback("PIECES_CYCLE_PLACEHOLDER_FOUND",[j,j!=h&&!a.is.median(j)]),o&&j!=h&&c.explainCallback("PIECES_CYCLE_EDGE_IS_FLIPPED",[j,a.is.median(j)]),g.call(this)),t)if(s=c.service.freeTarget(i,j.length),c.explainCallback("PIECES_CYCLE_CHECK_FREE_TARGET",s.toString()),s!==!1)j=s,h=s,g.call(this,!0);else{if(c.explainCallback("PIECES_CYCLE_ALL_IS_OK"),o&&f.call(this,d,!1,!0),q){if(c.explainCallback("PIECES_PARITY_BEGIN"),c.explainCallback("MEMORIZE_MIDDLE",[o?"M-slice":"R-face",e]),m=m.concat(e),o){if(n.length>0){for(var v in n)n[v]=c.service.opposite(n[v],!0);c.explainCallback("PIECES_PARITY_SWITCH_FLIPPED_MEDIANS",n.toString())}}else c.explainCallback("MEMORIZE_PARITY","PAR"),m=m.concat(["PAR"]);c.explainCallback("END_VOID")}if(o){var w=c.solve.mEdgesUnoriented(n);m=m.concat(w),w.length>0&&c.explainCallback("MEMORIZE_ORIENT_EDGES",w.toString())}l=!0}else g.call(this);c.explainCallback("END_VOID")}return c.explainCallback("END_VOID"),c.explainCallback("PIECES_END",[(o?"edges":p?"corners":"").toUpperCase(),m.toString()]),m},edgesUnoriented:function(){c.explainCallback("UNORIENTED_BEGIN");var a=[];return c.explainCallback("UNORIENTED_WIP"),c.explainCallback("UNORIENTED_END",[a.toString()]),a},mEdgesUnoriented:function(a){var b,c,d,e,f,g,h=[];return(1==a.length||3==a.length||a.length>4)&&console.error("ERROR: wrong array of flipped M-edges: ",a),4==a.length&&(h=["O2U","O2D"]),2==a.length&&(d=a[0].charAt(0),e=a[0].charAt(1),a[1].indexOf(d)>-1&&(c=d),a[1].indexOf(e)>-1&&(c=e),c?h=["O2"+c]:(f=a[0].indexOf("D"),g=a[1].indexOf("D"),f>-1&&(b=Number(!f),c=a[0].charAt(b)),g>-1&&(b=Number(!g),c=a[1].charAt(b)),c&&(h=[c+"2","O2U",c+"2"]))),h}}}}(b),d=function(){var a={TITLE:{p:0,g:0,m:"* SOLVE PROCESS *"},BEGIN:{p:0,g:1,m:"begin memorizing"},END:{p:0,g:-1,m:"end memorizing [%s]"},BEGIN_VOID:{p:3,g:1,m:""},END_VOID:{p:3,g:-1,m:""},UNORIENTED_BEGIN:{p:3,g:1,m:"solve unoriented edges"},UNORIENTED_END:{p:3,g:-1,m:"unoriented pieces: [%s]"},UNORIENTED_WIP:{p:3,g:0,m:"method not yet implemented. will return an empty array."},PIECES_BEGIN:{p:3,g:1,m:"solve unpermuted/unoriented %s"},PIECES_END:{p:1,g:-1,m:"done with %s: [%s]"},PIECES_CYCLE_BEGIN:{p:3,g:1,m:"piece-finding cycle"},PIECES_CYCLE_EXAMINE_BUFFER:{p:3,g:1,m:"examine the buffer [%s]"},PIECES_CYCLE_EXAMINE_PIECE:{p:3,g:1,m:"examine the piece [%s]"},PIECES_CYCLE_CHECK_BUFFER:{p:1,g:0,m:"first thing first: examine the buffer piece: [%s]"},PIECES_CYCLE_BUFFER_FOUND:{p:2,g:0,m:"the piece [%s] is the buffer - flipState: %s"},PIECES_CYCLE_PLACEHOLDER_FOUND:{p:2,g:0,m:"the piece in [%s] position is the buffer - should invert flipState? %s"},PIECES_CYCLE_CHECK_FREE_TARGET:{p:1,g:0,m:"check for the first target to be solved: [%s]"},PIECES_CYCLE_ALL_IS_OK:{p:2,g:0,m:"all pieces are correctly permuted"},PIECES_CYCLE_CHECK_BUFFER_FLIP:{p:1,g:0,m:"check if edge buffer is flipped after all iterations"},PIECES_CYCLE_EDGE_IS_FLIPPED:{p:2,g:0,m:"note that the edge [%s] is flipped - is median? %s"},PIECES_CYCLE_BUFFER_FLIP_STATE:{p:1,g:0,m:"remember to %s the flip state of buffer piece when edges are finished"},PIECES_CYCLE_OPPOSITE_MEDIAN_EDGES:{p:2,g:0,m:"the M-slice is rotated, so switch DB with UF or viceversa: [%s] -> [%s]"},PIECES_CYCLE_OPPOSITE_RIGHT_CORNERS:{p:2,g:0,m:"the R-face is rotated, so switch DRB with URF or viceversa: [%s] -> [%s]"},PIECES_CYCLE_CHECK_NEXT_PIECE:{p:2,g:0,m:"look at the piece in [%s] position: [%s]"},PIECES_CYCLE_CHECK_BUFFER_POSITION:{p:2,g:0,m:"look at the piece in buffer position: [%s]"},PIECES_EDGES_BEGIN:{p:3,g:1,m:"check for flipped median edge [%s]"},PIECES_EDGES_FLIPPED_STATE:{p:2,g:0,m:"flipped state of piece [%s] : %s"},PIECES_EDGES_PREVIOUS_FLIPPED:{p:1,g:0,m:"invert flipped state of [%s] because previous piece [%s] was unoriented"},PIECES_EDGES_BUFFER_FLIPPED:{p:2,g:0,m:"invert flipped state of buffer [%s]"},PIECES_EDGES_ADD_TO_FLIPPED:{p:1,g:0,m:"edge [%s] is flipped, add it to the flipped edge list: [%s]"},PIECES_EDGES_DONT_CHECK_BUFFER:{p:2,g:0,m:"is not the time to check the buffer [%s] flip state"},PIECES_EDGES_IS_MEDIAN:{p:2,g:0,m:"the piece [%s] is part of median slice"},PIECES_EDGES_CHECK_ONLY_MEDIAN:{p:2,g:0,m:"the piece [%s] is not part of median slice"},PIECES_PARITY_BEGIN:{p:3,g:1,m:"parity occurred!"},PIECES_PARITY_SWITCH_FLIPPED_MEDIANS:{p:2,g:0,m:"switch DF with UB and viceversa in the list of flipped edges: [%s]"},MEMORIZE_MIDDLE:{p:0,g:0,m:"** the %s is rotated, for now rotate it back with [%s]"},MEMORIZE_PARITY:{p:0,g:0,m:"** finally do the parity pattern: [%s]"},MEMORIZE_PIECE:{p:0,g:0,m:"** memorize the piece: [%s]"},MEMORIZE_PLACEHOLDER:{p:0,g:0,m:"** memorize the buffer placeholder position: [%s]"},MEMORIZE_ORIENT_EDGES:{p:0,g:0,m:"** memorize the sequence for correctly orient the median edges: [%s]"}};return{constants:a,explain:function(a,b){var c=0,d=0,e=a,f=this.constants[a]; -g=i.join("")}}else d=-1;return{m:g,g:d,p:c}},explainAll:function(a,b){for(var c,d=[],e=0;e=c)){var d=!0,e=d?console.groupCollapsed:console.group;b>0&&a&&e(a),0>=b&&a&&console.log(a),0>b&&console.groupEnd()}}}}(),e=function(a,b){function c(c,d){if(this.$el=a("#"+c),0==this.$el.length)throw new Error("rubik cube not drawn: given ID does not exists in dom");this.options={pieceSize:30,showAxis:!1},this.currentCube=b.service.cloneCube(b.pieces.cube),a.extend(this.options,d)}return c.prototype={willRender:function(){},didRender:function(){},render:function(){this.willRender(),this.didRender()},getCube:function(){return this.getObjectFromCube()},setCube:function(a){this.setCubeFromObject(a)},execute:function(a,b){this.setCubeFromSequence(a,b)},getObjectFromCube:function(){return b.service.cloneCube(this.currentCube)},setCubeFromObject:function(a){this.currentCube=b.service.cloneCube(a),this.render()},setCubeFromSequence:function(b,c){function d(b){a.extend(g,i.rotatedPieces(b)),i.setCubeFromObject(g)}function e(){b.length>0&&setTimeout(function(){d(b[h++]),h0||f>0||g>0?"+":0>e||0>f||0>g?"-":c;return h+i},rotatedPieces:function(a){var c={};if(a){var d,e,f,g=a.charAt(0),h=null;!h&&null!=b.pieces.axis[g]&&(h=b.pieces.pieces),!h&&null!=b.pieces.slices[g]&&(h=b.pieces.slices[g]),!h&&null!=b.pieces.faces[g]&&(h=b.pieces.faces[g]);for(d in h)h.hasOwnProperty(d)&&(e=b.service.targetOf(h[d]),f=this.orientedPiece(e,a),c[e]=b.service.getStickersFromPiece(f,this.currentCube,!0))}return c},orientedPiece:function(a,c){var d,e,f,g,h=this.axisRotation(c),i=b.pieces.axis[h.charAt(0)],j="-"==h.charAt(1)?-1:1,k=a.split(""),l=[];for(d=0;df?i.length-1:f>=i.length?0:f,l.push(i[f]));return l.join("")}},c}(jQuery,b),f=function(a,b,c){function d(a,c){b.call(this,a,c),this.renderOrder=["DBL","DB","DRB","DL","D","DR","DLF","DF","DFR","BL","B","BR","L","R","FL","F","FR","ULB","UB","UBR","UL","U","UR","UFL","UF","URF"],this.renderOptions={backfaces:!1,highlights:[]},this.iso={container:this.$el,engine:new f},this.iso.engine.init(this.iso.container,{worldSizeWidth:400,worldSizeHeight:300}),this.iso.layer=this.iso.engine.addLayer("cube",!0),this.iso.console=this.iso.engine.addLayer("console");var d=this.iso.console.addChild(new j("cubeletInfo"));d._position=new g(-200,120),d.setFont("Open Sans",20),this.render()}function e(a,b){return a.length>b?a[b]:a[a.length-1]}var f=c.core.Engine,g=c.core.Point,h=c.display.Sprite,i=c.display.Shape,j=c.display.Text;return d.prototype=Object.create(b.prototype),d.prototype.willRender=function(){},d.prototype.didRender=function(){this.iso.layer._render(),this.options.showAxis&&this.iso.engine.drawUtils.axis(this.iso.layer,200)},d.prototype.render=function(a){var b;return this.willRender(),this.renderOrder.forEach(function(c){0==this.renderOptions.highlights.length?(b=this.currentCube[c],(!a||a.indexOf(c)>-1)&&this.drawPiece(c,b,!1,this.renderOptions.backfaces)):(b=this.renderOptions.highlights.indexOf(c)>-1?"light":"grey",this.drawPiece(c,b,!0,this.renderOptions.backfaces))}.bind(this)),this.didRender(),!0},d.prototype.getImage=function(){return this.iso.layer.getCanvas().toDataURL()},d.prototype.backfaceState=function(){return this.renderOptions.backfaces},d.prototype.backfaceToggle=function(a){this.toggleRenderBackFaces(a)},d.prototype.highlight=function(a){this.highlightPieces(a)},d.prototype.highlightPieces=function(b){var c=[];b&&b.forEach(function(b){c.push(a.service.targetOf(b))}.bind(this)),this.renderOptions.highlights=c,this.render()},d.prototype.toggleRenderBackFaces=function(a){this.renderOptions.backfaces=null!=a?a:!this.renderOptions.backfaces,this.render()},d.prototype.drawPiece=function(b,c,d,e){c||(c=b);for(var f,h,i=this.options.pieceSize,j=new g(-i/2,-i/2,-i/2),k=[],l=[b.indexOf("U"),b.indexOf("R"),b.indexOf("F"),b.indexOf("D"),b.indexOf("B"),b.indexOf("L")],m=0;m=3)&&(h={name:f,color:f?d?a.colors[c]:a.colors[f]:null}),k.push(h);var n=-1!=b.indexOf("D")?-1:-1!=b.indexOf("U")?1:0,o=-1!=b.indexOf("F")?1:-1!=b.indexOf("B")?-1:0,p=-1!=b.indexOf("L")?-1:-1!=b.indexOf("R")?1:0,q=!0;this.iso.layer._children["_piece_"+b]||this.addCube(b,j.add(new g(i*p,i*o,i*n)),i,q),this.drawCube(b,c,i,{fills:k,stroke:a.colors.core},q)},d.prototype.addCube=function(a,b,c,d){var e=new h("_piece_"+a);e.set("position",a),d&&(e.addChild(new i("_face_D")).set("position","D")._position=b.add(new g(0,0,0)),e.addChild(new i("_face_B")).set("position","B")._position=b.add(new g(0,0,0)),e.addChild(new i("_face_L")).set("position","L")._position=b.add(new g(0,0,0))),e.addChild(new i("_face_U")).set("position","U")._position=b.add(new g(0,0,c)),e.addChild(new i("_face_R")).set("position","R")._position=b.add(new g(c,0,0)),e.addChild(new i("_face_F")).set("position","F")._position=b.add(new g(0,c,0)),this.iso.layer.addChild(e)},d.prototype.drawCube=function(a,b,c,d,f){var g=this.iso.layer._children["_piece_"+a];if(g){g.set("sticker",b);var h=d.fills.map(function(a){return a&&a.name}),i={fills:d.fills.map(function(a){return a&&a.color}),color:d.stroke};f&&i.fills&&6==i.fills.length&&(this.setShape(g._children._face_D,e(h,3),"get3DPolygonSquare",c,i.fills?e(i.fills,3):null,i.color),this.setShape(g._children._face_B,e(h,4),"get3DPolygonSquareLeft",c,i.fills?e(i.fills,4):null,i.color),this.setShape(g._children._face_L,e(h,5),"get3DPolygonSquareRight",c,i.fills?e(i.fills,5):null,i.color)),this.setShape(g._children._face_U,e(h,0),"get3DPolygonSquare",c,i.fills?e(i.fills,0):null,i.color),this.setShape(g._children._face_R,e(h,1),"get3DPolygonSquareRight",c,i.fills?e(i.fills,1):null,i.color),this.setShape(g._children._face_F,e(h,2),"get3DPolygonSquareLeft",c,i.fills?e(i.fills,2):null,i.color)}},d.prototype.setShape=function(a,b,c,d,e,f){e?a.setRenderInfo(this.iso.engine.drawUtils[c](d),{strokeColor:null==e?null:f,fillColor:e,strokeSize:1}):a.setRenderInfo(null),a.set("sticker",b)},d}(b,e,a),g=function(a,b,c,d,e){var f={};return f.cube={},f.cube.RubikCube=a,f.cube.RubikCubeIso=b,f["static"]={},f["static"].RubikSolver=c,f["static"].RubikTeacher=d,f["static"].RubikUtils=e,f}(e,f,c,d,b);return g}(); \ No newline at end of file +f&&(c=f.p,d=f.g,e=f.m);var g,h,i;if(e){if(g=e,b)if("string"==typeof b)g=e.replace(/%s/g,b);else{i=e.split("%s");for(h in i)i.hasOwnProperty(h)&&null!=b[h]&&(i[h]=i[h]+b[h]);g=i.join("")}}else d=-1;return{m:g,g:d,p:c}},explainAll:function(a,b){for(var c,d=[],e=0;e=c)){var d=!0,e=d?console.groupCollapsed:console.group;b>0&&a&&e(a),0>=b&&a&&console.log(a),0>b&&console.groupEnd()}}}}(),e=function(a,b){function c(c,d){if(this.$el=a("#"+c),0==this.$el.length)throw new Error("rubik cube not drawn: given ID does not exists in dom");this._options={pieceSize:30,showAxis:!1},this._currentCube=b.service.cloneCube(b.pieces.cube),a.extend(this._options,d)}function d(){return b.service.cloneCube(this._currentCube)}function e(a){this._currentCube=b.service.cloneCube(a),this.render()}function f(b,c){function f(b){a.extend(i,k.rotatedPieces(b)),e.call(k,i)}function g(){b.length>0&&setTimeout(function(){f(b[j++]),j0||f>0||g>0?"+":0>e||0>f||0>g?"-":c;return h+i},rotatedPieces:function(a){var c={};if(a){var d,e,f,g=a.charAt(0),h=null;!h&&null!=b.pieces.axis[g]&&(h=b.pieces.pieces),!h&&null!=b.pieces.slices[g]&&(h=b.pieces.slices[g]),!h&&null!=b.pieces.faces[g]&&(h=b.pieces.faces[g]);for(d in h)h.hasOwnProperty(d)&&(e=b.service.targetOf(h[d]),f=this.orientedPiece(e,a),c[e]=b.service.getStickersFromPiece(f,this._currentCube,!0))}return c},orientedPiece:function(a,c){var d,e,f,g,h=this.axisRotation(c),i=b.pieces.axis[h.charAt(0)],j="-"==h.charAt(1)?-1:1,k=a.split(""),l=[];for(d=0;df?i.length-1:f>=i.length?0:f,l.push(i[f]));return l.join("")}},c}(jQuery,b),f=function(a,b,c){function d(a,c){b.call(this,a,c),this._renderOptions={order:["DBL","DB","DRB","DL","D","DR","DLF","DF","DFR","BL","B","BR","L","R","FL","F","FR","ULB","UB","UBR","UL","U","UR","UFL","UF","URF"],backfaces:!1,highlights:[],highlightColored:!1},this.iso={container:this.$el,engine:new l},this.iso.engine.init(this.iso.container,{worldSizeWidth:400,worldSizeHeight:300}),this.iso.layer=this.iso.engine.addLayer("cube",!0),this.iso.console=this.iso.engine.addLayer("console");var d=this.iso.console.addChild(new p("cubeletInfo"));d._position=new m(-200,120),d.setFont("Open Sans",20),this.render()}function e(a){this._renderOptions.backfaces=null!=a?a:!this._renderOptions.backfaces,this.render()}function f(b){var c=[];b&&b.forEach(function(b){c.push(a.service.targetOf(b))}.bind(this)),this._renderOptions.highlights=c,this.render()}function g(b,c,d,e){c||(c=b);for(var f,g,j=this._options.pieceSize,k=new m(-j/2,-j/2,-j/2),l=[],n=[b.indexOf("U"),b.indexOf("R"),b.indexOf("F"),b.indexOf("D"),b.indexOf("B"),b.indexOf("L")],o=0;o=3)&&(g={name:f,color:f?d?a.colors[c]:a.colors[f]:null}),l.push(g);var p=-1!=b.indexOf("D")?-1:-1!=b.indexOf("U")?1:0,q=-1!=b.indexOf("F")?1:-1!=b.indexOf("B")?-1:0,r=-1!=b.indexOf("L")?-1:-1!=b.indexOf("R")?1:0,s=!0;this.iso.layer._children["_piece_"+b]||h.call(this,b,k.add(new m(j*r,j*q,j*p)),j,s),i.call(this,b,c,j,{fills:l,stroke:a.colors.core},s)}function h(a,b,c,d){var e=new n("_piece_"+a);e.set("position",a),d&&(e.addChild(new o("_face_D")).set("position","D")._position=b.add(new m(0,0,0)),e.addChild(new o("_face_B")).set("position","B")._position=b.add(new m(0,0,0)),e.addChild(new o("_face_L")).set("position","L")._position=b.add(new m(0,0,0))),e.addChild(new o("_face_U")).set("position","U")._position=b.add(new m(0,0,c)),e.addChild(new o("_face_R")).set("position","R")._position=b.add(new m(c,0,0)),e.addChild(new o("_face_F")).set("position","F")._position=b.add(new m(0,c,0)),this.iso.layer.addChild(e)}function i(a,b,c,d,e){var f=this.iso.layer._children["_piece_"+a];if(f){f.set("sticker",b);var g=d.fills.map(function(a){return a&&a.name}),h={fills:d.fills.map(function(a){return a&&a.color}),color:d.stroke};e&&h.fills&&6==h.fills.length&&(j.call(this,f._children._face_D,k(g,3),"get3DPolygonSquare",c,h.fills?k(h.fills,3):null,h.color),j.call(this,f._children._face_B,k(g,4),"get3DPolygonSquareLeft",c,h.fills?k(h.fills,4):null,h.color),j.call(this,f._children._face_L,k(g,5),"get3DPolygonSquareRight",c,h.fills?k(h.fills,5):null,h.color)),j.call(this,f._children._face_U,k(g,0),"get3DPolygonSquare",c,h.fills?k(h.fills,0):null,h.color),j.call(this,f._children._face_R,k(g,1),"get3DPolygonSquareRight",c,h.fills?k(h.fills,1):null,h.color),j.call(this,f._children._face_F,k(g,2),"get3DPolygonSquareLeft",c,h.fills?k(h.fills,2):null,h.color)}}function j(a,b,c,d,e,f){e?a.setRenderInfo(this.iso.engine.drawUtils[c](d),{strokeColor:null==e?null:f,fillColor:e,strokeSize:1}):a.setRenderInfo(null),a.set("sticker",b)}function k(a,b){return a.length>b?a[b]:a[a.length-1]}var l=c.core.Engine,m=c.core.Point,n=c.display.Sprite,o=c.display.Shape,p=c.display.Text;return d.prototype=Object.create(b.prototype),d.prototype.willRender=function(){},d.prototype.didRender=function(){this.iso.layer._render(),this._options.showAxis&&this.iso.engine.drawUtils.axis(this.iso.layer,200)},d.prototype.render=function(a){var b,c=this._renderOptions.highlights,d=this._renderOptions.highlightColored;return this.willRender(),this._renderOptions.order.forEach(function(e){0==c.length?(b=this._currentCube[e],(!a||a.indexOf(e)>-1)&&g.call(this,e,b,!1,this._renderOptions.backfaces)):(b=c.indexOf(e)>-1?d?this._currentCube[e]:"light":"grey",g.call(this,e,b,"grey"==b||"light"==b,this._renderOptions.backfaces))}.bind(this)),this.didRender(),!0},d.prototype.getImage=function(){return this.iso.layer.getCanvas().toDataURL()},d.prototype.backfaceState=function(){return this._renderOptions.backfaces},d.prototype.backfaceToggle=function(a){e.call(this,a)},d.prototype.highlight=function(a){f.call(this,a)},d.prototype.highlightColor=function(a){this._renderOptions.highlightColored=a,this.render()},d}(b,e,a),g=function(a,b,c,d,e){var f={};return f.cube={},f.cube.RubikCube=a,f.cube.RubikCubeIso=b,f["static"]={},f["static"].RubikSolver=c,f["static"].RubikTeacher=d,f["static"].RubikUtils=e,f}(e,f,c,d,b);return g}(); \ No newline at end of file diff --git a/src/cube/RubikCube.js b/src/cube/RubikCube.js index bef9a29..e51eb8b 100644 --- a/src/cube/RubikCube.js +++ b/src/cube/RubikCube.js @@ -14,21 +14,21 @@ var RubikCube = (function($, RubikUtils){ this.$el = $('#'+ID); if(this.$el.length==0) throw new Error('rubik cube not drawn: given ID does not exists in dom'); - this.options = { + this._options = { pieceSize: 30, showAxis: false }; - this.currentCube = RubikUtils.service.cloneCube(RubikUtils.pieces.cube); + this._currentCube = RubikUtils.service.cloneCube(RubikUtils.pieces.cube); - $.extend(this.options,options); + $.extend(this._options,options); } /** * RubikCube prototype * - * @type {{willRender: Function, didRender: Function, render: Function, getCube: Function, setCube: Function, execute: Function, getObjectFromCube: Function, setCubeFromObject: Function, setCubeFromSequence: Function, getPiece: Function, setPiece: Function, setPieceFromStickers: Function, updateColors: Function, axisRotation: Function, rotatedPieces: Function, orientedPiece: Function}} + * @type {{willRender: Function, didRender: Function, render: Function, getCube: Function, setCube: Function, execute: Function, getPiece: Function, setPiece: Function, updateColors: Function, axisRotation: Function, rotatedPieces: Function, orientedPiece: Function}} */ RubikCube.prototype = { @@ -38,9 +38,9 @@ var RubikCube = (function($, RubikUtils){ willRender: function(){}, didRender: function(){}, - render: function(piecesToRender){ + render: function(pieces){ this.willRender(); - //do something with piecesToRender + //do something with pieces this.didRender(); }, @@ -49,59 +49,24 @@ var RubikCube = (function($, RubikUtils){ ******************************/ getCube: function(){ - return this.getObjectFromCube(); + return getObjectFromCube.call(this); }, setCube: function(c){ - this.setCubeFromObject(c); + setCubeFromObject.call(this,c); }, execute: function(s,d){ - this.setCubeFromSequence(s,d); - }, - - // ** CUBE getters/setters ** // - getObjectFromCube: function(){ - return RubikUtils.service.cloneCube(this.currentCube); - }, - setCubeFromObject: function(cube){ - this.currentCube = RubikUtils.service.cloneCube(cube); - this.render(); - }, - setCubeFromSequence: function(sequence,duration){ - var C = this.getObjectFromCube(); - var move,m=0; - var _this = this; - - function iteration(move){ - $.extend(C, _this.rotatedPieces(move)); - _this.setCubeFromObject(C); - } - function timeout(){ - if(sequence.length>0){ - setTimeout(function(){ - iteration(sequence[m++]); - if(m0){ + setTimeout(function(){ + iteration(sequence[m++]); + if(m-1) && this.drawPiece(piece,stickers,false,this.renderOptions.backfaces); + this._renderOptions.order.forEach(function(piece){ + if(highlights.length==0){ + stickers = this._currentCube[piece]; + (!piecesToRender || piecesToRender.indexOf(piece)>-1) && drawPiece.call(this,piece,stickers,false,this._renderOptions.backfaces); }else{ - stickers = this.renderOptions.highlights.indexOf(piece)>-1 ? 'light' : 'grey'; - this.drawPiece(piece,stickers,true,this.renderOptions.backfaces); + stickers = highlights.indexOf(piece)>-1 ? (hl_colored ? this._currentCube[piece] : 'light') : 'grey'; + drawPiece.call(this,piece,stickers,(stickers=='grey'||stickers=='light'),this._renderOptions.backfaces); } }.bind(this)); this.didRender(); @@ -83,33 +86,38 @@ var RubikCubeIso = (function(RubikUtils, RubikCube, GraphicEngine){ * *******************************/ RubikCubeISO.prototype.getImage = function() { return this.iso.layer.getCanvas().toDataURL(); }; - RubikCubeISO.prototype.backfaceState = function() { return this.renderOptions.backfaces; }; - RubikCubeISO.prototype.backfaceToggle = function(f){ this.toggleRenderBackFaces(f); }; - RubikCubeISO.prototype.highlight = function(p){ this.highlightPieces(p); }; + RubikCubeISO.prototype.backfaceState = function() { return this._renderOptions.backfaces; }; + RubikCubeISO.prototype.backfaceToggle = function(f){ toggleRenderBackFaces.call(this,f); }; + RubikCubeISO.prototype.highlight = function(p){ highlightPieces.call(this,p); }; + RubikCubeISO.prototype.highlightColor = function(t){ this._renderOptions.highlightColored=t;this.render(); }; + + /* ******************************* + * PRIVATE METHODS + * *******************************/ // ** RENDERING METHODS ** // - RubikCubeISO.prototype.highlightPieces = function(pieces){ + function toggleRenderBackFaces(forceVal) { + this._renderOptions.backfaces = forceVal!=null?forceVal:!this._renderOptions.backfaces; + this.render(); + } + function highlightPieces(pieces) { var targets=[]; if(pieces){ pieces.forEach(function(piece){ targets.push(RubikUtils.service.targetOf(piece)); }.bind(this)); } - this.renderOptions.highlights = targets; + this._renderOptions.highlights = targets; this.render(); - }; - RubikCubeISO.prototype.toggleRenderBackFaces = function(forceVal){ - this.renderOptions.backfaces = forceVal!=null?forceVal:!this.renderOptions.backfaces; - this.render(); - }; - + } + // ** DRAWING METHODS ** // - - RubikCubeISO.prototype.drawPiece = function(position,stickers,fullColor,drawBack){ + + function drawPiece(position,stickers,fullColor,drawBack) { stickers || (stickers=position); - var size = this.options.pieceSize; + var size = this._options.pieceSize; var origin = new Point(-size/2,-size/2,-size/2); var fills = [], @@ -143,11 +151,11 @@ var RubikCubeIso = (function(RubikUtils, RubikCube, GraphicEngine){ var isFull = true; if(!this.iso.layer._children['_piece_'+position]) - this.addCube(position, origin.add(new Point(size*px,size*py,size*pz)), size, isFull); + addCube.call(this,position, origin.add(new Point(size*px,size*py,size*pz)), size, isFull); - this.drawCube(position, stickers, size, {fills:fills,stroke:RubikUtils.colors.core}, isFull); - }; - RubikCubeISO.prototype.addCube = function(name, origin, size, full_cube) { + drawCube.call(this,position, stickers, size, {fills:fills,stroke:RubikUtils.colors.core}, isFull); + } + function addCube(name, origin, size, full_cube) { var cube = new Sprite('_piece_'+name); cube.set('position',name); @@ -163,8 +171,8 @@ var RubikCubeIso = (function(RubikUtils, RubikCube, GraphicEngine){ this.iso.layer.addChild(cube); - }; - RubikCubeISO.prototype.drawCube = function(name, pieceName, size, colors, full_cube) { + } + function drawCube(name, pieceName, size, colors, full_cube) { var cube = this.iso.layer._children['_piece_'+name]; if(!cube) return; @@ -178,16 +186,16 @@ var RubikCubeIso = (function(RubikUtils, RubikCube, GraphicEngine){ }; if(full_cube && style.fills && style.fills.length==6) { - this.setShape( cube._children['_face_D'], arrayLastValue(names, 3), 'get3DPolygonSquare' , size, !style.fills ? null : arrayLastValue(style.fills, 3), style.color ); - this.setShape( cube._children['_face_B'], arrayLastValue(names, 4), 'get3DPolygonSquareLeft' , size, !style.fills ? null : arrayLastValue(style.fills, 4), style.color ); - this.setShape( cube._children['_face_L'], arrayLastValue(names, 5), 'get3DPolygonSquareRight', size, !style.fills ? null : arrayLastValue(style.fills, 5), style.color ); + setShape.call( this, cube._children['_face_D'], arrayLastValue(names, 3), 'get3DPolygonSquare' , size, !style.fills ? null : arrayLastValue(style.fills, 3), style.color ); + setShape.call( this, cube._children['_face_B'], arrayLastValue(names, 4), 'get3DPolygonSquareLeft' , size, !style.fills ? null : arrayLastValue(style.fills, 4), style.color ); + setShape.call( this, cube._children['_face_L'], arrayLastValue(names, 5), 'get3DPolygonSquareRight', size, !style.fills ? null : arrayLastValue(style.fills, 5), style.color ); } - this.setShape( cube._children['_face_U'], arrayLastValue(names, 0), 'get3DPolygonSquare' , size, !style.fills ? null : arrayLastValue(style.fills, 0), style.color ); - this.setShape( cube._children['_face_R'], arrayLastValue(names, 1), 'get3DPolygonSquareRight', size, !style.fills ? null : arrayLastValue(style.fills, 1), style.color ); - this.setShape( cube._children['_face_F'], arrayLastValue(names, 2), 'get3DPolygonSquareLeft' , size, !style.fills ? null : arrayLastValue(style.fills, 2), style.color ); + setShape.call( this, cube._children['_face_U'], arrayLastValue(names, 0), 'get3DPolygonSquare' , size, !style.fills ? null : arrayLastValue(style.fills, 0), style.color ); + setShape.call( this, cube._children['_face_R'], arrayLastValue(names, 1), 'get3DPolygonSquareRight', size, !style.fills ? null : arrayLastValue(style.fills, 1), style.color ); + setShape.call( this, cube._children['_face_F'], arrayLastValue(names, 2), 'get3DPolygonSquareLeft' , size, !style.fills ? null : arrayLastValue(style.fills, 2), style.color ); - }; - RubikCubeISO.prototype.setShape = function(child, value, squareType, size, fill, stroke) { + } + function setShape(child, value, squareType, size, fill, stroke) { if(!fill) child.setRenderInfo( null ); @@ -196,11 +204,7 @@ var RubikCubeIso = (function(RubikUtils, RubikCube, GraphicEngine){ child.set('sticker',value); - }; - - /* ******************************* - * PRIVATE METHODS - * *******************************/ + } function arrayLastValue(array,index) { return array.length>index ? array[index] : array[array.length-1]; diff --git a/src/static/RubikUtils.js b/src/static/RubikUtils.js index de3b0b3..6d28cda 100644 --- a/src/static/RubikUtils.js +++ b/src/static/RubikUtils.js @@ -30,23 +30,29 @@ var RubikUtils = (function(){ /* ################### ORIENTATION PATTERNS ################### */ /* -- orient edges -- */ - p_O4E: " (M'U)4 (MU)4 ", + p_O4U: " (M'U)4 (MU)4 ", + p_O4D: " (M'D)4 (MD)4 ",// x2 [O4U] x2 + p_O4F: " (M'F)4 (MF)4 ",// x [O4U] x' + p_O4B: " (M'B)4 (MB)4 ",// x' [O4U] x p_O2U: " (M'U)3 U (MU)3 U ", - p_O2D: " (M'D)3 D (MD)3 D ", - p_O2F: " (M'F)3 F (MF)3 F ", - p_O2B: " (M'B)3 B (MB)3 B ", + p_O2D: " (M'D)3 D (MD)3 D ",// x2 [O2U] x2 + p_O2F: " (M'F)3 F (MF)3 F ",// x [O2U] x' + p_O2B: " (M'B)3 B (MB)3 B ",// x' [O2U] x p_O6L: " (R'FRU)5 ", p_O6R: " ([O6L])m ", /* -- orient corners -- */ p_CW2: " (U'RU) R' (U'RU) ", p_CC2: " ([CW2])i ", - p_CW3: " ((UR)'UR)2 ", + p_CW3: " ((UR)n UR)2 ", p_CC3: " ([CW3])i ", /* -- parity -- */ p_PTJ: " (L'U2) LU (L'U2) (RU') L (RU')i ", - p_PAR: " (U'F2) [PTJ] (U'F2)i ", + p_PTN: " ((L'UR') U2 (L'UR')n)2 U ", + p_PRJ: " (U'F2) [PTJ] (U'F2)i ", + p_PRN: " (F2y) [PTN] (F2y)i ", + p_PAR: " [PRJ] ", /* ################### EDGES PERMUTATIONS ################### */ @@ -55,9 +61,9 @@ var RubikUtils = (function(){ s_UF: " (U2 M')2 ", s_DB: " ([UF])i ", /* -- right oriented -- */ - s_UR: " R'U RU' ", + s_UR: " R' [FR] ", s_DR: " U R RU' ", - s_FR: " URU' ", + s_FR: " U RU' ", s_BR: " ([FR])i ", /* -- left oriented -- */ s_UL: " ([UR])m ", @@ -70,15 +76,15 @@ var RubikUtils = (function(){ s_FU: " [UF] ", s_BD: " [DB] ", /* -- right not oriented -- */ - s_RU: " x' ([BR])' ", - s_RD: " x' ([FR])' ", - s_RF: " x' ([DR])' ", - s_RB: " x' ([UR])' ", + s_RU: " x' ([BR])n ", + s_RD: " x' ([FR])n ", + s_RF: " x' ([DR])n ", + s_RB: " x' ([UR])n ", /* -- left not oriented -- */ - s_LU: " x' (([BR])')m ", - s_LD: " x' (([FR])')m ", - s_LF: " x' (([DR])')m ", - s_LB: " x' (([UR])')m ", + s_LU: " x' (([BR])n)m ", + s_LD: " x' (([FR])n)m ", + s_LF: " x' (([DR])n)m ", + s_LB: " x' (([UR])n)m ", /* ################### CORNERS PERMUTATIONS ################### */ @@ -87,13 +93,13 @@ var RubikUtils = (function(){ s_URF: " U' (R F' RM' U R2 U') (MR' F R U R2') ",//" U' R F' L x U R2 U' x' L' F R U R2 ", s_DRB: " ([URF])i ", /* -- left oriented -- */ - s_ULB: " (LU)' (LU)", - s_UFL: " L U'L' U [ULB] ",// L [LBU] [ULB] + s_ULB: " (LU)n (LU) ", + s_UFL: " L [LBU] [ULB] ", s_DLF: " U' L2 U ", s_DBL: " [DLF] [ULB] ", /* -- UBR not oriented -- */ - s_BRU: " (U'L'U) L (U'L'U) ",// [LBU] L [LBU] + s_BRU: " [LBU] L [LBU] ", s_RUB: " ([BRU])i ", /* -- URF not oriented -- */ s_RFU: " (F'R) (UR2U') R' (FR) (UR2U') R ", @@ -101,18 +107,19 @@ var RubikUtils = (function(){ /* -- DRB not oriented -- */ s_RBD: " R'UR2U'R'F'RUR2U'R'F ", s_BDR: " RUR' DL2 x2 U'RU L2x2 U'D'R ", + /* -- ULB not oriented -- */ s_LBU: " (U'L'U) ", s_BUL: " y RUR2U'R' y' ", /* -- UFL not oriented -- */ - s_FLU: " R' (ULU') ", - s_LUF: " L' (U'L'U) ",// L' [LBU] + s_FLU: " (R [LBU])n ", + s_LUF: " L' [LBU] ", /* -- DLF not oriented -- */ - s_LFD: " L2 (U'L'U) ",// L2 [LBU] - s_FDL: " (U'L'U) L' (U'LU)",// [LBU] L' ([LBU])' + s_LFD: " L2 [LBU] ", + s_FDL: " [LBU] ([LBU] L)i ", /* -- DBL not oriented -- */ - s_BLD: " (U'LU) ",// ([LBU])i - s_LDB: " L (U'L'U) "// L [LBU] + s_BLD: " ([LBU])i ", + s_LDB: " L [LBU] " }, @@ -223,7 +230,7 @@ var RubikUtils = (function(){ modifier : function(m) { return (/^[2i'\-\+]$/).test(m); }, /** - * Returns TRUE if the given string is actually a single rotation + * Returns TRUE if the given string is actually a single rotation (face, slice or axis followed by a modifier) * * @param m {String} the move to search for * @returns {Boolean} true if the move is a rotation @@ -245,7 +252,7 @@ var RubikUtils = (function(){ * @param m {String} the pattern to search for * @returns {Boolean} true if the oriented piece is a property of RubikHelper.patterns */ - pattern : function(m) { return (/^(o2[udfb]|o4e|o6[lr]|c[cw][23]|ptj|par)$/i).test(m); }, + pattern : function(m) { return (/^(o[24][udfb]|o6[lr]|c[cw][23]|p[tr][jn]|par)$/i).test(m); }, /** * Returns TRUE if the given string is actually a cube's piece (edge or corner) @@ -311,7 +318,7 @@ var RubikUtils = (function(){ * @param but {String|Array} the move/moves to be NOT accepted * @returns {Boolean} true if the move is accepted */ - accepted : function(move, but, only) { + accepted : function(move, only, but) { var doMe = ((!only && !but) || (only=='' && but=='')); if(only && typeof(only)=='string') doMe = (only.length==1 && only==move.charAt(0)); if(only && only instanceof Array) doMe = (only.indexOf(move)>-1); @@ -745,10 +752,10 @@ var RubikUtils = (function(){ * parseMoves('U2FitriX',true,true,true) -> 'U+,U+,F-,r-,x+' * * you can also use parenthesis for grouping and square brackets for pieces - * eg. [dr] d'b (lu)' u2 (r'bu)4 [ulb] + * eg. [dr] d'b (lu)n u2 (r'bu)4 [ulb] * eg. ((RU[BR])m)i F [LB] (F'[LB])' * - * note: use (...)m to mirror, (...)i to invert and (...)' to negative the whole parenthesis content + * note: use ()m to mirror, ()i to invert and ()n or ()' to negative the whole parenthesis content * * @param sequence {String} the user typed sequence of moves * @param uncollapse {Boolean} whether double moves should be converted in a pair of positive single moves (F2 -> F+,F+) @@ -756,7 +763,7 @@ var RubikUtils = (function(){ * @param keepCase {Boolean} whether the returned string should contains lowercase face rotations (only if caseSensitive:true) * @returns {Array} the array of simple face rotations */ - moves: function(sequence, uncollapse, caseSensitive, keepCase) { + _moves: function(sequence, uncollapse, caseSensitive, keepCase) { var final,seq = []; var arr = RubikUtils.clear.all(sequence).split(''); var last,next,move,sign; @@ -795,7 +802,7 @@ var RubikUtils = (function(){ if(RubikUtils.is.piece(piece)||RubikUtils.is.pattern(piece)){ var prefix = RubikUtils.is.piece(piece)?'s_':RubikUtils.is.pattern(piece)?'p_':''; var moves = RubikUtils.patterns[prefix+piece]; - moves && addGroupToList(RubikUtils.parse.moves(moves)); + moves && addGroupToList(RubikUtils.parse._moves(moves)); } piece=false; @@ -858,8 +865,8 @@ var RubikUtils = (function(){ if(move.length==1) move+='+'; move = RubikUtils.is.piece(move)||RubikUtils.is.pattern(move) ? move.toUpperCase() : - RubikUtils.is.rotation(move) ? RubikUtils.clear.adjustCase(move.charAt(0))+move.charAt(1) : - null; + RubikUtils.is.rotation(move) ? RubikUtils.clear.adjustCase(move.charAt(0))+move.charAt(1) : + null; move && seq.push(move); } @@ -868,6 +875,74 @@ var RubikUtils = (function(){ final = uncollapse ? RubikUtils.clear.uncollapseSequence(seq) : RubikUtils.clear.collapseSequence(seq); return final; + }, + + moves: function(sequence){ + var p, mod, pref, seq = []; + var g = -1, group, groups = []; + var res, ro, rx = /(\()|(?:(([udfblrmesxyz])(?:([-i'])|(2))?)|(\[((?:(?:[ud][fb]|[fb][ud])(?:[lr]?)|(?:[fb][lr]|[lr][fb])(?:[ud]?)|(?:[ud][lr]|[lr][ud])(?:[fb]?))|(?:o[24][udfb]|o6[lr]|c[cw][23]|p[tr][jn]|par))]))|(\)([0-9min'])?)/ig; + + function pushMove(m) { (g>-1 ? groups[g] : seq).push(m); } + function concatMoves(m) { (g>-1 ? groups[g]=groups[g].concat(m) : seq=seq.concat(m)); } + + while((res = rx.exec(sequence)) !== null){ + ro = { + rotation: { + match: res[2], + move: res[3] && RubikUtils.clear.adjustCase(res[3]), + sign: res[4], + double: res[5] + }, + piece: { + match: res[6], + name: res[7] && res[7].toUpperCase() + }, + group: { + match: res[1], + end: res[8], + mod: res[9] + } + }; + + //startGroup + if(ro.group.match){ + groups[++g] = []; + }else + + //isRotation + if(ro.rotation.match){ + p = ro.rotation.move + (ro.rotation.sign?'-':'+'); + ro.rotation.double && pushMove(p); + pushMove(p); + }else + + //isPiece + if(ro.piece.match){ + pref = RubikUtils.is.piece(ro.piece.name) ? 's_' : RubikUtils.is.pattern(ro.piece.name) ? 'p_' : null; + pref && concatMoves(RubikUtils.parse.moves(RubikUtils.patterns[pref+ro.piece.name])); + }else + + //endGroup + if(ro.group.end){ + mod = ro.group.mod; + group = groups[g]; + + if(mod) + if(mod==Number(mod)) + group = RubikUtils.math.multiply(group,Number(mod)); + else if(mod=='-'||mod=='\''||mod=='n') + group = RubikUtils.math.negativePattern(group); + else if(mod.toLowerCase()=='m') + group = RubikUtils.math.mirrorPattern(group); + else if(mod.toLowerCase()=='i') + group = RubikUtils.math.inversePattern(group); + + g--; + concatMoves(group); + } + } + + return RubikUtils.clear.collapseSequence(seq); } }, @@ -884,13 +959,13 @@ var RubikUtils = (function(){ * @returns {String} */ all: function(seq) { - return seq.replace(/[^udfblrmesxyz2-9i'\-\+\(\)\[\]_oecwptja]+/ig,''); + return seq.replace(/[^udfblrmesxyz2-9i'\-\+\(\)\[\]ocwptjna]+/ig,''); }, /** * Returns a comma separated string with only accepted moves and patterns (faces, slices, axis, pieces, orient, parity) * It accepts all from clear.sequence, plus - * patterns: _o2u,_o2d,_o2f,_o2b,_o4e,_o6l,_o6r,_cw2,_cc2,_cw3,_cc3,_ptj,_par + * patterns: o2u, o2d, o2f, o2b, o4u, o4d, o4f, o4b, o6l, o6r, cw2, cc2, cw3, cc3, ptj, ptn, par, prn * * @param seq {String} * @returns {String} @@ -898,7 +973,7 @@ var RubikUtils = (function(){ pieces: function(seq) { seq = seq.replace(/[i']+/ig,'-'); seq = seq.replace(/[,;\.\n\r ]+/g,','); - seq = seq.replace(/[^udfblrmesxyz2\-\+,_oecwptja346]+/ig,''); + seq = seq.replace(/[^udfblrmesxyz2\-\+,ocwptjna346]+/ig,''); return seq; }, @@ -915,7 +990,7 @@ var RubikUtils = (function(){ */ sequence: function(seq) { seq = seq.replace(/[i']+/ig,'-'); - seq = seq.replace(/[^udfblrmesxyz2i'\-\+]+/ig,''); + seq = seq.replace(/[^udfblrmesxyz2\-\+]+/ig,''); return seq; }, @@ -944,8 +1019,8 @@ var RubikUtils = (function(){ adjustCase: function(move) { return ( RubikUtils.is.face(move)||RubikUtils.is.slice(move) ? move.toUpperCase(): - RubikUtils.is.axis(move) ? move.toLowerCase(): - move + RubikUtils.is.axis(move) ? move.toLowerCase(): + move ); },