UNPKG

stockfish

Version:

The Stockfish chess engine in Web Assembly (WASM)

9 lines • 28.1 kB
/*! * Stockfish.js 19 (c) 2026, Chess.com, LLC * https://github.com/nmrugg/stockfish.js * License: GPLv3 * * Based on Stockfish (c) T. Romstad, M. Costalba, J. Kiiski, G. Linscott and other contributors. * https://github.com/official-stockfish/Stockfish */ !function(){function e(){var e,t=(e=globalThis.document?.currentScript?.src,async function(t={}){var r=t,n=!!globalThis.window,a=!!globalThis.WorkerGlobalScope,o=globalThis.process?.versions?.node&&"renderer"!=globalThis.process?.type;"undefined"!=typeof global&&"[object process]"===Object.prototype.toString.call(global.process)&&"undefined"!=typeof fetch&&("undefined"==typeof XMLHttpRequest&&(global.XMLHttpRequest=function(){var e,t={readyState:0,status:0,onerror:null,onreadystatechange:null,onload:null,open:function(t,r){e=r},send:function(){require("fs").readFile(e,function(e,r){t.readyState=4,e?(t.status=404,t.onerror(e)):(t.status=200,t.response=r,t.onreadystatechange(),t.onload())})}};return t}),fetch=null),r.print=function(e){r.listener&&r.listener(e)},r.printErr=function(e){r.listener&&r.listener(e)},r.terminate=function(){"undefined"!=typeof PThread&&PThread.Ha()};var i=[],s="./this.program",f=(e,t)=>{throw t};"undefined"!=typeof __filename?e=__filename:a&&(e=self.location.href);var u,l,c="";if(o){var d=require("node:fs");c=__dirname+"/",l=e=>(e=y(e)?new URL(e):e,d.readFileSync(e)),u=async e=>(e=y(e)?new URL(e):e,d.readFileSync(e,void 0)),process.argv.length>1&&(s=process.argv[1].replace(/\\/g,"/")),i=process.argv.slice(2),f=(e,t)=>{throw process.exitCode=e,t}}else if(n||a){try{c=new URL(".",e).href}catch{}a&&(l=e=>{var t=new XMLHttpRequest;return t.open("GET",e,!1),t.responseType="arraybuffer",t.send(null),new Uint8Array(t.response)}),u=async e=>{if((e=await fetch(e,{credentials:"same-origin"})).ok)return e.arrayBuffer();throw Error(e.status+" : "+e.url)}}var h,m,w=function(){}.bind(),p=function(){}.bind(),v=!1,y=e=>e.startsWith("file://");function g(){if(!S?.buffer?.resizable){var e=Ke.buffer;S=new Int8Array(e),ge=new Int16Array(e),pe=new Uint8Array(e),F=new Int32Array(e),ve=new Uint32Array(e),be=new Float64Array(e),ye=new BigInt64Array(e)}}function b(e){throw p(e=`Aborted(${e})`),v=!0,new WebAssembly.RuntimeError(e+". Build with -sASSERTIONS for more info.")}class k{name="ExitStatus";constructor(e){this.message=`Program terminated with exit(${e})`,this.status=e}}var S,F,T=()=>{var e=F[+Se>>2];return Se+=4,e},M=(e,t)=>{for(var r=0,n=e.length-1;n>=0;n--){var a=e[n];"."===a?e.splice(n,1):".."===a?(e.splice(n,1),r++):r&&(e.splice(n,1),r--)}if(t)for(;r;r--)e.unshift("..");return e},x=e=>{var t="/"===e.charAt(0),r="/"===e.slice(-1);return(e=M(e.split("/").filter(e=>!!e),!t).join("/"))||t||(e="."),e&&r&&(e+="/"),(t?"/":"")+e},I=e=>{var t=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/.exec(e).slice(1);return e=t[0],t=t[1],e||t?(t&&=t.slice(0,-1),e+t):"."},A=e=>(A=(()=>{if(o){var e=require("node:crypto");return t=>(e.randomFillSync(t),0)}return e=>(crypto.getRandomValues(e),0)})())(e),E=globalThis.TextDecoder&&new TextDecoder,G=(e,t=0)=>{for(var r=t,n=r+NaN;e[r]&&!(r>=n);)++r;if(r-t>16&&e.buffer&&E)return E.decode(e.subarray(t,r));for(n="";t<r;){var a=e[t++];if(128&a){var o=63&e[t++];if(192==(224&a))n+=String.fromCharCode((31&a)<<6|o);else{var i=63&e[t++];(a=224==(240&a)?(15&a)<<12|o<<6|i:(7&a)<<18|o<<12|i<<6|63&e[t++])<65536?n+=String.fromCharCode(a):(a-=65536,n+=String.fromCharCode(55296|a>>10,56320|1023&a))}}else n+=String.fromCharCode(a)}return n},_=[],C=e=>{for(var t=0,r=0;r<e.length;++r){var n=e.charCodeAt(r);n<=127?t++:n<=2047?t+=2:n>=55296&&n<=57343?(t+=4,++r):t+=3}return t},L=(e,t,r,n)=>{if(!(n>0))return 0;var a=r;n=r+n-1;for(var o=0;o<e.length;++o){var i=e.codePointAt(o);if(i<=127){if(r>=n)break;t[r++]=i}else if(i<=2047){if(r+1>=n)break;t[r++]=192|i>>6,t[r++]=128|63&i}else if(i<=65535){if(r+2>=n)break;t[r++]=224|i>>12,t[r++]=128|i>>6&63,t[r++]=128|63&i}else{if(r+3>=n)break;t[r++]=240|i>>18,t[r++]=128|i>>12&63,t[r++]=128|i>>6&63,t[r++]=128|63&i,o++}}return t[r]=0,r-a},D=[];function U(e,t){D[e]={input:[],output:[],R:t},ie(e,P)}var P={open(e){var t=D[e.node.rdev];if(!t)throw new H(43);e.tty=t,e.seekable=!1},close(e){e.tty.R.fsync(e.tty)},fsync(e){e.tty.R.fsync(e.tty)},read(e,t,r,n){if(!e.tty||!e.tty.R.ha)throw new H(60);for(var a=0,o=0;o<n;o++){try{var i=e.tty.R.ha(e.tty)}catch(e){throw new H(29)}if(void 0===i&&!a)throw new H(6);if(null==i)break;if(a++,t[r+o]=i,10===i)break}return a&&(e.node.atime=Date.now()),a},write(e,t,r,n){if(!e.tty||!e.tty.R.ea)throw new H(60);try{for(var a=0;a<n;a++)e.tty.R.ea(e.tty,t[r+a])}catch(e){throw new H(29)}return n&&(e.node.mtime=e.node.ctime=Date.now()),a}},j={ha(){e:{if(!_.length){var e=null;if(o){var t=Buffer.alloc(256),r=0,n=process.stdin.fd;try{r=d.readSync(n,t,0,256)}catch(e){if(!e.toString().includes("EOF"))throw e;r=0}r>0&&(e=t.slice(0,r).toString("utf-8"))}else globalThis.window?.prompt&&null!==(e=window.prompt("Input: "))&&(e+="\n");if(!e){e=null;break e}t=Array(C(e)+1),e=L(e,t,0,t.length),t.length=e,_=t}e=_.shift()}return e},ea(e,t){null===t||10===t?(w(G(e.output)),e.output=[]):0!=t&&e.output.push(t)},fsync(e){e.output?.length>0&&(w(G(e.output)),e.output=[])},qa:()=>({Aa:25856,Ca:5,za:191,Ba:35387,ya:[3,28,127,21,4,0,1,0,17,19,26,0,18,15,23,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}),ra:()=>0,sa:()=>[24,80]},R={ea(e,t){null===t||10===t?(p(G(e.output)),e.output=[]):0!=t&&e.output.push(t)},fsync(e){e.output?.length>0&&(p(G(e.output)),e.output=[])}},N={N:null,P:()=>N.createNode(null,"/",16895,0),createNode(e,t,r,n){if(24576==(61440&r)||4096==(61440&r))throw new H(63);return N.N||(N.N={dir:{node:{T:N.G.T,S:N.G.S,lookup:N.G.lookup,V:N.G.V,rename:N.G.rename,unlink:N.G.unlink,rmdir:N.G.rmdir,readdir:N.G.readdir,symlink:N.G.symlink},stream:{M:N.F.M}},file:{node:{T:N.G.T,S:N.G.S},stream:{M:N.F.M,read:N.F.read,write:N.F.write,ja:N.F.ja,la:N.F.la}},link:{node:{T:N.G.T,S:N.G.S,readlink:N.G.readlink},stream:{}},ga:{node:{T:N.G.T,S:N.G.S},stream:oe}}),16384==(61440&(r=Q(e,t,r,n)).mode)?(r.G=N.N.dir.node,r.F=N.N.dir.stream,r.I={}):32768==(61440&r.mode)?(r.G=N.N.file.node,r.F=N.N.file.stream,r.J=0,r.I=N.na??(N.na=new Uint8Array(0))):40960==(61440&r.mode)?(r.G=N.N.link.node,r.F=N.N.link.stream):8192==(61440&r.mode)&&(r.G=N.N.ga.node,r.F=N.N.ga.stream),r.atime=r.mtime=r.ctime=Date.now(),e&&(e.I[t]=r,e.atime=e.mtime=e.ctime=r.atime),r},G:{T(e){var t={};return t.dev=8192==(61440&e.mode)?e.id:1,t.ino=e.id,t.mode=e.mode,t.nlink=1,t.uid=0,t.gid=0,t.rdev=e.rdev,16384==(61440&e.mode)?t.size=4096:32768==(61440&e.mode)?t.size=e.J:40960==(61440&e.mode)?t.size=e.link.length:t.size=0,t.atime=new Date(e.atime),t.mtime=new Date(e.mtime),t.ctime=new Date(e.ctime),t.blksize=4096,t.blocks=Math.ceil(t.size/t.blksize),t},S(e,t){for(var r of["mode","atime","mtime","ctime"])null!=t[r]&&(e[r]=t[r]);void 0!==t.size&&(t=t.size,e.J!=t&&(r=e.I,e.I=new Uint8Array(t),e.I.set(r.subarray(0,Math.min(t,e.J))),e.J=t))},lookup(){throw N.X||(N.X=new H(44),N.X.stack="<generic error, no stack>"),N.X},V:(e,t,r,n)=>N.createNode(e,t,r,n),rename(e,t,r){try{var n=K(t,r)}catch(e){}if(n){if(16384==(61440&e.mode))for(var a in n.I)throw new H(55);if(a=Z(n.parent.id,n.name),z[a]===n)z[a]=n.U;else for(a=z[a];a;){if(a.U===n){a.U=n.U;break}a=a.U}}delete e.parent.I[e.name],t.I[r]=e,e.name=r,t.ctime=t.mtime=e.parent.ctime=e.parent.mtime=Date.now()},unlink(e,t){delete e.I[t],e.ctime=e.mtime=Date.now()},rmdir(e,t){var r,n=K(e,t);for(r in n.I)throw new H(55);delete e.I[t],e.ctime=e.mtime=Date.now()},readdir:e=>[".","..",...Object.keys(e.I)],symlink:(e,t,r)=>((e=N.createNode(e,t,41471,0)).link=r,e),readlink(e){if(40960!=(61440&e.mode))throw new H(28);return e.link}},F:{read:(e,t,r,n,a)=>a>=e.node.J?0:(n=Math.min(e.node.J-a,n),t.set(e.node.I.subarray(a,a+n),r),n),write(e,t,r,n,a,o){if(t.buffer===S.buffer&&(o=!1),!n)return 0;if((e=e.node).mtime=e.ctime=Date.now(),o)e.I=t.subarray(r,r+n),e.J=n;else if(e.J||a){o=a+n;var i=e.I.length;i>=o||(o=Math.max(o,i*(i<1048576?2:1.125)>>>0),i&&(o=Math.max(o,256)),i=e.I.subarray(0,e.J),e.I=new Uint8Array(o),e.I.set(i)),e.I.set(t.subarray(r,r+n),a),e.J=Math.max(e.J,a+n)}else e.I=t.slice(r,r+n),e.J=n;return n},M(e,t,r){if(1===r?t+=e.position:2===r&&32768==(61440&e.node.mode)&&(t+=e.node.J),t<0)throw new H(28);return t},ja(e,t,r,n,a){if(32768!=(61440&e.node.mode))throw new H(43);if(e=e.node.I,2&a||e.buffer!==S.buffer){if(n=!0,b(),!(a=void 0))throw new H(48);e&&((r>0||r+t<e.length)&&(e=e.subarray?e.subarray(r,r+t):Array.prototype.slice.call(e,r,r+t)),S.set(e,a))}else n=!1,a=e.byteOffset;return{Ga:a,xa:n}},la:(e,t,r,n)=>(N.F.write(e,t,0,n,r,!1),0)}},O=null,$={},W=[],q=1,z=null,B=!1,J=!0,H=class{name="ErrnoError";constructor(e){this.L=e}},V=class{shared={};node=null;get flags(){return this.shared.flags}set flags(e){this.shared.flags=e}get position(){return this.shared.position}set position(e){this.shared.position=e}},X=class{G={};F={};W=null;listeners=null;fa=0;constructor(e,t,r,n){e||=this,this.parent=e,this.P=e.P,this.id=q++,this.name=t,this.mode=r,this.rdev=n,this.atime=this.mtime=this.ctime=Date.now()}get read(){return!(365&~this.mode)}set read(e){e?this.mode|=365:this.mode&=-366}get write(){return!(146&~this.mode)}set write(e){e?this.mode|=146:this.mode&=-147}va(){if(this.listeners){var e;for(t of this.listeners)t.exclusive?(e||=[]).push(t):t.ma(32);if(e){var t=(this.fa||0)%e.length;this.fa=t+1,e[t].ma(32)}}}};function Y(e,t={}){if(!e)throw new H(44);t.Z??(t.Z=!0),"/"===e.charAt(0)||(e="//"+e);var r=0;e:for(;r<40;r++){e=e.split("/").filter(e=>!!e);for(var n=O,a="/",o=0;o<e.length;o++){var i=o===e.length-1;if(i&&t.parent)break;if("."!==e[o])if(".."===e[o]){if(a=I(a),n===n.parent){e=a+"/"+e.slice(o+1).join("/"),r--;continue e}n=n.parent}else{a=x(a+"/"+e[o]);try{n=K(n,e[o])}catch(e){if(44===e?.L&&i&&t.ua)return{path:a};throw e}if(!n.W||i&&!t.Z||(n=n.W.root),40960==(61440&n.mode)&&(!i||t.Y)){if(!n.G.readlink)throw new H(52);"/"===(n=n.G.readlink(n)).charAt(0)||(n=I(a)+"/"+n),e=n+"/"+e.slice(o+1).join("/");continue e}}}return{path:a,node:n}}throw new H(32)}function Z(e,t){for(var r=0,n=0;n<t.length;n++)r=(r<<5)-r+t.charCodeAt(n)|0;return(e+r>>>0)%z.length}function K(e,t){var r=16384==(61440&e.mode)?(r=ee(e,"x"))?r:e.G.lookup?0:2:54;if(r)throw new H(r);for(r=z[Z(e.id,t)];r;r=r.U){var n=r.name;if(r.parent.id===e.id&&n===t)return r}return e.G.lookup(e,t)}function Q(e,t,r,n){return t=Z((e=new X(e,t,r,n)).parent.id,e.name),e.U=z[t],z[t]=e}function ee(e,t){return J?0:t.includes("r")&&!(292&e.mode)||t.includes("w")&&!(146&e.mode)||t.includes("x")&&!(73&e.mode)?2:0}function te(e,t){if(16384!=(61440&e.mode))return 54;try{return K(e,t),20}catch(e){}return ee(e,"wx")}function re(e){if(!(e=W[e]))throw new H(8);return e}function ne(e,t=-1){if(e=Object.assign(new V,e),-1==t)e:{for(t=0;t<=4096;t++)if(!W[t])break e;throw new H(33)}return e.fd=t,W[t]=e}function ae(e,t){var r=void 0,n=r?null:e;if(r??=e.G.S,!r)throw new H(63);try{r(n,t)}catch(e){if(e instanceof RangeError)throw new H(22);throw e}}var oe={open(e){e.F=$[e.node.rdev].F,e.F.open?.(e)},M(){throw new H(70)}};function ie(e,t){$[e]={F:t}}function se(e,t){var r="/"===t;if(r&&O)throw new H(10);if(!r&&t){var n=Y(t,{Z:!1});if(t=n.path,(n=n.node).W)throw new H(10);if(16384!=(61440&n.mode))throw new H(54)}t={type:e,Fa:{},ka:t,ta:[]},(e=e.P(t)).P=t,t.root=e,r?O=e:n&&(n.W=t,n.P&&n.P.ta.push(t))}function fe(e,t,r){var n=Y(e,{parent:!0}).node;if(!(e=e&&e.match(/([^\/]+|\/)\/*$/)[1]))throw new H(28);if("."===e||".."===e)throw new H(20);var a=te(n,e);if(a)throw new H(a);if(!n.G.V)throw new H(63);return n.G.V(n,e,t,r)}function ue(e){return fe(e,16895,0)}function le(e,t,r){void 0===r&&(r=t,t=438),fe(e,8192|t,r)}function ce(e,t){if(!((...e)=>{for(var t="",r=!1,n=e.length-1;n>=-1&&!r;n--){if("string"!=typeof(r=n>=0?e[n]:"/"))throw new TypeError("Arguments to path.resolve must be strings");if(!r)return"";t=r+"/"+t,r="/"===r.charAt(0)}return(r?"/":"")+(t=M(t.split("/").filter(e=>!!e),!r).join("/"))||"."})(e))throw new H(44);var r=Y(t,{parent:!0}).node;if(!r)throw new H(44);var n=te(r,t=t&&t.match(/([^\/]+|\/)\/*$/)[1]);if(n)throw new H(n);if(!r.G.symlink)throw new H(63);r.G.symlink(r,t,e)}function de(e,t,r=438){if(""===e)throw new H(44);if("string"==typeof t){var n={r:0,"r+":2,w:577,"w+":578,a:1089,"a+":1090}[t];if(void 0===n)throw Error(`Unknown file open mode: ${t}`);t=n}if(r=64&t?4095&r|32768:0,"object"==typeof e)n=e;else{var a=e.endsWith("/"),o=Y(e,{Y:!(131072&t),ua:!0});n=o.node,e=o.path}if(o=!1,64&t)if(n){if(128&t)throw new H(20)}else{if(a)throw new H(31);n=fe(e,511|r,0),o=!0}if(!n)throw new H(44);if(8192==(61440&n.mode)&&(t&=-513),65536&t&&16384!=(61440&n.mode))throw new H(54);if(!o&&(n?40960==(61440&n.mode)?a=32:(a=["r","w","rw"][3&t],512&t&&(a+="w"),a=16384==(61440&n.mode)&&("r"!==a||576&t)?31:ee(n,a)):a=44,a))throw new H(a);if(512&t&&!o){if(16384==(61440&(a="string"==typeof(a=n)?Y(a,{Y:!0}).node:a).mode))throw new H(31);if(32768!=(61440&a.mode))throw new H(28);if(e=ee(a,"w"))throw new H(e);ae(a,{size:0,timestamp:Date.now()})}e:{for(a=n;;){if(a===a.parent){a=a.P.ka;var i=i?"/"!==a[a.length-1]?`${a}/${i}`:a+i:a;break e}i=i?`${a.name}/${i}`:a.name,a=a.parent}i=void 0}return(t=ne({node:n,path:i,flags:-131713&t,seekable:!0,position:0,F:n.F,wa:[],error:!1})).F.open&&t.F.open(t),o&&(r&=511,ae(n="string"==typeof n?Y(n,{Y:!0}).node:n,{mode:4095&r|-4096&n.mode,ctime:Date.now(),Da:void 0})),t}function he(e,t,r){if(null===e.fd)throw new H(8);if(!e.seekable||!e.F.M)throw new H(70);if(0!=r&&1!=r&&2!=r)throw new H(28);e.position=e.F.M(e,t,r),e.wa=[]}function me(e,t,r,n){var a=void 0;if(n<0||a<0)throw new H(28);if(null===e.fd)throw new H(8);if(!(2097155&e.flags))throw new H(8);if(16384==(61440&e.node.mode))throw new H(31);if(!e.F.write)throw new H(28);e.seekable&&1024&e.flags&&he(e,0,2);var o=void 0!==a;if(o){if(!e.seekable)throw new H(70)}else a=e.position;return t=e.F.write(e,t,r,n,a,void 0),o||(e.position+=t),t}function we(e,t){e=x("/dev/"+e);var r=(e=>{var t=0;return e&&(t|=365),t})(!!t);we.ia??(we.ia=64);var n=we.ia++<<8;ie(n,{open(e){e.seekable=!1},close(){},read(e,r,n,a){for(var o=0,i=0;i<a;i++){try{var s=t()}catch(e){throw new H(29)}if(void 0===s&&!o)throw new H(6);if(null==s)break;o++,r[n+i]=s}return o&&(e.node.atime=Date.now()),o},write(e,t,r,n){for(var a=0;a<n;a++)try{(void 0)(t[r+a])}catch(e){throw new H(29)}return n&&(e.node.mtime=e.node.ctime=Date.now()),a}}),le(e,r,n)}var pe,ve,ye,ge,be,ke,Se=void 0,Fe={},Te=e=>{if(!v)try{return e()}catch(e){e instanceof k||"unwind"==e||f(1,e)}},Me=[],xe={},Ie=()=>{if(!ke){var e,t={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:(globalThis.navigator?.language??"C").replace("-","_")+".UTF-8",_:s};for(e in xe)void 0===xe[e]?delete t[e]:t[e]=xe[e];var r=[];for(e in t)r.push(`${e}=${t[e]}`);ke=r}return ke},Ae=e=>{var t=C(e)+1,r=Je(t);return L(e,pe,r,t),r},Ee=e=>{try{e()}catch(e){b(e)}};function Ge(e){var t=(...t)=>{De.push(e);try{return e(...t)}finally{v||(De.pop(),Ce&&1===_e&&!De.length&&(_e=0,Ee(Xe),"undefined"!=typeof Fibers&&Fibers.Ja()))}};return je.set(e,t),t}var _e=0,Ce=null,Le=0,De=[],Ue=new Map,Pe=new Map,je=new Map,Re=0,Ne=null,Oe=[];z=Array(4096),se(N,"/"),ue("/tmp"),ue("/home"),ue("/home/web_user"),function(){ue("/dev"),ie(259,{read:()=>0,write:(e,t,r,n)=>n,M:()=>0}),le("/dev/null",259),U(1280,j),U(1536,R),le("/dev/tty",1280),le("/dev/tty1",1536);var e=new Uint8Array(1024),t=0,r=()=>(t||(A(e),t=e.byteLength),e[--t]);we("random",r),we("urandom",r),ue("/dev/shm"),ue("/dev/shm/tmp")}(),function(){ue("/proc");var e=ue("/proc/self");ue("/proc/self/fd"),se({P(){var t=Q(e,"fd",16895,73);return t.F={M:N.F.M},t.G={lookup(e,t){var r=re(e=+t);return(e={parent:null,P:{ka:"fake"},G:{readlink:()=>r.path},id:e+1}).parent=e},readdir:()=>Array.from(W.entries()).filter(([,e])=>e).map(([e])=>e.toString())},t}},"/proc/self/fd")}(),r.print&&(w=r.print),r.printErr&&(p=r.printErr),r.wasmBinary&&(h=r.wasmBinary),r.ccall=(e,t,n,a,o)=>{function i(e){return u&&Be(u),"string"===t?e?G(pe,e):"":"boolean"===t?!!e:e}var s={string:e=>{var t=0;return null!=e&&0!==e&&(t=Ae(e)),t},array:e=>{var t=Je(e.length);return S.set(e,t),t}};e=r["_"+e];var f=[],u=0;if(a)for(var l=0;l<a.length;l++){var c=s[n[l]];c?(u||=He(),f[l]=c(a[l])):f[l]=a[l]}return n=Ce,a=e(...f),o=o?.async,Ce!=n?new Promise((e,t)=>{Ne={resolve:e,reject:t}}).then(i):(a=i(a),o?Promise.resolve(a):a)};var $e,We,qe,ze,Be,Je,He,Ve,Xe,Ye,Ze,Ke,Qe,et={98639912:()=>{try{r.onDoneSearching()}catch(e){}}},tt={b:function(e,t,r){Se=r;try{var n=re(e);switch(t){case 0:var a=T();if(a<0)break;for(;W[a];)a++;return function(e,t=-1){return e=ne(e,t),e.F?.Ea?.(e),e}(n,a).fd;case 1:case 2:case 13:case 14:return 0;case 3:return n.flags;case 4:return a=T(),n.flags=-289793&n.flags|289792&a,0;case 12:return a=T(),ge[a+0>>1]=2,0}return-28}catch(e){if("ErrnoError"!==e.name)throw e;return-e.L}},r:function(e,t,r){Se=r;try{var n=re(e);switch(t){case 21509:case 21510:case 21511:case 21512:case 21524:case 21515:return n.tty?0:-59;case 21505:if(!n.tty)return-59;if(n.tty.R.qa){e=[3,28,127,21,4,0,1,0,17,19,26,0,18,15,23,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];var a=T();F[a>>2]=25856,F[a+4>>2]=5,F[a+8>>2]=191,F[a+12>>2]=35387;for(var o=0;o<32;o++)S[a+o+17]=e[o]||0}return 0;case 21506:case 21507:case 21508:if(!n.tty)return-59;if(n.tty.R.ra)for(a=T(),e=[],o=0;o<32;o++)e.push(S[a+o+17]);return 0;case 21519:return n.tty?(a=T(),F[a>>2]=0):-59;case 21520:return n.tty?-28:-59;case 21537:case 21531:if(a=T(),!n.F.pa)throw new H(59);return n.F.pa(n,t,a);case 21523:return n.tty?(n.tty.R.sa&&(o=[24,80],a=T(),ge[a>>1]=o[0],ge[a+2>>1]=o[1]),0):-59;default:return-28}}catch(e){if("ErrnoError"!==e.name)throw e;return-e.L}},d:function(e,t,r,n){Se=n;try{var a=t=t?G(pe,t):"";if("/"===a.charAt(0))t=a;else{var o=-100===e?"/":re(e).path;if(0==a.length)throw new H(44);t=o+"/"+a}var i=n?T():0;return 64&r&&(i&=-19),de(t,r,i).fd}catch(e){if("ErrnoError"!==e.name)throw e;return-e.L}},i:()=>b(""),h:()=>{},k:(e,t)=>{if(Fe[e]&&(clearTimeout(Fe[e].id),delete Fe[e]),!t)return 0;var r=setTimeout(()=>{delete Fe[e],Te(()=>qe(e,performance.now()))},t);return Fe[e]={id:r,Ia:t},0},l:(e,t,r,n)=>{var a=(new Date).getFullYear(),o=new Date(a,0,1).getTimezoneOffset();a=new Date(a,6,1).getTimezoneOffset(),ve[e>>2]=60*Math.max(o,a),F[t>>2]=Number(o!=a),e=(t=e=>{var t=Math.abs(e);return`UTC${e>=0?"-":"+"}${String(Math.floor(t/60)).padStart(2,"0")}${String(t%60).padStart(2,"0")}`})(o),t=t(a),a<o?(L(e,pe,r,17),L(t,pe,n,17)):(L(e,pe,n,17),L(t,pe,r,17))},e:function(e,t,r){return e>=0&&e<=3?(ye[r>>3]=BigInt(Math.round(1e3*(0===e?Date.now():performance.now())*1e3)),0):28},j:(e,t,r)=>{Me.length=0;for(var n;n=pe[t++];){var a=105!=n;r+=(a&=112!=n)&&r%8?4:0,Me.push(112==n?ve[r>>2]:106==n?ye[r>>3]:105==n?F[r>>2]:be[r>>3]),r+=a?8:4}return et[e](...Me)},f:e=>{var t=pe.length;if((e>>>=0)>2147483648)return!1;for(var r=1;r<=4;r*=2){var n=t*(1+.2/r);n=Math.min(n,e+100663296);e:{n=(Math.min(2147483648,65536*Math.ceil(Math.max(e,n)/65536))-Ke.buffer.byteLength+65535)/65536|0;try{Ke.grow(n),g();var a=1;break e}catch(e){}a=void 0}if(a)return!0}return!1},s:function(e){return(e=>function(e){if(!v){if(0===_e){var t=!1,r=!1;e((e=0)=>{if(!v&&(Le=e,t=!0,r)){_e=2,Ee(()=>Ye(Ce)),"undefined"!=typeof MainLoop&&MainLoop.oa&&MainLoop.resume(),e=!1;try{var n=function(){var e=Pe.get(F[Ce+8>>2]);return e=je.get(e),Te(e)}()}catch(t){n=t,e=!0}var a=!1;if(!Ce){var o=Ne;o&&(Ne=null,(e?o.reject:o.resolve)(n),a=!0)}if(e&&!a)throw n}}),r=!0,t||(_e=1,Ce=function(){var e=ze(10485772),t=e+12;if(ve[e>>2]=t,ve[e+4>>2]=t+10485760,t=De[0],!Ue.has(t)){var r=Re++;Ue.set(t,r),Pe.set(r,t)}return t=Ue.get(t),F[e+8>>2]=t,e}(),"undefined"!=typeof MainLoop&&MainLoop.oa&&MainLoop.pause(),Ee(()=>Ve(Ce)))}else 2===_e?(_e=0,Ee(Ze),We(Ce),Ce=null,Oe.forEach(Te)):b(`invalid state: ${_e}`);return Le}}(async t=>{t(await e())}))(()=>new Promise(t=>setTimeout(t,e)))},m:(e,t)=>{var r,n=0,a=0;for(r of Ie()){var o=t+n;ve[e+a>>2]=o,n+=L(r,pe,o,1/0)+1,a+=4}return 0},n:(e,t)=>{var r=Ie();for(var n of(ve[e>>2]=r.length,e=0,r))e+=C(n)+1;return ve[t>>2]=e,0},a:e=>{f(e,new k(e))},c:function(e){try{var t=re(e);if(null===t.fd)throw new H(8);t.da&&(t.da=null),t.node?.va();try{t.F.close&&t.F.close(t)}catch(e){throw e}finally{W[t.fd]=null}return t.fd=null,0}catch(e){if("ErrnoError"!==e.name)throw e;return e.L}},q:function(e,t,r,n){try{e:{var a=re(e);e=t;for(var o,i=t=0;i<r;i++){var s=ve[e>>2],f=ve[e+4>>2];e+=8;try{var u=a,l=s,c=f,d=o,h=S;if(c<0||d<0)throw new H(28);if(null===u.fd)throw new H(8);if(1==(2097155&u.flags))throw new H(8);if(16384==(61440&u.node.mode))throw new H(31);if(!u.F.read)throw new H(28);var m=void 0!==d;if(m){if(!u.seekable)throw new H(70)}else d=u.position;var w=u.F.read(u,h,l,c,d);m||(u.position+=w);var p=w}catch(e){if(t>0&&e instanceof H&&(6==e.L||6==e.L))break;throw e}if(p<0){var v=-1;break e}if(t+=p,p<f)break;void 0!==o&&(o+=p)}v=t}return ve[n>>2]=v,0}catch(e){if("ErrnoError"!==e.name)throw e;return e.L}},o:function(e,t,r,n){t=t<-9007199254740992||t>9007199254740992?NaN:Number(t);try{if(isNaN(t))return 22;var a=re(e);return he(a,t,r),ye[n>>3]=BigInt(a.position),a.da&&!t&&0===r&&(a.da=null),0}catch(e){if("ErrnoError"!==e.name)throw e;return e.L}},p:function(e,t,r,n){try{var a=re(e);if(e=t,1==r)var o=me(a,S,ve[e>>2],ve[e+4>>2]);else{for(var i=t=0,s=e;i<r;i++,s+=8)t+=ve[s+4>>2];var f=new Uint8Array(t);for(i=s=0;i<r;i++,e+=8){var u=ve[e>>2],l=ve[e+4>>2];f.set(pe.subarray(u,u+l),s),s+=l}o=me(a,f,0,t)}return ve[n>>2]=o,0}catch(e){if("ErrnoError"!==e.name)throw e;return e.L}},g:e=>{f(e,new k(e))}};return Qe=await async function(){function e(e){var t=Qe=e.exports;e={};for(let[r,n]of Object.entries(t))"function"==typeof n?(t=Ge(n),e[r]=t):e[r]=n;return e=Qe=e,$e=r._main=e.v,r._command=e.w,r._isSearching=e.x,We=e.y,qe=e.z,ze=e.A,Be=e.B,Je=e.C,He=e.D,e.E,e.H,e.K,e.O,Ve=e._,Xe=e.$,Ye=e.aa,Ze=e.ba,Ke=e.t,g(),Qe}var t,n={a:tt},a=r.instantiateWasm;return a?new Promise(t=>{a(n,r=>t(e(r)))}):(m??=r.locateFile?r.locateFile("stockfish.wasm",c):c+"stockfish.wasm",t=await async function(e){var t=m;if(!h&&!o)try{var r=fetch(t,{credentials:"same-origin"});return await WebAssembly.instantiateStreaming(r,e)}catch(e){p(`wasm streaming compile failed: ${e}`),p("falling back to ArrayBuffer instantiation")}return async function(e,t){try{var r=await async function(e){if(!h)try{var t=await u(e);return new Uint8Array(t)}catch{}if(e==m&&h)e=new Uint8Array(h);else{if(!l)throw"both async and sync fetching of the wasm failed";e=l(e)}return e}(e);return await WebAssembly.instantiate(r,t)}catch(e){p(`failed to asynchronously prepare wasm: ${e}`),b(e)}}(t,e)}(n),e(t.instance))}(),await async function(e=i){v||(r.noFSInit||B||(B=!0,ce("/dev/tty","/dev/stdin"),ce("/dev/tty","/dev/stdout"),ce("/dev/tty1","/dev/stderr"),de("/dev/stdin",0),de("/dev/stdout",1),de("/dev/stderr",1)),Qe.u(),J=!1,function(e=[]){var t=$e;e.unshift(s);var r,n=e.length,a=Je(4*(n+1)),o=a;for(r of e)ve[o>>2]=Ae(r),o+=4;ve[o>>2]=0;try{var i=t(n,a);f(i,new k(i))}catch(e){e instanceof k||"unwind"==e||f(1,e)}}(e))}(),r});return"object"==typeof exports&&"object"==typeof module?(module.exports=t,module.exports.default=t):"function"==typeof define&&define.amd&&define([],()=>t),t}"undefined"!=typeof globalThis&&"string"==typeof globalThis.name&&0===globalThis.name.indexOf("em-pthread")||"undefined"!=typeof global&&"[object process]"===Object.prototype.toString.call(global.process)&&"em-pthread"===require("node:worker_threads").workerData?e():"undefined"!=typeof onmessage&&("undefined"==typeof window||void 0===window.document)||"undefined"!=typeof global&&"[object process]"===Object.prototype.toString.call(global.process)?function(){var t,r,n,a,o="undefined"!=typeof global&&"[object process]"===Object.prototype.toString.call(global.process),i={},s=[],f=[];function u(e){if(i.ccall("command",null,["string"],[e],{async:/^go\b/.test(e)}),"quit"===e){try{i.terminate()}catch(e){}try{self.close()}catch(e){}try{process.exit()}catch(e){}}return!0}function l(){for(;f.length&&(!i._isSearching||!i._isSearching());)u(f.shift())}function c(e){"go"===(e=e.trim()).substring(0,2)||"setoption"===e.substring(0,9)?f.push(e):u(e),l()}function d(){if(i._isReady&&!i._isReady())return setTimeout(d,10);var e;i.onDoneSearching=function(){setTimeout(l,1)},i.processCommand=c,s.length&&(e=0,function t(){for(var r;e<s.length;){if((r=s[e++]).startsWith("sleep "))return setTimeout(t,r.slice(6));c(r)}}())}o?(r=require("path"),t=r.join(__dirname,r.basename(__filename,r.extname(__filename))+".wasm"),i={locateFile:function(e){return e.indexOf(".wasm")>-1?e.indexOf(".wasm.map")>-1?t+".map":t:__filename},listener:function(e){process.stdout.write(e+"\n")}},s=process.argv.slice(2),require.main===module?(e()(i).then(d),require("readline").createInterface({input:process.stdin,output:process.stdout,completer:function(e){var t=["binc ","btime ","confidence ","depth ","infinite ","mate ","maxdepth ","maxtime ","mindepth ","mintime ","moves ","movestogo ","movetime ","ponder ","searchmoves ","shallow ","winc ","wtime "];function r(t){return 0===t.toLowerCase().indexOf(e.toLowerCase())}var n=["compiler","d","eval","flip","go ","isready","ponderhit","position fen ","position startpos","position startpos moves ","quit","setoption name Clear Hash value true","setoption name Hash value ","setoption name Minimum Thinking Time value ","setoption name Move Overhead value ","setoption name MultiPV value ","setoption name Ponder value ","setoption name Skill Level value ","setoption name Slow Mover value ","setoption name Threads value ","setoption name UCI_Chess960 value false","setoption name UCI_Chess960 value true","setoption name UCI_LimitStrength value true","setoption name UCI_LimitStrength value false","setoption name UCI_Elo value ","setoption name UCI_ShowWDL value true","setoption name UCI_ShowWDL value false","setoption name nodestime value ","stop","uci","ucinewgame"].filter(r);return n.length||(n=(e=e.replace(/^.*\s/,""))?t.filter(r):t),[n,e]},historySize:100}).on("line",function(e){e&&(i.processCommand?i.processCommand(e):s.push(e),"quit"===e&&process.exit())}).on("close",function(){process.exit()}).setPrompt("")):module.exports=function(){return e()(i).then(d),i.processCommand=function(e){s.push(e)},i}):(a=self.location.hash.substr(1).split(","),t=decodeURIComponent(a[0]||location.origin+location.pathname.replace(/\.js$/i,".wasm")),function(r){{var a,o;function s(){return function(e,t,r){var i;n&&(i=function(e,t,r){var n,a,o=e/((Date.now()-r||1)/1e3),i=0;return o>0&&e<t&&(i=(t-e)/o),{percent:e/t,loaded:e,total:t,speedBytesPerSec:o,speedText:(a=o,a<1024?Math.round(a)+" B/s":a<1048576?(a/1024).toFixed(1)+" KB/s":(a/1048576).toFixed(1)+" MB/s"),eta:i,etaText:(n=i,!n||n<0?"":n<60?Math.ceil(n)+" sec":Math.round(n/60)+" min")}}(t,r,e),o=i,a||(a=setTimeout(function(){a=null,n.postMessage(o),o.percent>=1&&(n.close(),n=null)},4)))}}(i={locateFile:function(e){return e.indexOf(".wasm")>-1?e.indexOf(".wasm.map")>-1?t+".map":r||t:self.location.href},listener:function(e){postMessage(e)}}).instantiateWasm=function(e,r){var n=s();return function(e,t){return fetch(e).then(function(e){var r=Date.now();if(!e.ok)throw new Error("HTTP "+e.status+": "+e.statusText);var n=99169054,a=0,o=e.body.getReader(),i=new ReadableStream({start:function(e){!function i(){o.read().then(function(o){var s=o.done,f=o.value;if(s)return t(r,n,n),void e.close();a+=f.byteLength,t(r,a,n),e.enqueue(f),i()}).catch(function t(r){e.error(r),t(r)})}()}}),s=new Headers(e.headers);return new Response(i,{status:e.status,statusText:e.statusText,headers:s})})}(t,n).then(function(t){return WebAssembly.instantiateStreaming(t,e)}).then(function(e){return r(e.instance,e.module),e.instance.exports}).catch(function(e){throw e})}}e()(i).then(d).catch(function(e){setTimeout(function(){throw e},1)})}(),onmessage||(onmessage=function(e){if("setoption name CanOutputEngineDownloadProgress"===e.data)postMessage("info WillOutputEngineDownloadProgress");else if(e.data.progressPort)n=e.data.progressPort;else if(i.processCommand?i.processCommand(e.data):s.push(e.data),"quit"===e.data)try{self.close()}catch(e){}}))}():"object"==typeof document&&document.currentScript?document.currentScript._exports=e():e()}();