chess-rules
Advanced tools
Comparing version 0.10.2 to 0.11.0
@@ -1,2 +0,2 @@ | ||
!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.chessRules=a()}}(function(){var a;return function b(a,c,d){function e(g,h){if(!c[g]){if(!a[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};a[g][0].call(k.exports,function(b){var c=a[g][1][b];return e(c?c:b)},k,k.exports,b,a,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){function d(a){var b=function c(){return e.apply(c,arguments)};return b._styles=a,b.__proto__=n,b}function e(){var a=arguments,b=a.length,c=0!==b&&String(arguments[0]);if(b>1)for(var d=1;b>d;d++)c+=" "+a[d];if(!h.enabled||!c)return c;for(var e=this._styles,f=e.length;f--;){var g=i[e[f]];c=g.open+c.replace(g.closeRe,g.open)+g.close}return c}function f(a){for(var b in a)!function(b){h[b]=function(c){if("object"==typeof a[b]){var d=c;for(var e in a[b])d=h[a[b][e]](d);return d}return h[a[b]](c)}}(b)}function g(){var a={};return Object.keys(m).forEach(function(b){a[b]={get:function(){return d([b])}}}),a}var h={};b.exports=h,h.themes={};var i=h.styles=a("./styles"),j=Object.defineProperties;h.supportsColor=a("./system/supports-colors"),"undefined"==typeof h.enabled&&(h.enabled=h.supportsColor),h.stripColors=h.strip=function(a){return(""+a).replace(/\x1B\[\d+m/g,"")};var k=(h.stylize=function(a,b){return h.enabled?i[b].open+a+i[b].close:a+""},/[|\\{}()[\]^$+*?.]/g),l=function(a){if("string"!=typeof a)throw new TypeError("Expected a string");return a.replace(k,"\\$&")},m=function(){var a={};return i.grey=i.gray,Object.keys(i).forEach(function(b){i[b].closeRe=new RegExp(l(i[b].close),"g"),a[b]={get:function(){return d(this._styles.concat(b))}}}),a}(),n=j(function(){},m);h.setTheme=function(b){if("string"==typeof b)try{return h.themes[b]=a(b),f(h.themes[b]),h.themes[b]}catch(c){return console.log(c),c}else f(b)};var o=function(a,b){var c=b.split("");return c=c.map(a),c.join("")};h.trap=a("./custom/trap"),h.zalgo=a("./custom/zalgo"),h.maps={},h.maps.america=a("./maps/america"),h.maps.zebra=a("./maps/zebra"),h.maps.rainbow=a("./maps/rainbow"),h.maps.random=a("./maps/random");for(var p in h.maps)!function(a){h[a]=function(b){return o(h.maps[a],b)}}(p);j(h,g())},{"./custom/trap":2,"./custom/zalgo":3,"./maps/america":6,"./maps/rainbow":7,"./maps/random":8,"./maps/zebra":9,"./styles":10,"./system/supports-colors":11}],2:[function(a,b,c){b.exports=function(a,b){var c="";a=a||"Run the trap, drop the bass",a=a.split("");var d={a:["@","Ą","Ⱥ","Ʌ","Δ","Λ","Д"],b:["ß","Ɓ","Ƀ","ɮ","β","฿"],c:["©","Ȼ","Ͼ"],d:["Ð","Ɗ","Ԁ","ԁ","Ԃ","ԃ"],e:["Ë","ĕ","Ǝ","ɘ","Σ","ξ","Ҽ","੬"],f:["Ӻ"],g:["ɢ"],h:["Ħ","ƕ","Ң","Һ","Ӈ","Ԋ"],i:["༏"],j:["Ĵ"],k:["ĸ","Ҡ","Ӄ","Ԟ"],l:["Ĺ"],m:["ʍ","Ӎ","ӎ","Ԡ","ԡ","൩"],n:["Ñ","ŋ","Ɲ","Ͷ","Π","Ҋ"],o:["Ø","õ","ø","Ǿ","ʘ","Ѻ","ם","","๏"],p:["Ƿ","Ҏ"],q:["্"],r:["®","Ʀ","Ȑ","Ɍ","ʀ","Я"],s:["§","Ϟ","ϟ","Ϩ"],t:["Ł","Ŧ","ͳ"],u:["Ʊ","Ս"],v:["ט"],w:["Ш","Ѡ","Ѽ","൰"],x:["Ҳ","Ӿ","Ӽ","ӽ"],y:["¥","Ұ","Ӌ"],z:["Ƶ","ɀ"]};return a.forEach(function(a){a=a.toLowerCase();var b=d[a]||[" "],e=Math.floor(Math.random()*b.length);c+="undefined"!=typeof d[a]?d[a][e]:a}),c}},{}],3:[function(a,b,c){b.exports=function(a,b){function c(a){var b=Math.floor(Math.random()*a);return b}function d(a){var b=!1;return g.filter(function(c){b=c===a}),b}function e(a,b){var e,g,h="";b=b||{},b.up="undefined"!=typeof b.up?b.up:!0,b.mid="undefined"!=typeof b.mid?b.mid:!0,b.down="undefined"!=typeof b.down?b.down:!0,b.size="undefined"!=typeof b.size?b.size:"maxi",a=a.split("");for(g in a)if(!d(g)){switch(h+=a[g],e={up:0,down:0,mid:0},b.size){case"mini":e.up=c(8),e.mid=c(2),e.down=c(8);break;case"maxi":e.up=c(16)+3,e.mid=c(4)+1,e.down=c(64)+3;break;default:e.up=c(8)+1,e.mid=c(6)/2,e.down=c(8)+1}var i=["up","mid","down"];for(var j in i)for(var k=i[j],l=0;l<=e[k];l++)b[k]&&(h+=f[k][c(f[k].length)])}return h}a=a||" he is here ";var f={up:["̍","̎","̄","̅","̿","̑","̆","̐","͒","͗","͑","̇","̈","̊","͂","̓","̈","͊","͋","͌","̃","̂","̌","͐","̀","́","̋","̏","̒","̓","̔","̽","̉","ͣ","ͤ","ͥ","ͦ","ͧ","ͨ","ͩ","ͪ","ͫ","ͬ","ͭ","ͮ","ͯ","̾","͛","͆","̚"],down:["̖","̗","̘","̙","̜","̝","̞","̟","̠","̤","̥","̦","̩","̪","̫","̬","̭","̮","̯","̰","̱","̲","̳","̹","̺","̻","̼","ͅ","͇","͈","͉","͍","͎","͓","͔","͕","͖","͙","͚","̣"],mid:["̕","̛","̀","́","͘","̡","̢","̧","̨","̴","̵","̶","͜","͝","͞","͟","͠","͢","̸","̷","͡"," ҉"]},g=[].concat(f.up,f.down,f.mid);return e(a,b)}},{}],4:[function(a,b,c){var d=a("./colors");b.exports=function(){function b(a){var b=["__defineGetter__","__defineSetter__","__lookupGetter__","__lookupSetter__","charAt","constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf","charCodeAt","indexOf","lastIndexof","length","localeCompare","match","replace","search","slice","split","substring","toLocaleLowerCase","toLocaleUpperCase","toLowerCase","toUpperCase","trim","trimLeft","trimRight"];Object.keys(a).forEach(function(e){-1!==b.indexOf(e)?console.log("warn: ".red+("String.prototype"+e).magenta+" is probably something you don't want to override. Ignoring style name"):"string"==typeof a[e]?(d[e]=d[a[e]],c(e,function(){return d[a[e]](this)})):c(e,function(){for(var b=this,c=0;c<a[e].length;c++)b=d[a[e][c]](b);return b})})}var c=function(a,b){String.prototype.__defineGetter__(a,b)};c("strip",function(){return d.strip(this)}),c("stripColors",function(){return d.strip(this)}),c("trap",function(){return d.trap(this)}),c("zalgo",function(){return d.zalgo(this)}),c("zebra",function(){return d.zebra(this)}),c("rainbow",function(){return d.rainbow(this)}),c("random",function(){return d.random(this)}),c("america",function(){return d.america(this)});var e=Object.keys(d.styles);e.forEach(function(a){c(a,function(){return d.stylize(this,a)})}),d.setTheme=function(c){if("string"==typeof c)try{return d.themes[c]=a(c),b(d.themes[c]),d.themes[c]}catch(e){return console.log(e),e}else b(c)}}},{"./colors":1}],5:[function(a,b,c){var d=a("./colors");b.exports=d,a("./extendStringPrototype")()},{"./colors":1,"./extendStringPrototype":4}],6:[function(a,b,c){var d=a("../colors");b.exports=function(){return function(a,b,c){if(" "===a)return a;switch(b%3){case 0:return d.red(a);case 1:return d.white(a);case 2:return d.blue(a)}}}()},{"../colors":1}],7:[function(a,b,c){var d=a("../colors");b.exports=function(){var a=["red","yellow","green","blue","magenta"];return function(b,c,e){return" "===b?b:d[a[c++%a.length]](b)}}()},{"../colors":1}],8:[function(a,b,c){var d=a("../colors");b.exports=function(){var a=["underline","inverse","grey","yellow","red","green","blue","white","cyan","magenta"];return function(b,c,e){return" "===b?b:d[a[Math.round(Math.random()*(a.length-1))]](b)}}()},{"../colors":1}],9:[function(a,b,c){var d=a("../colors");b.exports=function(a,b,c){return b%2===0?a:d.inverse(a)}},{"../colors":1}],10:[function(a,b,c){var d={};b.exports=d;var e={reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],inverse:[7,27],hidden:[8,28],strikethrough:[9,29],black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],gray:[90,39],grey:[90,39],bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],blackBG:[40,49],redBG:[41,49],greenBG:[42,49],yellowBG:[43,49],blueBG:[44,49],magentaBG:[45,49],cyanBG:[46,49],whiteBG:[47,49]};Object.keys(e).forEach(function(a){var b=e[a],c=d[a]=[];c.open="["+b[0]+"m",c.close="["+b[1]+"m"})},{}],11:[function(a,b,c){(function(a){var c=a.argv;b.exports=function(){return-1!==c.indexOf("--no-color")||-1!==c.indexOf("--color=false")?!1:-1!==c.indexOf("--color")||-1!==c.indexOf("--color=true")||-1!==c.indexOf("--color=always")?!0:a.stdout&&!a.stdout.isTTY?!1:"win32"===a.platform?!0:"COLORTERM"in a.env?!0:"dumb"===a.env.TERM?!1:/^screen|^xterm|^vt100|color|ansi|cygwin|linux/i.test(a.env.TERM)?!0:!1}()}).call(this,a("_process"))},{_process:12}],12:[function(a,b,c){function d(){k=!1,h.length?j=h.concat(j):l=-1,j.length&&e()}function e(){if(!k){var a=setTimeout(d);k=!0;for(var b=j.length;b;){for(h=j,j=[];++l<b;)h[l].run();l=-1,b=j.length}h=null,k=!1,clearTimeout(a)}}function f(a,b){this.fun=a,this.array=b}function g(){}var h,i=b.exports={},j=[],k=!1,l=-1;i.nextTick=function(a){var b=new Array(arguments.length-1);if(arguments.length>1)for(var c=1;c<arguments.length;c++)b[c-1]=arguments[c];j.push(new f(a,b)),1!==j.length||k||setTimeout(e,0)},f.prototype.run=function(){this.fun.apply(null,this.array)},i.title="browser",i.browser=!0,i.env={},i.argv=[],i.version="",i.versions={},i.on=g,i.addListener=g,i.once=g,i.off=g,i.removeListener=g,i.removeAllListeners=g,i.emit=g,i.binding=function(a){throw new Error("process.binding is not supported")},i.cwd=function(){return"/"},i.chdir=function(a){throw new Error("process.chdir is not supported")},i.umask=function(){return 0}},{}],13:[function(a,b,c){(function(c){(function(){var d,e,f,g,h,i,j,k,l=[].slice;k=a("underscore"),f={cmd:"⌘",ctrl:"⌃",alt:"⌥",option:"⌥",shift:"⇧",enter:"⏎",left:"←",right:"→",up:"↑",down:"↓"},g={cmd:"Cmd",ctrl:"Ctrl",alt:"Alt",option:"Alt",shift:"Shift",enter:"Enter",left:"Left",right:"Right",up:"Up",down:"Down"},i={"~":"`",_:"-","+":"=","|":"\\","{":"[","}":"]",":":";",'"':"'","<":",",">":".","?":"/"},j=function(a){var b,c,d,e,f,g;if(e=0,d=[],null==a)return d;for(c=f=0,g=a.length;g>f;c=++f)b=a[c],"."!==b||0!==c&&"\\"===a[c-1]||(d.push(a.substring(e,c)),e=c+1);return d.push(a.substr(e,a.length)),d},e=function(a){return k.isObject(a)&&!k.isArray(a)},h={adviseBefore:function(a,b,c){var d;return d=a[b],a[b]=function(){var a;return a=1<=arguments.length?l.call(arguments,0):[],c.apply(this,a)!==!1?d.apply(this,a):void 0}},camelize:function(a){return a?a.replace(/[_-]+(\w)/g,function(a){return a[1].toUpperCase()}):""},capitalize:function(a){return a?"github"===a.toLowerCase()?"GitHub":a[0].toUpperCase()+a.slice(1):""},compactObject:function(a){var b,c,d;c={};for(b in a)d=a[b],null!=d&&(c[b]=d);return c},dasherize:function(a){return a?(a=a[0].toLowerCase()+a.slice(1),a.replace(/([A-Z])|(_)/g,function(a,b){return b?"-"+b.toLowerCase():"-"})):""},deepClone:function(a){return k.isArray(a)?a.map(function(a){return h.deepClone(a)}):k.isObject(a)&&!k.isFunction(a)?h.mapObject(a,function(a){return function(a,b){return[a,h.deepClone(b)]}}(this)):a},deepExtend:function(a){var b,c,d,f,g,i,j;for(f=a,b=0;++b<arguments.length;)if(d=arguments[b],e(f)&&e(d))for(j=Object.keys(d),g=0,i=j.length;i>g;g++)c=j[g],f[c]=h.deepExtend(f[c],d[c]);else f=h.deepClone(d);return f},deepContains:function(a,b){var c,d,e;if(null==a)return!1;for(d=0,e=a.length;e>d;d++)if(c=a[d],k.isEqual(c,b))return!0;return!1},endsWith:function(a,b){return null==b&&(b=""),a?-1!==a.indexOf(b,a.length-b.length):!1},escapeAttribute:function(a){return a?a.replace(/"/g,""").replace(/\n/g,"").replace(/\\/g,"-"):""},escapeRegExp:function(a){return a?a.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"):""},humanizeEventName:function(a,b){var c,d,e,f;return f=a.split(":"),d=f[0],c=f[1],null==c?h.undasherize(d):(e=h.undasherize(d),null==b&&(b=h.undasherize(c)),""+e+": "+b)},humanizeKey:function(a,b){var d;return null==b&&(b=c.platform),a?(d="darwin"===b?f:g,d[a]?d[a]:1===a.length&&null!=i[a]?[d.shift,i[a]]:1===a.length&&a===a.toUpperCase()&&a.toUpperCase()!==a.toLowerCase()?[d.shift,a.toUpperCase()]:1===a.length||/f[0-9]{1,2}/.test(a)?a.toUpperCase():"darwin"===b?a:h.capitalize(a)):a},humanizeKeystroke:function(a,b){var d,e,f,g,i,j,l,m,n,o;if(null==b&&(b=c.platform),!a)return a;for(i=a.split(" "),d=[],l=0,n=i.length;n>l;l++){for(a=i[l],g=[],j=a.split("-"),e=m=0,o=j.length;o>m;e=++m)f=j[e],""===f&&""===j[e-1]&&(f="-"),f&&g.push(h.humanizeKey(f,b));g=k.uniq(k.flatten(g)),g="darwin"===b?g.join(""):g.join("+"),d.push(g)}return d.join(" ")},isSubset:function(a,b){return k.every(a,function(a){return k.include(b,a)})},losslessInvert:function(a){var b,c,d;b={};for(c in a)d=a[c],null==b[d]&&(b[d]=[]),b[d].push(c);return b},mapObject:function(a,b){var c,d,e,f,g,h,i;for(d={},h=Object.keys(a),f=0,g=h.length;g>f;f++)c=h[f],i=b(c,a[c]),c=i[0],e=i[1],d[c]=e;return d},multiplyString:function(a,b){var c,d;for(c="",d=0;b>d;)c+=a,d++;return c},pluralize:function(a,b,c){return null==a&&(a=0),null==c&&(c=b+"s"),1===a?""+a+" "+b:""+a+" "+c},remove:function(a,b){var c;return c=a.indexOf(b),c>=0&&a.splice(c,1),a},setValueForKeyPath:function(a,b,c){var d,e;for(e=j(b);e.length>1;)d=e.shift(),null==a[d]&&(a[d]={}),a=a[d];return null!=c?a[e.shift()]=c:delete a[e.shift()]},hasKeyPath:function(a,b){var c,d,e,f;for(d=j(b),e=0,f=d.length;f>e;e++){if(c=d[e],!a.hasOwnProperty(c))return!1;a=a[c]}return!0},spliceWithArray:function(a,b,c,d,e){var f,g,h,i;if(null==e&&(e=1e5),d.length<e)return a.splice.apply(a,[b,c].concat(l.call(d)));for(a.splice(b,c),i=[],f=g=0,h=d.length;e>0?h>=g:g>=h;f=g+=e)i.push(a.splice.apply(a,[b+f,0].concat(l.call(d.slice(f,f+e)))));return i},sum:function(a){var b,c,d,e;for(c=0,d=0,e=a.length;e>d;d++)b=a[d],c+=b;return c},uncamelcase:function(a){var b;return a?(b=a.replace(/([A-Z])|_+/g,function(a,b){return null==b&&(b="")," "+b}),h.capitalize(b.trim())):""},undasherize:function(a){return a?a.split("-").map(h.capitalize).join(" "):""},underscore:function(a){return a?(a=a[0].toLowerCase()+a.slice(1),a.replace(/([A-Z])|-+/g,function(a,b){return null==b&&(b=""),"_"+b.toLowerCase()})):""},valueForKeyPath:function(a,b){var c,d,e,f;for(d=j(b),e=0,f=d.length;f>e;e++)if(c=d[e],a=a[c],null==a)return;return a},isEqual:function(a,b,c,e){return k.isArray(c)&&k.isArray(e)?d(a,b,c,e):d(a,b)},isEqualForProperties:function(){var a,b,c,d,e,f;for(a=arguments[0],b=arguments[1],c=3<=arguments.length?l.call(arguments,2):[],e=0,f=c.length;f>e;e++)if(d=c[e],!k.isEqual(a[d],b[d]))return!1;return!0}},d=function(a,b,c,e){var f,g,h,i,j,l,m,n,o,p,q,r,s,t,u;if(null==c&&(c=[]),null==e&&(e=[]),a===b)return k.isEqual(a,b);if(k.isFunction(a)||k.isFunction(b))return k.isEqual(a,b);for(s=c.length;s--;)if(c[s]===a)return e[s]===b;if(c.push(a),e.push(b),p=!1,k.isFunction(null!=a?a.isEqual:void 0))p=a.isEqual(b,c,e);else if(k.isFunction(null!=b?b.isEqual:void 0))p=b.isEqual(a,e,c);else if(k.isArray(a)&&k.isArray(b)&&a.length===b.length){for(p=!0,q=t=0,u=a.length;u>t;q=++t)if(h=a[q],!d(h,b[q],c,e)){p=!1;break}}else if(k.isRegExp(a)&&k.isRegExp(b))p=k.isEqual(a,b);else if(k.isElement(a)&&k.isElement(b))p=a===b;else if(k.isObject(a)&&k.isObject(b))if(f=a.constructor,l=b.constructor,g=k.isFunction(f)&&f instanceof f,m=k.isFunction(l)&&l instanceof l,f===l||g&&m){i=0,p=!0;for(r in a)if(j=a[r],k.has(a,r)&&(i++,!k.has(b,r)||!d(j,b[r],c,e))){p=!1;break}if(p){n=0;for(r in b)o=b[r],k.has(b,r)&&n++;p=i===n}}else p=!1;else p=k.isEqual(a,b);return c.pop(),e.pop(),p},b.exports=k.extend({},k,h)}).call(this)}).call(this,a("_process"))},{_process:12,underscore:14}],14:[function(b,c,d){(function(){var b=this,e=b._,f={},g=Array.prototype,h=Object.prototype,i=Function.prototype,j=g.push,k=g.slice,l=g.concat,m=h.toString,n=h.hasOwnProperty,o=g.forEach,p=g.map,q=g.reduce,r=g.reduceRight,s=g.filter,t=g.every,u=g.some,v=g.indexOf,w=g.lastIndexOf,x=Array.isArray,y=Object.keys,z=i.bind,A=function(a){return a instanceof A?a:this instanceof A?void(this._wrapped=a):new A(a)};"undefined"!=typeof d?("undefined"!=typeof c&&c.exports&&(d=c.exports=A),d._=A):b._=A,A.VERSION="1.6.0";var B=A.each=A.forEach=function(a,b,c){if(null==a)return a;if(o&&a.forEach===o)a.forEach(b,c);else if(a.length===+a.length){for(var d=0,e=a.length;e>d;d++)if(b.call(c,a[d],d,a)===f)return}else for(var g=A.keys(a),d=0,e=g.length;e>d;d++)if(b.call(c,a[g[d]],g[d],a)===f)return;return a};A.map=A.collect=function(a,b,c){var d=[];return null==a?d:p&&a.map===p?a.map(b,c):(B(a,function(a,e,f){d.push(b.call(c,a,e,f))}),d)};var C="Reduce of empty array with no initial value";A.reduce=A.foldl=A.inject=function(a,b,c,d){var e=arguments.length>2;if(null==a&&(a=[]),q&&a.reduce===q)return d&&(b=A.bind(b,d)),e?a.reduce(b,c):a.reduce(b);if(B(a,function(a,f,g){e?c=b.call(d,c,a,f,g):(c=a,e=!0)}),!e)throw new TypeError(C);return c},A.reduceRight=A.foldr=function(a,b,c,d){var e=arguments.length>2;if(null==a&&(a=[]),r&&a.reduceRight===r)return d&&(b=A.bind(b,d)),e?a.reduceRight(b,c):a.reduceRight(b);var f=a.length;if(f!==+f){var g=A.keys(a);f=g.length}if(B(a,function(h,i,j){i=g?g[--f]:--f,e?c=b.call(d,c,a[i],i,j):(c=a[i],e=!0)}),!e)throw new TypeError(C);return c},A.find=A.detect=function(a,b,c){var d;return D(a,function(a,e,f){return b.call(c,a,e,f)?(d=a,!0):void 0}),d},A.filter=A.select=function(a,b,c){var d=[];return null==a?d:s&&a.filter===s?a.filter(b,c):(B(a,function(a,e,f){b.call(c,a,e,f)&&d.push(a)}),d)},A.reject=function(a,b,c){return A.filter(a,function(a,d,e){return!b.call(c,a,d,e)},c)},A.every=A.all=function(a,b,c){b||(b=A.identity);var d=!0;return null==a?d:t&&a.every===t?a.every(b,c):(B(a,function(a,e,g){return(d=d&&b.call(c,a,e,g))?void 0:f}),!!d)};var D=A.some=A.any=function(a,b,c){b||(b=A.identity);var d=!1;return null==a?d:u&&a.some===u?a.some(b,c):(B(a,function(a,e,g){return d||(d=b.call(c,a,e,g))?f:void 0}),!!d)};A.contains=A.include=function(a,b){return null==a?!1:v&&a.indexOf===v?-1!=a.indexOf(b):D(a,function(a){return a===b})},A.invoke=function(a,b){var c=k.call(arguments,2),d=A.isFunction(b);return A.map(a,function(a){return(d?b:a[b]).apply(a,c)})},A.pluck=function(a,b){return A.map(a,A.property(b))},A.where=function(a,b){return A.filter(a,A.matches(b))},A.findWhere=function(a,b){return A.find(a,A.matches(b))},A.max=function(a,b,c){if(!b&&A.isArray(a)&&a[0]===+a[0]&&a.length<65535)return Math.max.apply(Math,a);var d=-(1/0),e=-(1/0);return B(a,function(a,f,g){var h=b?b.call(c,a,f,g):a;h>e&&(d=a,e=h)}),d},A.min=function(a,b,c){if(!b&&A.isArray(a)&&a[0]===+a[0]&&a.length<65535)return Math.min.apply(Math,a);var d=1/0,e=1/0;return B(a,function(a,f,g){var h=b?b.call(c,a,f,g):a;e>h&&(d=a,e=h)}),d},A.shuffle=function(a){var b,c=0,d=[];return B(a,function(a){b=A.random(c++),d[c-1]=d[b],d[b]=a}),d},A.sample=function(a,b,c){return null==b||c?(a.length!==+a.length&&(a=A.values(a)),a[A.random(a.length-1)]):A.shuffle(a).slice(0,Math.max(0,b))};var E=function(a){return null==a?A.identity:A.isFunction(a)?a:A.property(a)};A.sortBy=function(a,b,c){return b=E(b),A.pluck(A.map(a,function(a,d,e){return{value:a,index:d,criteria:b.call(c,a,d,e)}}).sort(function(a,b){var c=a.criteria,d=b.criteria;if(c!==d){if(c>d||void 0===c)return 1;if(d>c||void 0===d)return-1}return a.index-b.index}),"value")};var F=function(a){return function(b,c,d){var e={};return c=E(c),B(b,function(f,g){var h=c.call(d,f,g,b);a(e,h,f)}),e}};A.groupBy=F(function(a,b,c){A.has(a,b)?a[b].push(c):a[b]=[c]}),A.indexBy=F(function(a,b,c){a[b]=c}),A.countBy=F(function(a,b){A.has(a,b)?a[b]++:a[b]=1}),A.sortedIndex=function(a,b,c,d){c=E(c);for(var e=c.call(d,b),f=0,g=a.length;g>f;){var h=f+g>>>1;c.call(d,a[h])<e?f=h+1:g=h}return f},A.toArray=function(a){return a?A.isArray(a)?k.call(a):a.length===+a.length?A.map(a,A.identity):A.values(a):[]},A.size=function(a){return null==a?0:a.length===+a.length?a.length:A.keys(a).length},A.first=A.head=A.take=function(a,b,c){return null==a?void 0:null==b||c?a[0]:0>b?[]:k.call(a,0,b)},A.initial=function(a,b,c){return k.call(a,0,a.length-(null==b||c?1:b))},A.last=function(a,b,c){return null==a?void 0:null==b||c?a[a.length-1]:k.call(a,Math.max(a.length-b,0))},A.rest=A.tail=A.drop=function(a,b,c){return k.call(a,null==b||c?1:b)},A.compact=function(a){return A.filter(a,A.identity)};var G=function(a,b,c){return b&&A.every(a,A.isArray)?l.apply(c,a):(B(a,function(a){A.isArray(a)||A.isArguments(a)?b?j.apply(c,a):G(a,b,c):c.push(a)}),c)};A.flatten=function(a,b){return G(a,b,[])},A.without=function(a){return A.difference(a,k.call(arguments,1))},A.partition=function(a,b){var c=[],d=[];return B(a,function(a){(b(a)?c:d).push(a)}),[c,d]},A.uniq=A.unique=function(a,b,c,d){A.isFunction(b)&&(d=c,c=b,b=!1);var e=c?A.map(a,c,d):a,f=[],g=[];return B(e,function(c,d){(b?d&&g[g.length-1]===c:A.contains(g,c))||(g.push(c),f.push(a[d]))}),f},A.union=function(){return A.uniq(A.flatten(arguments,!0))},A.intersection=function(a){var b=k.call(arguments,1);return A.filter(A.uniq(a),function(a){return A.every(b,function(b){return A.contains(b,a)})})},A.difference=function(a){var b=l.apply(g,k.call(arguments,1));return A.filter(a,function(a){return!A.contains(b,a)})},A.zip=function(){for(var a=A.max(A.pluck(arguments,"length").concat(0)),b=new Array(a),c=0;a>c;c++)b[c]=A.pluck(arguments,""+c);return b},A.object=function(a,b){if(null==a)return{};for(var c={},d=0,e=a.length;e>d;d++)b?c[a[d]]=b[d]:c[a[d][0]]=a[d][1];return c},A.indexOf=function(a,b,c){if(null==a)return-1;var d=0,e=a.length;if(c){if("number"!=typeof c)return d=A.sortedIndex(a,b),a[d]===b?d:-1;d=0>c?Math.max(0,e+c):c}if(v&&a.indexOf===v)return a.indexOf(b,c);for(;e>d;d++)if(a[d]===b)return d;return-1},A.lastIndexOf=function(a,b,c){if(null==a)return-1;var d=null!=c;if(w&&a.lastIndexOf===w)return d?a.lastIndexOf(b,c):a.lastIndexOf(b);for(var e=d?c:a.length;e--;)if(a[e]===b)return e;return-1},A.range=function(a,b,c){arguments.length<=1&&(b=a||0,a=0),c=arguments[2]||1;for(var d=Math.max(Math.ceil((b-a)/c),0),e=0,f=new Array(d);d>e;)f[e++]=a,a+=c;return f};var H=function(){};A.bind=function(a,b){var c,d;if(z&&a.bind===z)return z.apply(a,k.call(arguments,1));if(!A.isFunction(a))throw new TypeError;return c=k.call(arguments,2),d=function(){if(!(this instanceof d))return a.apply(b,c.concat(k.call(arguments)));H.prototype=a.prototype;var e=new H;H.prototype=null;var f=a.apply(e,c.concat(k.call(arguments)));return Object(f)===f?f:e}},A.partial=function(a){var b=k.call(arguments,1);return function(){for(var c=0,d=b.slice(),e=0,f=d.length;f>e;e++)d[e]===A&&(d[e]=arguments[c++]);for(;c<arguments.length;)d.push(arguments[c++]);return a.apply(this,d)}},A.bindAll=function(a){var b=k.call(arguments,1);if(0===b.length)throw new Error("bindAll must be passed function names");return B(b,function(b){a[b]=A.bind(a[b],a)}),a},A.memoize=function(a,b){var c={};return b||(b=A.identity),function(){var d=b.apply(this,arguments);return A.has(c,d)?c[d]:c[d]=a.apply(this,arguments)}},A.delay=function(a,b){var c=k.call(arguments,2);return setTimeout(function(){return a.apply(null,c)},b)},A.defer=function(a){return A.delay.apply(A,[a,1].concat(k.call(arguments,1)))},A.throttle=function(a,b,c){var d,e,f,g=null,h=0;c||(c={});var i=function(){h=c.leading===!1?0:A.now(),g=null,f=a.apply(d,e),d=e=null};return function(){var j=A.now();h||c.leading!==!1||(h=j);var k=b-(j-h);return d=this,e=arguments,0>=k?(clearTimeout(g),g=null,h=j,f=a.apply(d,e),d=e=null):g||c.trailing===!1||(g=setTimeout(i,k)),f}},A.debounce=function(a,b,c){var d,e,f,g,h,i=function(){var j=A.now()-g;b>j?d=setTimeout(i,b-j):(d=null,c||(h=a.apply(f,e),f=e=null))};return function(){f=this,e=arguments,g=A.now();var j=c&&!d;return d||(d=setTimeout(i,b)),j&&(h=a.apply(f,e),f=e=null),h}},A.once=function(a){var b,c=!1;return function(){return c?b:(c=!0,b=a.apply(this,arguments),a=null,b)}},A.wrap=function(a,b){return A.partial(b,a)},A.compose=function(){var a=arguments;return function(){for(var b=arguments,c=a.length-1;c>=0;c--)b=[a[c].apply(this,b)];return b[0]}},A.after=function(a,b){return function(){return--a<1?b.apply(this,arguments):void 0}},A.keys=function(a){if(!A.isObject(a))return[];if(y)return y(a);var b=[];for(var c in a)A.has(a,c)&&b.push(c);return b},A.values=function(a){for(var b=A.keys(a),c=b.length,d=new Array(c),e=0;c>e;e++)d[e]=a[b[e]];return d},A.pairs=function(a){for(var b=A.keys(a),c=b.length,d=new Array(c),e=0;c>e;e++)d[e]=[b[e],a[b[e]]];return d},A.invert=function(a){for(var b={},c=A.keys(a),d=0,e=c.length;e>d;d++)b[a[c[d]]]=c[d];return b},A.functions=A.methods=function(a){var b=[];for(var c in a)A.isFunction(a[c])&&b.push(c);return b.sort()},A.extend=function(a){return B(k.call(arguments,1),function(b){if(b)for(var c in b)a[c]=b[c]}),a},A.pick=function(a){var b={},c=l.apply(g,k.call(arguments,1));return B(c,function(c){c in a&&(b[c]=a[c])}),b},A.omit=function(a){var b={},c=l.apply(g,k.call(arguments,1));for(var d in a)A.contains(c,d)||(b[d]=a[d]);return b},A.defaults=function(a){return B(k.call(arguments,1),function(b){if(b)for(var c in b)void 0===a[c]&&(a[c]=b[c])}),a},A.clone=function(a){return A.isObject(a)?A.isArray(a)?a.slice():A.extend({},a):a},A.tap=function(a,b){return b(a),a};var I=function(a,b,c,d){if(a===b)return 0!==a||1/a==1/b;if(null==a||null==b)return a===b;a instanceof A&&(a=a._wrapped),b instanceof A&&(b=b._wrapped);var e=m.call(a);if(e!=m.call(b))return!1;switch(e){case"[object String]":return a==String(b);case"[object Number]":return a!=+a?b!=+b:0==a?1/a==1/b:a==+b;case"[object Date]":case"[object Boolean]":return+a==+b;case"[object RegExp]":return a.source==b.source&&a.global==b.global&&a.multiline==b.multiline&&a.ignoreCase==b.ignoreCase}if("object"!=typeof a||"object"!=typeof b)return!1;for(var f=c.length;f--;)if(c[f]==a)return d[f]==b;var g=a.constructor,h=b.constructor;if(g!==h&&!(A.isFunction(g)&&g instanceof g&&A.isFunction(h)&&h instanceof h)&&"constructor"in a&&"constructor"in b)return!1;c.push(a),d.push(b);var i=0,j=!0;if("[object Array]"==e){if(i=a.length,j=i==b.length)for(;i--&&(j=I(a[i],b[i],c,d)););}else{for(var k in a)if(A.has(a,k)&&(i++,!(j=A.has(b,k)&&I(a[k],b[k],c,d))))break;if(j){for(k in b)if(A.has(b,k)&&!i--)break;j=!i}}return c.pop(),d.pop(),j};A.isEqual=function(a,b){return I(a,b,[],[])},A.isEmpty=function(a){if(null==a)return!0;if(A.isArray(a)||A.isString(a))return 0===a.length;for(var b in a)if(A.has(a,b))return!1;return!0},A.isElement=function(a){return!(!a||1!==a.nodeType)},A.isArray=x||function(a){return"[object Array]"==m.call(a)},A.isObject=function(a){return a===Object(a)},B(["Arguments","Function","String","Number","Date","RegExp"],function(a){A["is"+a]=function(b){return m.call(b)=="[object "+a+"]"}}),A.isArguments(arguments)||(A.isArguments=function(a){return!(!a||!A.has(a,"callee"))}),"function"!=typeof/./&&(A.isFunction=function(a){return"function"==typeof a}),A.isFinite=function(a){return isFinite(a)&&!isNaN(parseFloat(a))},A.isNaN=function(a){return A.isNumber(a)&&a!=+a},A.isBoolean=function(a){return a===!0||a===!1||"[object Boolean]"==m.call(a)},A.isNull=function(a){return null===a},A.isUndefined=function(a){return void 0===a},A.has=function(a,b){return n.call(a,b)},A.noConflict=function(){return b._=e,this},A.identity=function(a){return a},A.constant=function(a){return function(){return a}},A.property=function(a){return function(b){return b[a]}},A.matches=function(a){return function(b){if(b===a)return!0;for(var c in a)if(a[c]!==b[c])return!1;return!0}},A.times=function(a,b,c){for(var d=Array(Math.max(0,a)),e=0;a>e;e++)d[e]=b.call(c,e);return d},A.random=function(a,b){return null==b&&(b=a,a=0),a+Math.floor(Math.random()*(b-a+1))},A.now=Date.now||function(){return(new Date).getTime()};var J={escape:{"&":"&","<":"<",">":">",'"':""","'":"'"}};J.unescape=A.invert(J.escape);var K={escape:new RegExp("["+A.keys(J.escape).join("")+"]","g"),unescape:new RegExp("("+A.keys(J.unescape).join("|")+")","g")};A.each(["escape","unescape"],function(a){A[a]=function(b){return null==b?"":(""+b).replace(K[a],function(b){return J[a][b]})}}),A.result=function(a,b){if(null==a)return void 0;var c=a[b];return A.isFunction(c)?c.call(a):c},A.mixin=function(a){B(A.functions(a),function(b){var c=A[b]=a[b];A.prototype[b]=function(){var a=[this._wrapped];return j.apply(a,arguments),P.call(this,c.apply(A,a))}})};var L=0;A.uniqueId=function(a){var b=++L+"";return a?a+b:b},A.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var M=/(.)^/,N={"'":"'","\\":"\\","\r":"r","\n":"n"," ":"t","\u2028":"u2028","\u2029":"u2029"},O=/\\|'|\r|\n|\t|\u2028|\u2029/g;A.template=function(a,b,c){var d;c=A.defaults({},c,A.templateSettings);var e=new RegExp([(c.escape||M).source,(c.interpolate||M).source,(c.evaluate||M).source].join("|")+"|$","g"),f=0,g="__p+='";a.replace(e,function(b,c,d,e,h){return g+=a.slice(f,h).replace(O,function(a){return"\\"+N[a]}),c&&(g+="'+\n((__t=("+c+"))==null?'':_.escape(__t))+\n'"),d&&(g+="'+\n((__t=("+d+"))==null?'':__t)+\n'"),e&&(g+="';\n"+e+"\n__p+='"),f=h+b.length,b}),g+="';\n",c.variable||(g="with(obj||{}){\n"+g+"}\n"),g="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+g+"return __p;\n";try{d=new Function(c.variable||"obj","_",g)}catch(h){throw h.source=g,h}if(b)return d(b,A);var i=function(a){return d.call(this,a,A)};return i.source="function("+(c.variable||"obj")+"){\n"+g+"}",i},A.chain=function(a){return A(a).chain()};var P=function(a){return this._chain?A(a).chain():a};A.mixin(A),B(["pop","push","reverse","shift","sort","splice","unshift"],function(a){var b=g[a];A.prototype[a]=function(){var c=this._wrapped;return b.apply(c,arguments),"shift"!=a&&"splice"!=a||0!==c.length||delete c[0],P.call(this,c)}}),B(["concat","join","slice"],function(a){var b=g[a];A.prototype[a]=function(){return P.call(this,b.apply(this._wrapped,arguments))}}),A.extend(A.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}}),"function"==typeof a&&a.amd&&a("underscore",[],function(){return A})}).call(this)},{}],15:[function(a,b,c){"use strict";function d(a,b){void 0===b?(this.offset=a,this.x=this.offset%8,this.y=Math.floor(this.offset/8)):(this.offset=a+8*b,this.x=a,this.y=b)}d.prototype.add=function(a){return new d(this.x+a.x,this.y+a.y)},d.prototype.sub=function(a){return new d(this.x-a.x,this.y-a.y)},d.prototype.isValid=function(){return this.x>=0&&this.x<8&&this.y>=0&&this.y<8},b.exports={BoardCoordinates:d}},{}],16:[function(a,b,c){"use strict";function d(a,b){return b.isValid()&&null==a.board[b.offset]}function e(a,b){if(!b.isValid())return!1;var c=a.board[b.offset];return null!=c&&a.turn!==c.side}function f(a,b){if(!b.isValid())return!1;var c=a.board[b.offset];return null==c||a.turn!==c.side}function g(a,b,c,f){for(var g=b;;){if(g=g.add(c),!g.isValid())break;if(!d(a,g)){e(a,g)&&f.push(g);break}f.push(g)}}function h(a){for(var b=[],c=0;64>=c;c++){var d=a.board[c],e=new i(c);if(null!=d&&d.side===a.turn){var f=j[d.type](a,e);f.forEach(function(a){b.push({src:e.offset,dst:a.offset})})}}return b}var i=a("./coordinates").BoardCoordinates,j=[];j.P=function(a,b){var c="W"==a.turn?1:-1,f="W"==a.turn?1:6,g=b.add(new i(0,c)),h=g.add(new i(0,c)),j=b.add(new i(1,c)),k=b.add(new i(-1,c)),l=[];return d(a,g)&&l.push(g),e(a,k)?l.push(k):a.lastPawnMoveColumn==b.x-1&&(b.y-f)/c==3&&l.push(k),e(a,j)?l.push(j):a.lastPawnMoveColumn==b.x+1&&(b.y-f)/c==3&&l.push(j),b.y==f&&d(a,g)&&d(a,h)&&l.push(h),l},j.N=function(a,b){var c=[];return[b.add(new i(-1,2)),b.add(new i(1,2)),b.add(new i(2,-1)),b.add(new i(2,1)),b.add(new i(1,-2)),b.add(new i(-1,-2)),b.add(new i(-2,1)),b.add(new i(-2,-1))].forEach(function(b){f(a,b)&&c.push(b)}),c},j.B=function(a,b){var c=[];return[new i(-1,-1),new i(-1,1),new i(1,-1),new i(1,1)].forEach(function(d){g(a,b,d,c)}),c},j.R=function(a,b){var c=[];return[new i(-1,0),new i(1,0),new i(0,-1),new i(0,1)].forEach(function(d){g(a,b,d,c)}),c},j.K=function(a,b){for(var c=[],e=-1;2>e;e++)for(var g=-1;2>g;g++)if(0!=e||0!=g){var h=new i(e,g),j=b.add(h);f(a,j)&&c.push(j)}if(a.castlingFlags[a.turn].K){var k=b.add(new i(1,0)),l=b.add(new i(2,0));d(a,k)&&d(a,l)&&c.push(l)}if(a.castlingFlags[a.turn].Q){var k=b.add(new i(-1,0)),l=b.add(new i(-2,0));d(a,k)&&d(a,l)&&c.push(l)}return c},j.Q=function(a,b){var c=[];return[new i(-1,0),new i(1,0),new i(0,-1),new i(0,1),new i(-1,-1),new i(-1,1),new i(1,-1),new i(1,1)].forEach(function(d){g(a,b,d,c)}),c},b.exports={computeAllMoves:h,pieceDestinationsEvaluator:j}},{"./coordinates":15}],17:[function(a,b,c){ | ||
"use strict";function d(a,b,c){for(var d=null,e=0;64>e;e++){var f=a.board[e];if(null!=f&&f.type===b&&f.side===c){d=e;break}}return d}function e(a){var b=i.computeAllMoves(a),c=[],e=function(b,c,e){var f=h.applyMove(a,b),g=i.computeAllMoves(f),j=d(f,c,e),k=!1;return g.forEach(function(a){a.dst==j&&(k=!0)}),k};return b.forEach(function(b){var d=new j(b.src),f=new j(b.dst),g=f.sub(d),h=e(b,"K",a.turn);"K"==a.board[b.src].type&&2==g.x&&(h=h||e({src:b.src,dst:b.src+1},"K",a.turn)),"K"==a.board[b.src].type&&-2==g.x&&(h=h||e({src:b.src,dst:b.src-1},"K",a.turn)),h||c.push(b)}),c}function f(a){var b=!1,c=a.turn;a.turn="W"===c?"B":"W";for(var d=0;64>=d;d++){var e=a.board[d],f=new j(d);if(null!=e&&e.side===a.turn){var g=i.pieceDestinationsEvaluator[e.type](a,f);g.forEach(function(c){var d=a.board[c.offset];d&&"K"===d.type&&d.side!==a.turn&&(b=!0)})}}return a.turn=c,b}var g=a("./coordinates"),h=a("./updates"),i=a("./moves-pieces"),j=g.BoardCoordinates;b.exports={getAvailableMoves:e,isCurrentPlayerInCheck:f}},{"./coordinates":15,"./moves-pieces":16,"./updates":23}],18:[function(a,b,c){"use strict";function d(a){var b="";return b+=String.fromCharCode("a".charCodeAt(0)+a%8),b+=String.fromCharCode("1".charCodeAt(0)+Math.floor(a/8))}function e(a,b){var c=null,d=j[b];if(d)c=d[a.turn];else{var e=i.parsePgnMove(b);if(e){var f=g.getAvailableMoves(a);f.forEach(function(b){(null==e.srcCol||b.src%8==e.srcCol)&&(null==e.srcRow||Math.floor(b.src/8)==e.srcRow)&&b.dst==e.dst&&a.board[b.src].type==e.type&&(e.src=b.src)}),null!=e.src&&null!=e.dst&&(c={src:e.src,dst:e.dst})}}return c}function f(a,b){var c="",e=a.board[b.src];if("P"!=e.type&&(c+=e.type),"K"===e.type&&b.dst-b.src==2)return"O-O";if("K"===e.type&&b.dst-b.src==-2)return"O-O-O";var f=g.getAvailableMoves(a),i=[];f.forEach(function(c){c.dst==b.dst&&e.type==a.board[c.src].type&&i.push(c.src)});var j=d(b.src);if(i.length>1){var k=d(i[0]),l=d(i[1]);c+=k[0]==l[0]?j[1]:j[0]}null!=a.board[b.dst]&&(""==c&&"P"==e.type&&(c+=j[0]),c+="x"),c+=d(b.dst);var m=h.applyMove(a,b);return"P"==e.type&&(b.dst<8||b.dst>56)&&(c+="=Q"),g.isCurrentPlayerInCheck(m)&&(c+="+"),c}var g=a("./moves"),h=a("./updates"),i=a("./pgnParser"),j={"O-O":{W:{src:4,dst:6},B:{src:60,dst:62}},"O-O-O":{W:{src:4,dst:2},B:{src:60,dst:58}}};b.exports={pgnToMove:e,moveToPgn:f}},{"./moves":17,"./pgnParser":19,"./updates":23}],19:[function(a,b,c){"use strict";function d(a,b){var c=null,d=a.charCodeAt(b)-f,e=a.charCodeAt(b+1)-g;return d>=0&&8>d&&e>=0&&8>e&&(c+=d,c+=8*e),c}function e(a){var b={type:null,srcCol:null,srcRow:null,dst:null,promotion:null,capture:!1,checking:!1,mate:!1},c=0,e=a.length;-1!=["P","R","N","B","K","Q"].indexOf(a[c])?(b.type=a[c],c++):b.type="P";var h=a.indexOf("+"),i=a.indexOf("#"),j=a.indexOf("=");h>=0&&(b.checking=!0,e=h),i>=0&&(b.mate=!0,e=i),j>=0&&(b.promotion=a.substring(j+1,j+2),e=j);var k=d(a,e-2);if(null==k)return null;b.dst=k,e-=2,"x"===a[e-1]&&(e-=1,b.capture=!0);for(var l=c;e>l;l++){var m=a.charCodeAt(c),n=m-g,o=m-f;n>=0&&8>n&&(b.srcRow=n),o>=0&&8>o&&(b.srcCol=o)}return b}var f="a".charCodeAt(0),g="1".charCodeAt(0);b.exports={parsePgnMove:e}},{}],20:[function(a,b,c){"use strict";function d(a,b){return{type:a,side:b}}function e(a){return f[a.type.concat(a.side)]}var f={PW:"♙",PB:"♟",NW:"♘",NB:"♞",BW:"♗",BB:"♝",RW:"♖",RB:"♜",QW:"♕",QB:"♛",KW:"♔",KB:"♚"};b.exports={pieceFactory:d,pieceToUTF8:e}},{}],21:[function(a,b,c){"use strict";function d(a){return j.deepClone(a)}function e(){return{turn:"W",castlingFlags:{W:{K:!0,Q:!0},B:{K:!0,Q:!0}},lastPawnMoveColumn:null,check:!1,board:[h.pieceFactory("R","W"),h.pieceFactory("N","W"),h.pieceFactory("B","W"),h.pieceFactory("Q","W"),h.pieceFactory("K","W"),h.pieceFactory("B","W"),h.pieceFactory("N","W"),h.pieceFactory("R","W"),h.pieceFactory("P","W"),h.pieceFactory("P","W"),h.pieceFactory("P","W"),h.pieceFactory("P","W"),h.pieceFactory("P","W"),h.pieceFactory("P","W"),h.pieceFactory("P","W"),h.pieceFactory("P","W"),null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,h.pieceFactory("P","B"),h.pieceFactory("P","B"),h.pieceFactory("P","B"),h.pieceFactory("P","B"),h.pieceFactory("P","B"),h.pieceFactory("P","B"),h.pieceFactory("P","B"),h.pieceFactory("P","B"),h.pieceFactory("R","B"),h.pieceFactory("N","B"),h.pieceFactory("B","B"),h.pieceFactory("Q","B"),h.pieceFactory("K","B"),h.pieceFactory("B","B"),h.pieceFactory("N","B"),h.pieceFactory("R","B")]}}function f(a,b,c,d){var e;return e=(a+b)%2==0?"W"===c?d.WB:d.BB:"W"===c?d.WW:d.BW}function g(a,b){var c=[];c.push("W"==a.turn?"WHITE":"BLACK"),c.push(" "),c.push(a.castlingFlags.W.K?"K":""),c.push(a.castlingFlags.W.Q?"Q":""),c.push(a.castlingFlags.B.K?"k":""),c.push(a.castlingFlags.B.Q?"q":"");var d,e;for(d=7;d>=0;d--)for(c.push("\n"),c.push(d+1),c.push(" "),e=0;8>e;e++){var g=a.board[8*d+e];b?null==g?c.push(f(d,e,"W"," ")):c.push(f(d,e,g.side,h.pieceToUTF8(g)+" ")):null==g?c.push(". "):"W"==g.side?c.push(g.type.toUpperCase()+" "):c.push(g.type.toLowerCase()+" ")}return c.push("\n a b c d e f g h "),c.join("")}var h=a("./piece"),i=a("colors");i.setTheme({BW:["black","bgWhite"],BB:["black","bgMagenta"],WW:["white","bgWhite"],WB:["white","bgMagenta"]});var j=a("underscore-plus");b.exports={getInitialPosition:e,positionToString:g,clone:d}},{"./piece":20,colors:5,"underscore-plus":13}],22:[function(a,b,c){"use strict";function d(a){var b=e.getAvailableMoves(a),c="OPEN";return 0==b.length&&(c=a.check?"W"==a.turn?"BLACKWON":"WHITEWON":"PAT"),c}var e=a("./moves");b.exports={getGameStatus:d}},{"./moves":17}],23:[function(a,b,c){"use strict";function d(a,b){var c=[],d=new j(b.src),f=new j(b.dst),g=f.sub(d),h=a.board[b.dst];if(null!=h&&c.push({action:"remove",src:b.dst}),c.push({action:"move",src:b.src,dst:b.dst}),null==h&&"P"==a.board[b.src].type&&Math.abs(g.x)){var k=d.add(new j(g.x,0));c.push({action:"remove",src:k.offset})}"P"==a.board[b.src].type&&2==Math.abs(g.y)?c.push({action:"pawnColumn",col:b.src%8}):c.push({action:"pawnColumn",col:null}),"P"!=a.board[b.src].type||0!=f.y&&7!=f.y||c.push({action:"promote",src:b.dst}),"K"==a.board[b.src].type&&(c.push({action:"resetCastling",sides:["K","Q"]}),4==d.x&&6==f.x&&c.push({action:"move",src:f.add(new j(1,0)).offset,dst:f.add(new j(-1,0)).offset}),4==d.x&&2==f.x&&c.push({action:"move",src:f.add(new j(-2,0)).offset,dst:f.add(new j(1,0)).offset})),"R"==a.board[b.src].type&&0==d.x&&c.push({action:"resetCastling",sides:["Q"]}),"R"==a.board[b.src].type&&7==d.x&&c.push({action:"resetCastling",sides:["K"]});var l=e(a,c);l.turn=a.turn;var m=!1;return i.computeAllMoves(l).forEach(function(b){var c=a.board[b.dst];c&&"K"==c.type&&c.side!=a.turn&&(m=!0)}),c.push({action:"updateCheckFlag",value:m}),c}function e(a,b){var c=g.clone(a);return b.forEach(function(b){if("remove"===b.action){var d=b.src;c.board[d]=null}else"move"===b.action?(c.board[b.dst]=c.board[b.src],c.board[b.src]=null):"pawnColumn"===b.action?c.lastPawnMoveColumn=b.col:"resetCastling"===b.action?b.sides.forEach(function(b){c.castlingFlags[a.turn][b]=!1}):"updateCheckFlag"===b.action?c.check=b.value:"promote"===b.action&&(c.board[b.src].type="Q")}),c.turn="W"===a.turn?"B":"W",c}function f(a,b){var c=d(a,b);return e(a,c)}var g=a("./position"),h=a("./coordinates"),i=a("./moves-pieces"),j=h.BoardCoordinates;b.exports={computeDiffs:d,applyDiffs:e,applyMove:f}},{"./coordinates":15,"./moves-pieces":16,"./position":21}],24:[function(a,b,c){"use strict";var d=a("./chess/position"),e=a("./chess/moves"),f=a("./chess/updates"),g=a("./chess/pgn"),h=a("./chess/status"),i={getInitialPosition:d.getInitialPosition,positionToString:d.positionToString,getAvailableMoves:e.getAvailableMoves,applyMove:f.applyMove,computeDiffs:f.computeDiffs,applyDiffs:f.applyDiffs,pgnToMove:g.pgnToMove,moveToPgn:g.moveToPgn,getGameStatus:h.getGameStatus};b.exports=i},{"./chess/moves":17,"./chess/pgn":18,"./chess/position":21,"./chess/status":22,"./chess/updates":23}]},{},[24])(24)}); | ||
!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.chessRules=a()}}(function(){var a;return function b(a,c,d){function e(g,h){if(!c[g]){if(!a[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};a[g][0].call(k.exports,function(b){var c=a[g][1][b];return e(c?c:b)},k,k.exports,b,a,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){function d(a){var b=function c(){return e.apply(c,arguments)};return b._styles=a,b.__proto__=n,b}function e(){var a=arguments,b=a.length,c=0!==b&&String(arguments[0]);if(b>1)for(var d=1;b>d;d++)c+=" "+a[d];if(!h.enabled||!c)return c;for(var e=this._styles,f=e.length;f--;){var g=i[e[f]];c=g.open+c.replace(g.closeRe,g.open)+g.close}return c}function f(a){for(var b in a)!function(b){h[b]=function(c){if("object"==typeof a[b]){var d=c;for(var e in a[b])d=h[a[b][e]](d);return d}return h[a[b]](c)}}(b)}function g(){var a={};return Object.keys(m).forEach(function(b){a[b]={get:function(){return d([b])}}}),a}var h={};b.exports=h,h.themes={};var i=h.styles=a("./styles"),j=Object.defineProperties;h.supportsColor=a("./system/supports-colors"),"undefined"==typeof h.enabled&&(h.enabled=h.supportsColor),h.stripColors=h.strip=function(a){return(""+a).replace(/\x1B\[\d+m/g,"")};var k=(h.stylize=function(a,b){return h.enabled?i[b].open+a+i[b].close:a+""},/[|\\{}()[\]^$+*?.]/g),l=function(a){if("string"!=typeof a)throw new TypeError("Expected a string");return a.replace(k,"\\$&")},m=function(){var a={};return i.grey=i.gray,Object.keys(i).forEach(function(b){i[b].closeRe=new RegExp(l(i[b].close),"g"),a[b]={get:function(){return d(this._styles.concat(b))}}}),a}(),n=j(function(){},m);h.setTheme=function(b){if("string"==typeof b)try{return h.themes[b]=a(b),f(h.themes[b]),h.themes[b]}catch(c){return console.log(c),c}else f(b)};var o=function(a,b){var c=b.split("");return c=c.map(a),c.join("")};h.trap=a("./custom/trap"),h.zalgo=a("./custom/zalgo"),h.maps={},h.maps.america=a("./maps/america"),h.maps.zebra=a("./maps/zebra"),h.maps.rainbow=a("./maps/rainbow"),h.maps.random=a("./maps/random");for(var p in h.maps)!function(a){h[a]=function(b){return o(h.maps[a],b)}}(p);j(h,g())},{"./custom/trap":2,"./custom/zalgo":3,"./maps/america":6,"./maps/rainbow":7,"./maps/random":8,"./maps/zebra":9,"./styles":10,"./system/supports-colors":11}],2:[function(a,b,c){b.exports=function(a,b){var c="";a=a||"Run the trap, drop the bass",a=a.split("");var d={a:["@","Ą","Ⱥ","Ʌ","Δ","Λ","Д"],b:["ß","Ɓ","Ƀ","ɮ","β","฿"],c:["©","Ȼ","Ͼ"],d:["Ð","Ɗ","Ԁ","ԁ","Ԃ","ԃ"],e:["Ë","ĕ","Ǝ","ɘ","Σ","ξ","Ҽ","੬"],f:["Ӻ"],g:["ɢ"],h:["Ħ","ƕ","Ң","Һ","Ӈ","Ԋ"],i:["༏"],j:["Ĵ"],k:["ĸ","Ҡ","Ӄ","Ԟ"],l:["Ĺ"],m:["ʍ","Ӎ","ӎ","Ԡ","ԡ","൩"],n:["Ñ","ŋ","Ɲ","Ͷ","Π","Ҋ"],o:["Ø","õ","ø","Ǿ","ʘ","Ѻ","ם","","๏"],p:["Ƿ","Ҏ"],q:["্"],r:["®","Ʀ","Ȑ","Ɍ","ʀ","Я"],s:["§","Ϟ","ϟ","Ϩ"],t:["Ł","Ŧ","ͳ"],u:["Ʊ","Ս"],v:["ט"],w:["Ш","Ѡ","Ѽ","൰"],x:["Ҳ","Ӿ","Ӽ","ӽ"],y:["¥","Ұ","Ӌ"],z:["Ƶ","ɀ"]};return a.forEach(function(a){a=a.toLowerCase();var b=d[a]||[" "],e=Math.floor(Math.random()*b.length);c+="undefined"!=typeof d[a]?d[a][e]:a}),c}},{}],3:[function(a,b,c){b.exports=function(a,b){function c(a){var b=Math.floor(Math.random()*a);return b}function d(a){var b=!1;return g.filter(function(c){b=c===a}),b}function e(a,b){var e,g,h="";b=b||{},b.up="undefined"!=typeof b.up?b.up:!0,b.mid="undefined"!=typeof b.mid?b.mid:!0,b.down="undefined"!=typeof b.down?b.down:!0,b.size="undefined"!=typeof b.size?b.size:"maxi",a=a.split("");for(g in a)if(!d(g)){switch(h+=a[g],e={up:0,down:0,mid:0},b.size){case"mini":e.up=c(8),e.mid=c(2),e.down=c(8);break;case"maxi":e.up=c(16)+3,e.mid=c(4)+1,e.down=c(64)+3;break;default:e.up=c(8)+1,e.mid=c(6)/2,e.down=c(8)+1}var i=["up","mid","down"];for(var j in i)for(var k=i[j],l=0;l<=e[k];l++)b[k]&&(h+=f[k][c(f[k].length)])}return h}a=a||" he is here ";var f={up:["̍","̎","̄","̅","̿","̑","̆","̐","͒","͗","͑","̇","̈","̊","͂","̓","̈","͊","͋","͌","̃","̂","̌","͐","̀","́","̋","̏","̒","̓","̔","̽","̉","ͣ","ͤ","ͥ","ͦ","ͧ","ͨ","ͩ","ͪ","ͫ","ͬ","ͭ","ͮ","ͯ","̾","͛","͆","̚"],down:["̖","̗","̘","̙","̜","̝","̞","̟","̠","̤","̥","̦","̩","̪","̫","̬","̭","̮","̯","̰","̱","̲","̳","̹","̺","̻","̼","ͅ","͇","͈","͉","͍","͎","͓","͔","͕","͖","͙","͚","̣"],mid:["̕","̛","̀","́","͘","̡","̢","̧","̨","̴","̵","̶","͜","͝","͞","͟","͠","͢","̸","̷","͡"," ҉"]},g=[].concat(f.up,f.down,f.mid);return e(a,b)}},{}],4:[function(a,b,c){var d=a("./colors");b.exports=function(){function b(a){var b=["__defineGetter__","__defineSetter__","__lookupGetter__","__lookupSetter__","charAt","constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf","charCodeAt","indexOf","lastIndexof","length","localeCompare","match","replace","search","slice","split","substring","toLocaleLowerCase","toLocaleUpperCase","toLowerCase","toUpperCase","trim","trimLeft","trimRight"];Object.keys(a).forEach(function(e){-1!==b.indexOf(e)?console.log("warn: ".red+("String.prototype"+e).magenta+" is probably something you don't want to override. Ignoring style name"):"string"==typeof a[e]?(d[e]=d[a[e]],c(e,function(){return d[a[e]](this)})):c(e,function(){for(var b=this,c=0;c<a[e].length;c++)b=d[a[e][c]](b);return b})})}var c=function(a,b){String.prototype.__defineGetter__(a,b)};c("strip",function(){return d.strip(this)}),c("stripColors",function(){return d.strip(this)}),c("trap",function(){return d.trap(this)}),c("zalgo",function(){return d.zalgo(this)}),c("zebra",function(){return d.zebra(this)}),c("rainbow",function(){return d.rainbow(this)}),c("random",function(){return d.random(this)}),c("america",function(){return d.america(this)});var e=Object.keys(d.styles);e.forEach(function(a){c(a,function(){return d.stylize(this,a)})}),d.setTheme=function(c){if("string"==typeof c)try{return d.themes[c]=a(c),b(d.themes[c]),d.themes[c]}catch(e){return console.log(e),e}else b(c)}}},{"./colors":1}],5:[function(a,b,c){var d=a("./colors");b.exports=d,a("./extendStringPrototype")()},{"./colors":1,"./extendStringPrototype":4}],6:[function(a,b,c){var d=a("../colors");b.exports=function(){return function(a,b,c){if(" "===a)return a;switch(b%3){case 0:return d.red(a);case 1:return d.white(a);case 2:return d.blue(a)}}}()},{"../colors":1}],7:[function(a,b,c){var d=a("../colors");b.exports=function(){var a=["red","yellow","green","blue","magenta"];return function(b,c,e){return" "===b?b:d[a[c++%a.length]](b)}}()},{"../colors":1}],8:[function(a,b,c){var d=a("../colors");b.exports=function(){var a=["underline","inverse","grey","yellow","red","green","blue","white","cyan","magenta"];return function(b,c,e){return" "===b?b:d[a[Math.round(Math.random()*(a.length-1))]](b)}}()},{"../colors":1}],9:[function(a,b,c){var d=a("../colors");b.exports=function(a,b,c){return b%2===0?a:d.inverse(a)}},{"../colors":1}],10:[function(a,b,c){var d={};b.exports=d;var e={reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],inverse:[7,27],hidden:[8,28],strikethrough:[9,29],black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],gray:[90,39],grey:[90,39],bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],blackBG:[40,49],redBG:[41,49],greenBG:[42,49],yellowBG:[43,49],blueBG:[44,49],magentaBG:[45,49],cyanBG:[46,49],whiteBG:[47,49]};Object.keys(e).forEach(function(a){var b=e[a],c=d[a]=[];c.open="["+b[0]+"m",c.close="["+b[1]+"m"})},{}],11:[function(a,b,c){(function(a){var c=a.argv;b.exports=function(){return-1!==c.indexOf("--no-color")||-1!==c.indexOf("--color=false")?!1:-1!==c.indexOf("--color")||-1!==c.indexOf("--color=true")||-1!==c.indexOf("--color=always")?!0:a.stdout&&!a.stdout.isTTY?!1:"win32"===a.platform?!0:"COLORTERM"in a.env?!0:"dumb"===a.env.TERM?!1:/^screen|^xterm|^vt100|color|ansi|cygwin|linux/i.test(a.env.TERM)?!0:!1}()}).call(this,a("_process"))},{_process:12}],12:[function(a,b,c){function d(){k=!1,h.length?j=h.concat(j):l=-1,j.length&&e()}function e(){if(!k){var a=setTimeout(d);k=!0;for(var b=j.length;b;){for(h=j,j=[];++l<b;)h[l].run();l=-1,b=j.length}h=null,k=!1,clearTimeout(a)}}function f(a,b){this.fun=a,this.array=b}function g(){}var h,i=b.exports={},j=[],k=!1,l=-1;i.nextTick=function(a){var b=new Array(arguments.length-1);if(arguments.length>1)for(var c=1;c<arguments.length;c++)b[c-1]=arguments[c];j.push(new f(a,b)),1!==j.length||k||setTimeout(e,0)},f.prototype.run=function(){this.fun.apply(null,this.array)},i.title="browser",i.browser=!0,i.env={},i.argv=[],i.version="",i.versions={},i.on=g,i.addListener=g,i.once=g,i.off=g,i.removeListener=g,i.removeAllListeners=g,i.emit=g,i.binding=function(a){throw new Error("process.binding is not supported")},i.cwd=function(){return"/"},i.chdir=function(a){throw new Error("process.chdir is not supported")},i.umask=function(){return 0}},{}],13:[function(a,b,c){(function(c){(function(){var d,e,f,g,h,i,j,k,l=[].slice;k=a("underscore"),f={cmd:"⌘",ctrl:"⌃",alt:"⌥",option:"⌥",shift:"⇧",enter:"⏎",left:"←",right:"→",up:"↑",down:"↓"},g={cmd:"Cmd",ctrl:"Ctrl",alt:"Alt",option:"Alt",shift:"Shift",enter:"Enter",left:"Left",right:"Right",up:"Up",down:"Down"},i={"~":"`",_:"-","+":"=","|":"\\","{":"[","}":"]",":":";",'"':"'","<":",",">":".","?":"/"},j=function(a){var b,c,d,e,f,g;if(e=0,d=[],null==a)return d;for(c=f=0,g=a.length;g>f;c=++f)b=a[c],"."!==b||0!==c&&"\\"===a[c-1]||(d.push(a.substring(e,c)),e=c+1);return d.push(a.substr(e,a.length)),d},e=function(a){return k.isObject(a)&&!k.isArray(a)},h={adviseBefore:function(a,b,c){var d;return d=a[b],a[b]=function(){var a;return a=1<=arguments.length?l.call(arguments,0):[],c.apply(this,a)!==!1?d.apply(this,a):void 0}},camelize:function(a){return a?a.replace(/[_-]+(\w)/g,function(a){return a[1].toUpperCase()}):""},capitalize:function(a){return a?"github"===a.toLowerCase()?"GitHub":a[0].toUpperCase()+a.slice(1):""},compactObject:function(a){var b,c,d;c={};for(b in a)d=a[b],null!=d&&(c[b]=d);return c},dasherize:function(a){return a?(a=a[0].toLowerCase()+a.slice(1),a.replace(/([A-Z])|(_)/g,function(a,b){return b?"-"+b.toLowerCase():"-"})):""},deepClone:function(a){return k.isArray(a)?a.map(function(a){return h.deepClone(a)}):k.isObject(a)&&!k.isFunction(a)?h.mapObject(a,function(a){return function(a,b){return[a,h.deepClone(b)]}}(this)):a},deepExtend:function(a){var b,c,d,f,g,i,j;for(f=a,b=0;++b<arguments.length;)if(d=arguments[b],e(f)&&e(d))for(j=Object.keys(d),g=0,i=j.length;i>g;g++)c=j[g],f[c]=h.deepExtend(f[c],d[c]);else f=h.deepClone(d);return f},deepContains:function(a,b){var c,d,e;if(null==a)return!1;for(d=0,e=a.length;e>d;d++)if(c=a[d],k.isEqual(c,b))return!0;return!1},endsWith:function(a,b){return null==b&&(b=""),a?-1!==a.indexOf(b,a.length-b.length):!1},escapeAttribute:function(a){return a?a.replace(/"/g,""").replace(/\n/g,"").replace(/\\/g,"-"):""},escapeRegExp:function(a){return a?a.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"):""},humanizeEventName:function(a,b){var c,d,e,f;return f=a.split(":"),d=f[0],c=f[1],null==c?h.undasherize(d):(e=h.undasherize(d),null==b&&(b=h.undasherize(c)),""+e+": "+b)},humanizeKey:function(a,b){var d;return null==b&&(b=c.platform),a?(d="darwin"===b?f:g,d[a]?d[a]:1===a.length&&null!=i[a]?[d.shift,i[a]]:1===a.length&&a===a.toUpperCase()&&a.toUpperCase()!==a.toLowerCase()?[d.shift,a.toUpperCase()]:1===a.length||/f[0-9]{1,2}/.test(a)?a.toUpperCase():"darwin"===b?a:h.capitalize(a)):a},humanizeKeystroke:function(a,b){var d,e,f,g,i,j,l,m,n,o;if(null==b&&(b=c.platform),!a)return a;for(i=a.split(" "),d=[],l=0,n=i.length;n>l;l++){for(a=i[l],g=[],j=a.split("-"),e=m=0,o=j.length;o>m;e=++m)f=j[e],""===f&&""===j[e-1]&&(f="-"),f&&g.push(h.humanizeKey(f,b));g=k.uniq(k.flatten(g)),g="darwin"===b?g.join(""):g.join("+"),d.push(g)}return d.join(" ")},isSubset:function(a,b){return k.every(a,function(a){return k.include(b,a)})},losslessInvert:function(a){var b,c,d;b={};for(c in a)d=a[c],null==b[d]&&(b[d]=[]),b[d].push(c);return b},mapObject:function(a,b){var c,d,e,f,g,h,i;for(d={},h=Object.keys(a),f=0,g=h.length;g>f;f++)c=h[f],i=b(c,a[c]),c=i[0],e=i[1],d[c]=e;return d},multiplyString:function(a,b){var c,d;for(c="",d=0;b>d;)c+=a,d++;return c},pluralize:function(a,b,c){return null==a&&(a=0),null==c&&(c=b+"s"),1===a?""+a+" "+b:""+a+" "+c},remove:function(a,b){var c;return c=a.indexOf(b),c>=0&&a.splice(c,1),a},setValueForKeyPath:function(a,b,c){var d,e;for(e=j(b);e.length>1;)d=e.shift(),null==a[d]&&(a[d]={}),a=a[d];return null!=c?a[e.shift()]=c:delete a[e.shift()]},hasKeyPath:function(a,b){var c,d,e,f;for(d=j(b),e=0,f=d.length;f>e;e++){if(c=d[e],!a.hasOwnProperty(c))return!1;a=a[c]}return!0},spliceWithArray:function(a,b,c,d,e){var f,g,h,i;if(null==e&&(e=1e5),d.length<e)return a.splice.apply(a,[b,c].concat(l.call(d)));for(a.splice(b,c),i=[],f=g=0,h=d.length;e>0?h>=g:g>=h;f=g+=e)i.push(a.splice.apply(a,[b+f,0].concat(l.call(d.slice(f,f+e)))));return i},sum:function(a){var b,c,d,e;for(c=0,d=0,e=a.length;e>d;d++)b=a[d],c+=b;return c},uncamelcase:function(a){var b;return a?(b=a.replace(/([A-Z])|_+/g,function(a,b){return null==b&&(b="")," "+b}),h.capitalize(b.trim())):""},undasherize:function(a){return a?a.split("-").map(h.capitalize).join(" "):""},underscore:function(a){return a?(a=a[0].toLowerCase()+a.slice(1),a.replace(/([A-Z])|-+/g,function(a,b){return null==b&&(b=""),"_"+b.toLowerCase()})):""},valueForKeyPath:function(a,b){var c,d,e,f;for(d=j(b),e=0,f=d.length;f>e;e++)if(c=d[e],a=a[c],null==a)return;return a},isEqual:function(a,b,c,e){return k.isArray(c)&&k.isArray(e)?d(a,b,c,e):d(a,b)},isEqualForProperties:function(){var a,b,c,d,e,f;for(a=arguments[0],b=arguments[1],c=3<=arguments.length?l.call(arguments,2):[],e=0,f=c.length;f>e;e++)if(d=c[e],!k.isEqual(a[d],b[d]))return!1;return!0}},d=function(a,b,c,e){var f,g,h,i,j,l,m,n,o,p,q,r,s,t,u;if(null==c&&(c=[]),null==e&&(e=[]),a===b)return k.isEqual(a,b);if(k.isFunction(a)||k.isFunction(b))return k.isEqual(a,b);for(s=c.length;s--;)if(c[s]===a)return e[s]===b;if(c.push(a),e.push(b),p=!1,k.isFunction(null!=a?a.isEqual:void 0))p=a.isEqual(b,c,e);else if(k.isFunction(null!=b?b.isEqual:void 0))p=b.isEqual(a,e,c);else if(k.isArray(a)&&k.isArray(b)&&a.length===b.length){for(p=!0,q=t=0,u=a.length;u>t;q=++t)if(h=a[q],!d(h,b[q],c,e)){p=!1;break}}else if(k.isRegExp(a)&&k.isRegExp(b))p=k.isEqual(a,b);else if(k.isElement(a)&&k.isElement(b))p=a===b;else if(k.isObject(a)&&k.isObject(b))if(f=a.constructor,l=b.constructor,g=k.isFunction(f)&&f instanceof f,m=k.isFunction(l)&&l instanceof l,f===l||g&&m){i=0,p=!0;for(r in a)if(j=a[r],k.has(a,r)&&(i++,!k.has(b,r)||!d(j,b[r],c,e))){p=!1;break}if(p){n=0;for(r in b)o=b[r],k.has(b,r)&&n++;p=i===n}}else p=!1;else p=k.isEqual(a,b);return c.pop(),e.pop(),p},b.exports=k.extend({},k,h)}).call(this)}).call(this,a("_process"))},{_process:12,underscore:14}],14:[function(b,c,d){(function(){var b=this,e=b._,f={},g=Array.prototype,h=Object.prototype,i=Function.prototype,j=g.push,k=g.slice,l=g.concat,m=h.toString,n=h.hasOwnProperty,o=g.forEach,p=g.map,q=g.reduce,r=g.reduceRight,s=g.filter,t=g.every,u=g.some,v=g.indexOf,w=g.lastIndexOf,x=Array.isArray,y=Object.keys,z=i.bind,A=function(a){return a instanceof A?a:this instanceof A?void(this._wrapped=a):new A(a)};"undefined"!=typeof d?("undefined"!=typeof c&&c.exports&&(d=c.exports=A),d._=A):b._=A,A.VERSION="1.6.0";var B=A.each=A.forEach=function(a,b,c){if(null==a)return a;if(o&&a.forEach===o)a.forEach(b,c);else if(a.length===+a.length){for(var d=0,e=a.length;e>d;d++)if(b.call(c,a[d],d,a)===f)return}else for(var g=A.keys(a),d=0,e=g.length;e>d;d++)if(b.call(c,a[g[d]],g[d],a)===f)return;return a};A.map=A.collect=function(a,b,c){var d=[];return null==a?d:p&&a.map===p?a.map(b,c):(B(a,function(a,e,f){d.push(b.call(c,a,e,f))}),d)};var C="Reduce of empty array with no initial value";A.reduce=A.foldl=A.inject=function(a,b,c,d){var e=arguments.length>2;if(null==a&&(a=[]),q&&a.reduce===q)return d&&(b=A.bind(b,d)),e?a.reduce(b,c):a.reduce(b);if(B(a,function(a,f,g){e?c=b.call(d,c,a,f,g):(c=a,e=!0)}),!e)throw new TypeError(C);return c},A.reduceRight=A.foldr=function(a,b,c,d){var e=arguments.length>2;if(null==a&&(a=[]),r&&a.reduceRight===r)return d&&(b=A.bind(b,d)),e?a.reduceRight(b,c):a.reduceRight(b);var f=a.length;if(f!==+f){var g=A.keys(a);f=g.length}if(B(a,function(h,i,j){i=g?g[--f]:--f,e?c=b.call(d,c,a[i],i,j):(c=a[i],e=!0)}),!e)throw new TypeError(C);return c},A.find=A.detect=function(a,b,c){var d;return D(a,function(a,e,f){return b.call(c,a,e,f)?(d=a,!0):void 0}),d},A.filter=A.select=function(a,b,c){var d=[];return null==a?d:s&&a.filter===s?a.filter(b,c):(B(a,function(a,e,f){b.call(c,a,e,f)&&d.push(a)}),d)},A.reject=function(a,b,c){return A.filter(a,function(a,d,e){return!b.call(c,a,d,e)},c)},A.every=A.all=function(a,b,c){b||(b=A.identity);var d=!0;return null==a?d:t&&a.every===t?a.every(b,c):(B(a,function(a,e,g){return(d=d&&b.call(c,a,e,g))?void 0:f}),!!d)};var D=A.some=A.any=function(a,b,c){b||(b=A.identity);var d=!1;return null==a?d:u&&a.some===u?a.some(b,c):(B(a,function(a,e,g){return d||(d=b.call(c,a,e,g))?f:void 0}),!!d)};A.contains=A.include=function(a,b){return null==a?!1:v&&a.indexOf===v?-1!=a.indexOf(b):D(a,function(a){return a===b})},A.invoke=function(a,b){var c=k.call(arguments,2),d=A.isFunction(b);return A.map(a,function(a){return(d?b:a[b]).apply(a,c)})},A.pluck=function(a,b){return A.map(a,A.property(b))},A.where=function(a,b){return A.filter(a,A.matches(b))},A.findWhere=function(a,b){return A.find(a,A.matches(b))},A.max=function(a,b,c){if(!b&&A.isArray(a)&&a[0]===+a[0]&&a.length<65535)return Math.max.apply(Math,a);var d=-(1/0),e=-(1/0);return B(a,function(a,f,g){var h=b?b.call(c,a,f,g):a;h>e&&(d=a,e=h)}),d},A.min=function(a,b,c){if(!b&&A.isArray(a)&&a[0]===+a[0]&&a.length<65535)return Math.min.apply(Math,a);var d=1/0,e=1/0;return B(a,function(a,f,g){var h=b?b.call(c,a,f,g):a;e>h&&(d=a,e=h)}),d},A.shuffle=function(a){var b,c=0,d=[];return B(a,function(a){b=A.random(c++),d[c-1]=d[b],d[b]=a}),d},A.sample=function(a,b,c){return null==b||c?(a.length!==+a.length&&(a=A.values(a)),a[A.random(a.length-1)]):A.shuffle(a).slice(0,Math.max(0,b))};var E=function(a){return null==a?A.identity:A.isFunction(a)?a:A.property(a)};A.sortBy=function(a,b,c){return b=E(b),A.pluck(A.map(a,function(a,d,e){return{value:a,index:d,criteria:b.call(c,a,d,e)}}).sort(function(a,b){var c=a.criteria,d=b.criteria;if(c!==d){if(c>d||void 0===c)return 1;if(d>c||void 0===d)return-1}return a.index-b.index}),"value")};var F=function(a){return function(b,c,d){var e={};return c=E(c),B(b,function(f,g){var h=c.call(d,f,g,b);a(e,h,f)}),e}};A.groupBy=F(function(a,b,c){A.has(a,b)?a[b].push(c):a[b]=[c]}),A.indexBy=F(function(a,b,c){a[b]=c}),A.countBy=F(function(a,b){A.has(a,b)?a[b]++:a[b]=1}),A.sortedIndex=function(a,b,c,d){c=E(c);for(var e=c.call(d,b),f=0,g=a.length;g>f;){var h=f+g>>>1;c.call(d,a[h])<e?f=h+1:g=h}return f},A.toArray=function(a){return a?A.isArray(a)?k.call(a):a.length===+a.length?A.map(a,A.identity):A.values(a):[]},A.size=function(a){return null==a?0:a.length===+a.length?a.length:A.keys(a).length},A.first=A.head=A.take=function(a,b,c){return null==a?void 0:null==b||c?a[0]:0>b?[]:k.call(a,0,b)},A.initial=function(a,b,c){return k.call(a,0,a.length-(null==b||c?1:b))},A.last=function(a,b,c){return null==a?void 0:null==b||c?a[a.length-1]:k.call(a,Math.max(a.length-b,0))},A.rest=A.tail=A.drop=function(a,b,c){return k.call(a,null==b||c?1:b)},A.compact=function(a){return A.filter(a,A.identity)};var G=function(a,b,c){return b&&A.every(a,A.isArray)?l.apply(c,a):(B(a,function(a){A.isArray(a)||A.isArguments(a)?b?j.apply(c,a):G(a,b,c):c.push(a)}),c)};A.flatten=function(a,b){return G(a,b,[])},A.without=function(a){return A.difference(a,k.call(arguments,1))},A.partition=function(a,b){var c=[],d=[];return B(a,function(a){(b(a)?c:d).push(a)}),[c,d]},A.uniq=A.unique=function(a,b,c,d){A.isFunction(b)&&(d=c,c=b,b=!1);var e=c?A.map(a,c,d):a,f=[],g=[];return B(e,function(c,d){(b?d&&g[g.length-1]===c:A.contains(g,c))||(g.push(c),f.push(a[d]))}),f},A.union=function(){return A.uniq(A.flatten(arguments,!0))},A.intersection=function(a){var b=k.call(arguments,1);return A.filter(A.uniq(a),function(a){return A.every(b,function(b){return A.contains(b,a)})})},A.difference=function(a){var b=l.apply(g,k.call(arguments,1));return A.filter(a,function(a){return!A.contains(b,a)})},A.zip=function(){for(var a=A.max(A.pluck(arguments,"length").concat(0)),b=new Array(a),c=0;a>c;c++)b[c]=A.pluck(arguments,""+c);return b},A.object=function(a,b){if(null==a)return{};for(var c={},d=0,e=a.length;e>d;d++)b?c[a[d]]=b[d]:c[a[d][0]]=a[d][1];return c},A.indexOf=function(a,b,c){if(null==a)return-1;var d=0,e=a.length;if(c){if("number"!=typeof c)return d=A.sortedIndex(a,b),a[d]===b?d:-1;d=0>c?Math.max(0,e+c):c}if(v&&a.indexOf===v)return a.indexOf(b,c);for(;e>d;d++)if(a[d]===b)return d;return-1},A.lastIndexOf=function(a,b,c){if(null==a)return-1;var d=null!=c;if(w&&a.lastIndexOf===w)return d?a.lastIndexOf(b,c):a.lastIndexOf(b);for(var e=d?c:a.length;e--;)if(a[e]===b)return e;return-1},A.range=function(a,b,c){arguments.length<=1&&(b=a||0,a=0),c=arguments[2]||1;for(var d=Math.max(Math.ceil((b-a)/c),0),e=0,f=new Array(d);d>e;)f[e++]=a,a+=c;return f};var H=function(){};A.bind=function(a,b){var c,d;if(z&&a.bind===z)return z.apply(a,k.call(arguments,1));if(!A.isFunction(a))throw new TypeError;return c=k.call(arguments,2),d=function(){if(!(this instanceof d))return a.apply(b,c.concat(k.call(arguments)));H.prototype=a.prototype;var e=new H;H.prototype=null;var f=a.apply(e,c.concat(k.call(arguments)));return Object(f)===f?f:e}},A.partial=function(a){var b=k.call(arguments,1);return function(){for(var c=0,d=b.slice(),e=0,f=d.length;f>e;e++)d[e]===A&&(d[e]=arguments[c++]);for(;c<arguments.length;)d.push(arguments[c++]);return a.apply(this,d)}},A.bindAll=function(a){var b=k.call(arguments,1);if(0===b.length)throw new Error("bindAll must be passed function names");return B(b,function(b){a[b]=A.bind(a[b],a)}),a},A.memoize=function(a,b){var c={};return b||(b=A.identity),function(){var d=b.apply(this,arguments);return A.has(c,d)?c[d]:c[d]=a.apply(this,arguments)}},A.delay=function(a,b){var c=k.call(arguments,2);return setTimeout(function(){return a.apply(null,c)},b)},A.defer=function(a){return A.delay.apply(A,[a,1].concat(k.call(arguments,1)))},A.throttle=function(a,b,c){var d,e,f,g=null,h=0;c||(c={});var i=function(){h=c.leading===!1?0:A.now(),g=null,f=a.apply(d,e),d=e=null};return function(){var j=A.now();h||c.leading!==!1||(h=j);var k=b-(j-h);return d=this,e=arguments,0>=k?(clearTimeout(g),g=null,h=j,f=a.apply(d,e),d=e=null):g||c.trailing===!1||(g=setTimeout(i,k)),f}},A.debounce=function(a,b,c){var d,e,f,g,h,i=function(){var j=A.now()-g;b>j?d=setTimeout(i,b-j):(d=null,c||(h=a.apply(f,e),f=e=null))};return function(){f=this,e=arguments,g=A.now();var j=c&&!d;return d||(d=setTimeout(i,b)),j&&(h=a.apply(f,e),f=e=null),h}},A.once=function(a){var b,c=!1;return function(){return c?b:(c=!0,b=a.apply(this,arguments),a=null,b)}},A.wrap=function(a,b){return A.partial(b,a)},A.compose=function(){var a=arguments;return function(){for(var b=arguments,c=a.length-1;c>=0;c--)b=[a[c].apply(this,b)];return b[0]}},A.after=function(a,b){return function(){return--a<1?b.apply(this,arguments):void 0}},A.keys=function(a){if(!A.isObject(a))return[];if(y)return y(a);var b=[];for(var c in a)A.has(a,c)&&b.push(c);return b},A.values=function(a){for(var b=A.keys(a),c=b.length,d=new Array(c),e=0;c>e;e++)d[e]=a[b[e]];return d},A.pairs=function(a){for(var b=A.keys(a),c=b.length,d=new Array(c),e=0;c>e;e++)d[e]=[b[e],a[b[e]]];return d},A.invert=function(a){for(var b={},c=A.keys(a),d=0,e=c.length;e>d;d++)b[a[c[d]]]=c[d];return b},A.functions=A.methods=function(a){var b=[];for(var c in a)A.isFunction(a[c])&&b.push(c);return b.sort()},A.extend=function(a){return B(k.call(arguments,1),function(b){if(b)for(var c in b)a[c]=b[c]}),a},A.pick=function(a){var b={},c=l.apply(g,k.call(arguments,1));return B(c,function(c){c in a&&(b[c]=a[c])}),b},A.omit=function(a){var b={},c=l.apply(g,k.call(arguments,1));for(var d in a)A.contains(c,d)||(b[d]=a[d]);return b},A.defaults=function(a){return B(k.call(arguments,1),function(b){if(b)for(var c in b)void 0===a[c]&&(a[c]=b[c])}),a},A.clone=function(a){return A.isObject(a)?A.isArray(a)?a.slice():A.extend({},a):a},A.tap=function(a,b){return b(a),a};var I=function(a,b,c,d){if(a===b)return 0!==a||1/a==1/b;if(null==a||null==b)return a===b;a instanceof A&&(a=a._wrapped),b instanceof A&&(b=b._wrapped);var e=m.call(a);if(e!=m.call(b))return!1;switch(e){case"[object String]":return a==String(b);case"[object Number]":return a!=+a?b!=+b:0==a?1/a==1/b:a==+b;case"[object Date]":case"[object Boolean]":return+a==+b;case"[object RegExp]":return a.source==b.source&&a.global==b.global&&a.multiline==b.multiline&&a.ignoreCase==b.ignoreCase}if("object"!=typeof a||"object"!=typeof b)return!1;for(var f=c.length;f--;)if(c[f]==a)return d[f]==b;var g=a.constructor,h=b.constructor;if(g!==h&&!(A.isFunction(g)&&g instanceof g&&A.isFunction(h)&&h instanceof h)&&"constructor"in a&&"constructor"in b)return!1;c.push(a),d.push(b);var i=0,j=!0;if("[object Array]"==e){if(i=a.length,j=i==b.length)for(;i--&&(j=I(a[i],b[i],c,d)););}else{for(var k in a)if(A.has(a,k)&&(i++,!(j=A.has(b,k)&&I(a[k],b[k],c,d))))break;if(j){for(k in b)if(A.has(b,k)&&!i--)break;j=!i}}return c.pop(),d.pop(),j};A.isEqual=function(a,b){return I(a,b,[],[])},A.isEmpty=function(a){if(null==a)return!0;if(A.isArray(a)||A.isString(a))return 0===a.length;for(var b in a)if(A.has(a,b))return!1;return!0},A.isElement=function(a){return!(!a||1!==a.nodeType)},A.isArray=x||function(a){return"[object Array]"==m.call(a)},A.isObject=function(a){return a===Object(a)},B(["Arguments","Function","String","Number","Date","RegExp"],function(a){A["is"+a]=function(b){return m.call(b)=="[object "+a+"]"}}),A.isArguments(arguments)||(A.isArguments=function(a){return!(!a||!A.has(a,"callee"))}),"function"!=typeof/./&&(A.isFunction=function(a){return"function"==typeof a}),A.isFinite=function(a){return isFinite(a)&&!isNaN(parseFloat(a))},A.isNaN=function(a){return A.isNumber(a)&&a!=+a},A.isBoolean=function(a){return a===!0||a===!1||"[object Boolean]"==m.call(a)},A.isNull=function(a){return null===a},A.isUndefined=function(a){return void 0===a},A.has=function(a,b){return n.call(a,b)},A.noConflict=function(){return b._=e,this},A.identity=function(a){return a},A.constant=function(a){return function(){return a}},A.property=function(a){return function(b){return b[a]}},A.matches=function(a){return function(b){if(b===a)return!0;for(var c in a)if(a[c]!==b[c])return!1;return!0}},A.times=function(a,b,c){for(var d=Array(Math.max(0,a)),e=0;a>e;e++)d[e]=b.call(c,e);return d},A.random=function(a,b){return null==b&&(b=a,a=0),a+Math.floor(Math.random()*(b-a+1))},A.now=Date.now||function(){return(new Date).getTime()};var J={escape:{"&":"&","<":"<",">":">",'"':""","'":"'"}};J.unescape=A.invert(J.escape);var K={escape:new RegExp("["+A.keys(J.escape).join("")+"]","g"),unescape:new RegExp("("+A.keys(J.unescape).join("|")+")","g")};A.each(["escape","unescape"],function(a){A[a]=function(b){return null==b?"":(""+b).replace(K[a],function(b){return J[a][b]})}}),A.result=function(a,b){if(null==a)return void 0;var c=a[b];return A.isFunction(c)?c.call(a):c},A.mixin=function(a){B(A.functions(a),function(b){var c=A[b]=a[b];A.prototype[b]=function(){var a=[this._wrapped];return j.apply(a,arguments),P.call(this,c.apply(A,a))}})};var L=0;A.uniqueId=function(a){var b=++L+"";return a?a+b:b},A.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var M=/(.)^/,N={"'":"'","\\":"\\","\r":"r","\n":"n"," ":"t","\u2028":"u2028","\u2029":"u2029"},O=/\\|'|\r|\n|\t|\u2028|\u2029/g;A.template=function(a,b,c){var d;c=A.defaults({},c,A.templateSettings);var e=new RegExp([(c.escape||M).source,(c.interpolate||M).source,(c.evaluate||M).source].join("|")+"|$","g"),f=0,g="__p+='";a.replace(e,function(b,c,d,e,h){return g+=a.slice(f,h).replace(O,function(a){return"\\"+N[a]}),c&&(g+="'+\n((__t=("+c+"))==null?'':_.escape(__t))+\n'"),d&&(g+="'+\n((__t=("+d+"))==null?'':__t)+\n'"),e&&(g+="';\n"+e+"\n__p+='"),f=h+b.length,b}),g+="';\n",c.variable||(g="with(obj||{}){\n"+g+"}\n"),g="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+g+"return __p;\n";try{d=new Function(c.variable||"obj","_",g)}catch(h){throw h.source=g,h}if(b)return d(b,A);var i=function(a){return d.call(this,a,A)};return i.source="function("+(c.variable||"obj")+"){\n"+g+"}",i},A.chain=function(a){return A(a).chain()};var P=function(a){return this._chain?A(a).chain():a};A.mixin(A),B(["pop","push","reverse","shift","sort","splice","unshift"],function(a){var b=g[a];A.prototype[a]=function(){var c=this._wrapped;return b.apply(c,arguments),"shift"!=a&&"splice"!=a||0!==c.length||delete c[0],P.call(this,c)}}),B(["concat","join","slice"],function(a){var b=g[a];A.prototype[a]=function(){return P.call(this,b.apply(this._wrapped,arguments))}}),A.extend(A.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}}),"function"==typeof a&&a.amd&&a("underscore",[],function(){return A})}).call(this)},{}],15:[function(a,b,c){"use strict";function d(a,b){void 0===b?(this.offset=a,this.x=this.offset%8,this.y=Math.floor(this.offset/8)):(this.offset=a+8*b,this.x=a,this.y=b)}d.prototype.add=function(a){return new d(this.x+a.x,this.y+a.y)},d.prototype.sub=function(a){return new d(this.x-a.x,this.y-a.y)},d.prototype.isValid=function(){return this.x>=0&&this.x<8&&this.y>=0&&this.y<8},b.exports={BoardCoordinates:d}},{}],16:[function(a,b,c){"use strict";function d(a,b,c){for(var d=c?c:a.turn,e=[],g=0;64>g;g++){var h=a.board[g];null!=h&&h.type===b&&h.side===d&&e.push(g)}var i=[];return e.forEach(function(a){i.push(new f(a))}),i}var e=a("./coordinates"),f=e.BoardCoordinates;b.exports={findPiece:d}},{"./coordinates":15}],17:[function(a,b,c){"use strict";function d(a,b){return b.isValid()&&null==a.board[b.offset]}function e(a,b){if(!b.isValid())return!1;var c=a.board[b.offset];return null!=c&&a.turn!==c.side}function f(a,b){if(!b.isValid())return!1;var c=a.board[b.offset];return null==c||a.turn!==c.side}function g(a,b,c,f){for(var g=b;;){if(g=g.add(c),!g.isValid())break;if(!d(a,g)){e(a,g)&&f.push(g);break}f.push(g)}}function h(a){for(var b=[],c=0;64>=c;c++){var d=a.board[c],e=new i(c);if(null!=d&&d.side===a.turn){var f=j[d.type](a,e);f.forEach(function(a){b.push({src:e.offset,dst:a.offset})})}}return b}var i=a("./coordinates").BoardCoordinates,j=[];j.P=function(a,b){var c="W"==a.turn?1:-1,f="W"==a.turn?1:6,g=b.add(new i(0,c)),h=g.add(new i(0,c)),j=b.add(new i(1,c)),k=b.add(new i(-1,c)),l=[];return d(a,g)&&l.push(g),e(a,k)?l.push(k):a.lastPawnMoveColumn==b.x-1&&(b.y-f)/c==3&&l.push(k),e(a,j)?l.push(j):a.lastPawnMoveColumn==b.x+1&&(b.y-f)/c==3&&l.push(j),b.y==f&&d(a,g)&&d(a,h)&&l.push(h),l},j.N=function(a,b){var c=[];return[b.add(new i(-1,2)),b.add(new i(1,2)),b.add(new i(2,-1)),b.add(new i(2,1)),b.add(new i(1,-2)),b.add(new i(-1,-2)),b.add(new i(-2,1)),b.add(new i(-2,-1))].forEach(function(b){f(a,b)&&c.push(b)}),c},j.B=function(a,b){var c=[];return[new i(-1,-1),new i(-1,1),new i(1,-1),new i(1,1)].forEach(function(d){g(a,b,d,c)}),c},j.R=function(a,b){var c=[];return[new i(-1,0),new i(1,0),new i(0,-1),new i(0,1)].forEach(function(d){g(a,b,d,c)}),c},j.K=function(a,b){for(var c=[],e=-1;2>e;e++)for(var g=-1;2>g;g++)if(0!=e||0!=g){var h=new i(e,g),j=b.add(h);f(a,j)&&c.push(j)}if(a.castlingFlags[a.turn].K){var k=b.add(new i(1,0)),l=b.add(new i(2,0));d(a,k)&&d(a,l)&&c.push(l)}if(a.castlingFlags[a.turn].Q){var k=b.add(new i(-1,0)),l=b.add(new i(-2,0)); | ||
d(a,k)&&d(a,l)&&c.push(l)}return c},j.Q=function(a,b){var c=[];return[new i(-1,0),new i(1,0),new i(0,-1),new i(0,1),new i(-1,-1),new i(-1,1),new i(1,-1),new i(1,1)].forEach(function(d){g(a,b,d,c)}),c},b.exports={computeAllMoves:h,pieceDestinationsEvaluator:j}},{"./coordinates":15}],18:[function(a,b,c){"use strict";function d(a,b,c){for(var d=null,e=0;64>e;e++){var f=a.board[e];if(null!=f&&f.type===b&&f.side===c){d=e;break}}return d}function e(a){var b=i.computeAllMoves(a),c=[],e=function(b,c,e){var f=h.applyMove(a,b),g=i.computeAllMoves(f),j=d(f,c,e),k=!1;return g.forEach(function(a){a.dst==j&&(k=!0)}),k};return b.forEach(function(b){var d=new j(b.src),f=new j(b.dst),g=f.sub(d),h=e(b,"K",a.turn);"K"==a.board[b.src].type&&2==g.x&&(h=h||e({src:b.src,dst:b.src+1},"K",a.turn)),"K"==a.board[b.src].type&&-2==g.x&&(h=h||e({src:b.src,dst:b.src-1},"K",a.turn)),h||c.push(b)}),c}function f(a){var b=!1,c=a.turn;a.turn="W"===c?"B":"W";for(var d=0;64>=d;d++){var e=a.board[d],f=new j(d);if(null!=e&&e.side===a.turn){var g=i.pieceDestinationsEvaluator[e.type](a,f);g.forEach(function(c){var d=a.board[c.offset];d&&"K"===d.type&&d.side!==a.turn&&(b=!0)})}}return a.turn=c,b}var g=a("./coordinates"),h=a("./updates"),i=a("./moves-pieces"),j=g.BoardCoordinates;b.exports={getAvailableMoves:e,isCurrentPlayerInCheck:f}},{"./coordinates":15,"./moves-pieces":17,"./updates":24}],19:[function(a,b,c){"use strict";function d(a){var b="";return b+=String.fromCharCode("a".charCodeAt(0)+a%8),b+=String.fromCharCode("1".charCodeAt(0)+Math.floor(a/8))}function e(a,b){var c=null,d=j[b];if(d)c=d[a.turn];else{var e=i.parsePgnMove(b);if(e){var f=g.getAvailableMoves(a);f.forEach(function(b){(null==e.srcCol||b.src%8==e.srcCol)&&(null==e.srcRow||Math.floor(b.src/8)==e.srcRow)&&b.dst==e.dst&&a.board[b.src].type==e.type&&(e.src=b.src)}),null!=e.src&&null!=e.dst&&(c={src:e.src,dst:e.dst})}}return c}function f(a,b){var c="",e=a.board[b.src];if("P"!=e.type&&(c+=e.type),"K"===e.type&&b.dst-b.src==2)return"O-O";if("K"===e.type&&b.dst-b.src==-2)return"O-O-O";var f=g.getAvailableMoves(a),i=[];f.forEach(function(c){c.dst==b.dst&&e.type==a.board[c.src].type&&i.push(c.src)});var j=d(b.src);if(i.length>1){var k=d(i[0]),l=d(i[1]);c+=k[0]==l[0]?j[1]:j[0]}null!=a.board[b.dst]&&(""==c&&"P"==e.type&&(c+=j[0]),c+="x"),c+=d(b.dst);var m=h.applyMove(a,b);return"P"==e.type&&(b.dst<8||b.dst>56)&&(c+="=Q"),g.isCurrentPlayerInCheck(m)&&(c+="+"),c}var g=a("./moves"),h=a("./updates"),i=a("./pgnParser"),j={"O-O":{W:{src:4,dst:6},B:{src:60,dst:62}},"O-O-O":{W:{src:4,dst:2},B:{src:60,dst:58}}};b.exports={pgnToMove:e,moveToPgn:f}},{"./moves":18,"./pgnParser":20,"./updates":24}],20:[function(a,b,c){"use strict";function d(a,b){var c=null,d=a.charCodeAt(b)-f,e=a.charCodeAt(b+1)-g;return d>=0&&8>d&&e>=0&&8>e&&(c+=d,c+=8*e),c}function e(a){var b={type:null,srcCol:null,srcRow:null,dst:null,promotion:null,capture:!1,checking:!1,mate:!1},c=0,e=a.length;-1!=["P","R","N","B","K","Q"].indexOf(a[c])?(b.type=a[c],c++):b.type="P";var h=a.indexOf("+"),i=a.indexOf("#"),j=a.indexOf("=");h>=0&&(b.checking=!0,e=h),i>=0&&(b.mate=!0,e=i),j>=0&&(b.promotion=a.substring(j+1,j+2),e=j);var k=d(a,e-2);if(null==k)return null;b.dst=k,e-=2,"x"===a[e-1]&&(e-=1,b.capture=!0);for(var l=c;e>l;l++){var m=a.charCodeAt(c),n=m-g,o=m-f;n>=0&&8>n&&(b.srcRow=n),o>=0&&8>o&&(b.srcCol=o)}return b}var f="a".charCodeAt(0),g="1".charCodeAt(0);b.exports={parsePgnMove:e}},{}],21:[function(a,b,c){"use strict";function d(a,b){return{type:a,side:b}}function e(a){return f[a.type.concat(a.side)]}var f={PW:"♙",PB:"♟",NW:"♘",NB:"♞",BW:"♗",BB:"♝",RW:"♖",RB:"♜",QW:"♕",QB:"♛",KW:"♔",KB:"♚"};b.exports={pieceFactory:d,pieceToUTF8:e}},{}],22:[function(a,b,c){"use strict";function d(a){return j.deepClone(a)}function e(){return{turn:"W",castlingFlags:{W:{K:!0,Q:!0},B:{K:!0,Q:!0}},lastPawnMoveColumn:null,check:!1,board:[h.pieceFactory("R","W"),h.pieceFactory("N","W"),h.pieceFactory("B","W"),h.pieceFactory("Q","W"),h.pieceFactory("K","W"),h.pieceFactory("B","W"),h.pieceFactory("N","W"),h.pieceFactory("R","W"),h.pieceFactory("P","W"),h.pieceFactory("P","W"),h.pieceFactory("P","W"),h.pieceFactory("P","W"),h.pieceFactory("P","W"),h.pieceFactory("P","W"),h.pieceFactory("P","W"),h.pieceFactory("P","W"),null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,h.pieceFactory("P","B"),h.pieceFactory("P","B"),h.pieceFactory("P","B"),h.pieceFactory("P","B"),h.pieceFactory("P","B"),h.pieceFactory("P","B"),h.pieceFactory("P","B"),h.pieceFactory("P","B"),h.pieceFactory("R","B"),h.pieceFactory("N","B"),h.pieceFactory("B","B"),h.pieceFactory("Q","B"),h.pieceFactory("K","B"),h.pieceFactory("B","B"),h.pieceFactory("N","B"),h.pieceFactory("R","B")]}}function f(a,b,c,d){var e;return e=(a+b)%2==0?"W"===c?d.WB:d.BB:"W"===c?d.WW:d.BW}function g(a,b){var c=[];c.push("W"==a.turn?"WHITE":"BLACK"),c.push(" "),c.push(a.castlingFlags.W.K?"K":""),c.push(a.castlingFlags.W.Q?"Q":""),c.push(a.castlingFlags.B.K?"k":""),c.push(a.castlingFlags.B.Q?"q":"");var d,e;for(d=7;d>=0;d--)for(c.push("\n"),c.push(d+1),c.push(" "),e=0;8>e;e++){var g=a.board[8*d+e];b?null==g?c.push(f(d,e,"W"," ")):c.push(f(d,e,g.side,h.pieceToUTF8(g)+" ")):null==g?c.push(". "):"W"==g.side?c.push(g.type.toUpperCase()+" "):c.push(g.type.toLowerCase()+" ")}return c.push("\n a b c d e f g h "),c.join("")}var h=a("./piece"),i=a("colors");i.setTheme({BW:["black","bgWhite"],BB:["black","bgMagenta"],WW:["white","bgWhite"],WB:["white","bgMagenta"]});var j=a("underscore-plus");b.exports={getInitialPosition:e,positionToString:g,clone:d}},{"./piece":21,colors:5,"underscore-plus":13}],23:[function(a,b,c){"use strict";function d(a){var b=e.getAvailableMoves(a),c="OPEN";return 0==b.length&&(c=a.check?"W"==a.turn?"BLACKWON":"WHITEWON":"PAT"),c}var e=a("./moves");b.exports={getGameStatus:d}},{"./moves":18}],24:[function(a,b,c){"use strict";function d(a,b){var c=[],d=new j(b.src),f=new j(b.dst),g=f.sub(d),h=a.board[b.dst];if(null!=h&&c.push({action:"remove",src:b.dst}),c.push({action:"move",src:b.src,dst:b.dst}),null==h&&"P"==a.board[b.src].type&&Math.abs(g.x)){var k=d.add(new j(g.x,0));c.push({action:"remove",src:k.offset})}"P"==a.board[b.src].type&&2==Math.abs(g.y)?c.push({action:"pawnColumn",col:b.src%8}):c.push({action:"pawnColumn",col:null}),"P"!=a.board[b.src].type||0!=f.y&&7!=f.y||c.push({action:"promote",src:b.dst}),"K"==a.board[b.src].type&&(c.push({action:"resetCastling",sides:["K","Q"]}),4==d.x&&6==f.x&&c.push({action:"move",src:f.add(new j(1,0)).offset,dst:f.add(new j(-1,0)).offset}),4==d.x&&2==f.x&&c.push({action:"move",src:f.add(new j(-2,0)).offset,dst:f.add(new j(1,0)).offset})),"R"==a.board[b.src].type&&0==d.x&&c.push({action:"resetCastling",sides:["Q"]}),"R"==a.board[b.src].type&&7==d.x&&c.push({action:"resetCastling",sides:["K"]});var l=e(a,c);l.turn=a.turn;var m=!1;return i.computeAllMoves(l).forEach(function(b){var c=a.board[b.dst];c&&"K"==c.type&&c.side!=a.turn&&(m=!0)}),c.push({action:"updateCheckFlag",value:m}),c}function e(a,b){var c=g.clone(a);return b.forEach(function(b){if("remove"===b.action){var d=b.src;c.board[d]=null}else"move"===b.action?(c.board[b.dst]=c.board[b.src],c.board[b.src]=null):"pawnColumn"===b.action?c.lastPawnMoveColumn=b.col:"resetCastling"===b.action?b.sides.forEach(function(b){c.castlingFlags[a.turn][b]=!1}):"updateCheckFlag"===b.action?c.check=b.value:"promote"===b.action&&(c.board[b.src].type="Q")}),c.turn="W"===a.turn?"B":"W",c}function f(a,b){var c=d(a,b);return e(a,c)}var g=a("./position"),h=a("./coordinates"),i=a("./moves-pieces"),j=h.BoardCoordinates;b.exports={computeDiffs:d,applyDiffs:e,applyMove:f}},{"./coordinates":15,"./moves-pieces":17,"./position":22}],25:[function(a,b,c){"use strict";var d=a("./chess/position"),e=a("./chess/moves"),f=a("./chess/updates"),g=a("./chess/pgn"),h=a("./chess/status"),i=a("./chess/locator"),j={getInitialPosition:d.getInitialPosition,positionToString:d.positionToString,getAvailableMoves:e.getAvailableMoves,applyMove:f.applyMove,computeDiffs:f.computeDiffs,applyDiffs:f.applyDiffs,pgnToMove:g.pgnToMove,moveToPgn:g.moveToPgn,getGameStatus:h.getGameStatus,findPiece:i.findPiece};b.exports=j},{"./chess/locator":16,"./chess/moves":18,"./chess/pgn":19,"./chess/position":22,"./chess/status":23,"./chess/updates":24}]},{},[25])(25)}); |
{ | ||
"name": "chess-rules", | ||
"version": "0.10.2", | ||
"version": "0.11.0", | ||
"description": "Chess Rules implementation as a standalone module.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/chesscorp/chess-rules", |
204
README.md
@@ -5,12 +5,14 @@ [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Coverage Status](https://coveralls.io/repos/ChessCorp/chess-rules/badge.svg?branch=master&service=github)](https://coveralls.io/github/ChessCorp/chess-rules?branch=master) | ||
# Install | ||
## Install as node bundle | ||
## As a Node module | ||
```sh | ||
$ npm install --save chess-rules | ||
$ npm install chess-rules | ||
``` | ||
This will install rules module in the node_modules folder and update your package.json. | ||
This will install rules module in the node_modules folder. | ||
## Install using bower | ||
## Using Bower | ||
@@ -31,11 +33,23 @@ ```sh | ||
## Usage | ||
# Usage | ||
### Import the main rules object | ||
## Import the main rules object | ||
```js | ||
var chessRules = require('chess-rules'); | ||
> var chessRules = require('chess-rules'); | ||
> chessRules | ||
{ getInitialPosition: [Function: getInitialPosition], | ||
positionToString: [Function: positionToString], | ||
getAvailableMoves: [Function: getAvailableMoves], | ||
applyMove: [Function: applyMove], | ||
computeDiffs: [Function: computeDiffs], | ||
applyDiffs: [Function: applyDiffs], | ||
pgnToMove: [Function: pgnToMove], | ||
moveToPgn: [Function: moveToPgn], | ||
getGameStatus: [Function: getGameStatus] | ||
} | ||
``` | ||
### Instantiate an initial position model | ||
## Instantiate an initial position model | ||
@@ -46,3 +60,177 @@ ```js | ||
The position model used by the internal engine has the following structure: | ||
```js | ||
{ turn: 'W', | ||
castlingFlags: { W: { K: true, Q: true }, B: { K: true, Q: true } }, | ||
lastPawnMoveColumn: null, | ||
check: false, | ||
board: | ||
[ { type: 'R', side: 'W' }, | ||
{ type: 'N', side: 'W' }, | ||
{ type: 'B', side: 'W' }, | ||
{ type: 'Q', side: 'W' }, | ||
{ type: 'K', side: 'W' }, | ||
{ type: 'B', side: 'W' }, | ||
{ type: 'N', side: 'W' }, | ||
{ type: 'R', side: 'W' }, | ||
{ type: 'P', side: 'W' }, | ||
{ type: 'P', side: 'W' }, | ||
{ type: 'P', side: 'W' }, | ||
{ type: 'P', side: 'W' }, | ||
{ type: 'P', side: 'W' }, | ||
{ type: 'P', side: 'W' }, | ||
{ type: 'P', side: 'W' }, | ||
{ type: 'P', side: 'W' }, | ||
null, | ||
null, | ||
null, | ||
... | ||
] | ||
} | ||
``` | ||
The position can be logged more conveniently using the provided function positionToString: | ||
```js | ||
> console.log(chessRules.positionToString(position)) | ||
WHITE KQkq | ||
8 r n b q k b n r | ||
7 p p p p p p p p | ||
6 . . . . . . . . | ||
5 . . . . . . . . | ||
4 . . . . . . . . | ||
3 . . . . . . . . | ||
2 P P P P P P P P | ||
1 R N B Q K B N R | ||
a b c d e f g h | ||
``` | ||
An extra parameter can be provided to use extended charsets but may not be supported by all terminals: | ||
```js | ||
> console.log(chessRules.positionToString(position, true)) | ||
WHITE KQkq | ||
8 ♜ ♞ ♝ ♛ ♚ ♝ ♞ ♜ | ||
7 ♟ ♟ ♟ ♟ ♟ ♟ ♟ ♟ | ||
6 | ||
5 | ||
4 | ||
3 | ||
2 ♙ ♙ ♙ ♙ ♙ ♙ ♙ ♙ | ||
1 ♖ ♘ ♗ ♕ ♔ ♗ ♘ ♖ | ||
a b c d e f g h | ||
``` | ||
## Get available moves for a given position | ||
Moves are expressed as a pair of coordinates on the board. The offset value is computed row by row starting at A1. | ||
```js | ||
> var availableMoves = chessRules.getAvailableMoves(position); | ||
undefined | ||
> availableMoves | ||
[ { src: 1, dst: 16 }, | ||
{ src: 1, dst: 18 }, | ||
{ src: 6, dst: 21 }, | ||
{ src: 6, dst: 23 }, | ||
{ src: 8, dst: 16 }, | ||
{ src: 8, dst: 24 }, | ||
{ src: 9, dst: 17 }, | ||
{ src: 9, dst: 25 }, | ||
{ src: 10, dst: 18 }, | ||
{ src: 10, dst: 26 }, | ||
{ src: 11, dst: 19 }, | ||
{ src: 11, dst: 27 }, | ||
{ src: 12, dst: 20 }, | ||
{ src: 12, dst: 28 }, | ||
{ src: 13, dst: 21 }, | ||
{ src: 13, dst: 29 }, | ||
{ src: 14, dst: 22 }, | ||
{ src: 14, dst: 30 }, | ||
{ src: 15, dst: 23 }, | ||
{ src: 15, dst: 31 } ] | ||
> | ||
``` | ||
## Converting a move from / to PGN movetext notation | ||
PGN move text is described here [https://en.wikipedia.org/wiki/Portable_Game_Notation](https://en.wikipedia.org/wiki/Portable_Game_Notation) | ||
Converting move text to move vector: | ||
```js | ||
> chessRules.pgnToMove(position, 'e4') | ||
{ src: 12, dst: 28 } | ||
> chessRules.pgnToMove(position, 'Pe2e4') | ||
{ src: 12, dst: 28 } | ||
> chessRules.pgnToMove(position, 'Nf3') | ||
{ src: 6, dst: 21 } | ||
``` | ||
Converting move vector to PGN move text: | ||
```js | ||
> chessRules.moveToPgn(position, { src: 6, dst: 23 }); | ||
'Nh3' | ||
``` | ||
Note: the position must always be provided because the way that the moves are shortened requires access to the current piece positions to make these transforms. | ||
## Update the position by playing moves | ||
The **applyMove** will apply a move vector to create a new updated position structure. The original position object remains unchanged. | ||
```js | ||
> var moveE4 = chessRules.pgnToMove(position,'e4'); | ||
undefined | ||
> var updatedPosition = chessRules.applyMove(position, moveE4); | ||
undefined | ||
> console.log(chessRules.positionToString(position)) | ||
WHITE KQkq | ||
8 r n b q k b n r | ||
7 p p p p p p p p | ||
6 . . . . . . . . | ||
5 . . . . . . . . | ||
4 . . . . . . . . | ||
3 . . . . . . . . | ||
2 P P P P P P P P | ||
1 R N B Q K B N R | ||
a b c d e f g h | ||
undefined | ||
> console.log(chessRules.positionToString(updatedPosition)) | ||
BLACK KQkq | ||
8 r n b q k b n r | ||
7 p p p p p p p p | ||
6 . . . . . . . . | ||
5 . . . . . . . . | ||
4 . . . . P . . . | ||
3 . . . . . . . . | ||
2 P P P P . P P P | ||
1 R N B Q K B N R | ||
a b c d e f g h | ||
undefined | ||
> | ||
``` | ||
## Determine game status | ||
A game status can be either: | ||
* OPEN - The game is still in progress | ||
* PAT - The game has ended as one of the players couldn't move anymore while not being checkmate | ||
* WHITEWON - The white player won | ||
* BLACKWON - The black player won | ||
```js | ||
> chessRules.getGameStatus(position) | ||
'OPEN' | ||
``` | ||
## License | ||
@@ -49,0 +237,0 @@ |
@@ -8,2 +8,3 @@ 'use strict'; | ||
var status = require('./chess/status'); | ||
var locator = require('./chess/locator'); | ||
@@ -19,5 +20,6 @@ var chessRules = { | ||
moveToPgn: pgn.moveToPgn, | ||
getGameStatus: status.getGameStatus | ||
getGameStatus: status.getGameStatus, | ||
findPiece: locator.findPiece | ||
}; | ||
module.exports = chessRules; |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
181614
15
4025
244