Answers.Body: <p>After a detailed look on the web, the only project I was able to find is <a href="https://github.com/glinscott/Garbochess-JS" rel="nofollow">Garbochess</a>. It is BSD licensed, but it looks like it is not longer under development (latest commit was a year ago). I also was not able to find anything about the strength of the engine (ELO).</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-03-19T02:25:39.937Z
Answers.LastActivityDate: 2014-03-19T02:25:39.937Z
Answers.UserDisplayName: Salvador Dali
Answers.Body: <p>Stockfish has been ported to Javascript:</p>
  
  <p><a href="https://github.com/exoticorn/stockfish-js">https://github.com/exoticorn/stockfish-js</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-28T15:02:26.393Z
Answers.LastActivityDate: 2015-09-28T15:02:26.393Z
Answers.UserDisplayName: A passerby
Answers.Body: <p>Depends what your definition of strong is, but my basic Javascript engine is probably about 2400 now (v1.16) and is still in development. </p>
  
  <p>UI: <a href="http://op12no2.me/toys/lozza" rel="nofollow">http://op12no2.me/toys/lozza</a></p>
  
  <p>Source: <a href="http://op12no2.me/toys/lozza/lozza.js" rel="nofollow">http://op12no2.me/toys/lozza/lozza.js</a></p>
  
  <p>Typed arrays can be used for the hash table.  It's client side browser based.  The UI fires up a web worker which then uses UCI for comms, meaning the same code can also run offline in node.js (or jxCore), which in turn means it can be used in Arena and Winboard etc.</p>
  
  <p>While Lozza is hand-written, another route (licence permitting) is to use Emscripten and asm.js etc to automate trans-compilation from C/C++.  Some people have done this for Stockfish.  I'm unsure the resulting ELO (probably better than Lozza) but the code is of course unreadable.</p>
  
  <p><a href="https://github.com/kripken/emscripten" rel="nofollow">https://github.com/kripken/emscripten</a></p>
  
  <p><a href="http://asmjs.org/" rel="nofollow">http://asmjs.org/</a></p>
  
  <p>From a coding perspective one of the biggest drawbacks of Javascript is the lack of native 64bit unsigned integers. </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-10T14:24:28.027Z
Answers.LastActivityDate: 2015-11-13T11:09:40.367Z
Answers.LastEditDate: 2015-11-13T11:09:40.367Z
Answers.UserDisplayName: Colin Jenkins
Answers.Body: <p><em>Edit: This answer has been written by someone who is unexperienced in JavaScript programming (me). Please note the comments shed a slightly different light on the topic.</em></p>
  
  <p>One of the reasons there are not many JS chess engines out there is that JavaScript is quite unsuited for heavily parallelisable tasks, especially complex minimax analysis.</p>
  
  <p>Major drawbacks JS has (in my opinion) are:</p>
  
  <ol>
  <li>JavaScript is a high level language, making writing fast code
  difficult. (Of course I have to add that coding in ASM or C isn't
  going to be faster if you don't know what you are doing. But chess
  programmers know.) Additionally, performance optimisation details depend on the browser you are using.</li>
  <li><a href="http://www.sitepoint.com/multi-threading-javascript/" rel="nofollow">No real multithreading support.</a> (That's a damn hard limit on
  computation speed.)</li>
  <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Memory_Management" rel="nofollow">No real memory management.</a> (JS does it for you, but I imagine you as
  a programmer can allocate much more efficiently.)</li>
  <li>Apparently, limits on stack size, CPU usage etc. are imposed on
  JavScript Code (although Icannot give hard evidence right now).</li>
  <li>I cannot imagine JS being very efficient with hash tables.</li>
  <li>I imagine it being difficult to load opening books or endgame
  tablebases during runtime (slow) or preloading it on startup (still
  slow and your bandwidth won't like it).</li>
  </ol>
  
  <p>Well, technically, these are reasons why it would be hard to code a <em>good</em> chess engine - but who wants an engine with 1800 Elo? (Well, still enough for one or two standard deviations of players' practical purposes.)</p>
  
  <p>And in the end: it's client side. If you need something client side, don't do it in a browser. If it can be done on the server, use it! E. g., using PHP, pipes and the UCI protocol, you'll get much further and you can let the server compute it for all clients (and I know it has been done before, but can't tell exactly where I've seen it).</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-07T21:06:44.727Z
Answers.Text: I agree with this comment, I use nodejs to talk to a c++ engine so it can take advantage of multithreading, popcnt, and NUMA memory optimizations
Answers.UserDisplayName: jaggedsoft
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-03-19T10:25:18.237Z
Answers.Text: As a programmer, I can tell that there are inaccuracies in the post. JS is also run on the server (node.js) and it performs pretty good. Nevertheless the execution is definitely slower than C (it improves with every new browser version), but writing the code is much faster. Multithreading is achieved with web-workers and is pretty good. JS can also take use of gpu through WebCL. Javascript object `{a: 1, b: 2}` is actually a hash table (so it has native support). Loading opening book - yes, this is true... Although right now JS supports p2p with WebRTC, so you can paralelize your AI tasks.
Answers.UserDisplayName: Salvador Dali
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-03-19T10:26:11.600Z
Answers.Text: By the way - check the engine I found. It was done by one guy and I think that it is stronger than 1800.
Answers.UserDisplayName: Salvador Dali
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-03-19T10:28:52.493Z
Answers.Text: I'm not using JS that often, so thanks for correcting me. Would you still agree with my conclusion that outsourcing the task to a UCI engine on a server would be the better option in most cases, though?
Answers.UserDisplayName: chaosflaws
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-03-19T10:43:52.893Z
Answers.Text: Sure, and it was the only option like 3 years ago. But imagine the following situation. There are 20 users. Each of them wants to analyse some position. Server will not handle even 2 of them. I have no illusions that JS engine will perform faster than C. I was curious about the current situation for JS engines.
Answers.UserDisplayName: Salvador Dali
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-03-19T10:00:02.283Z
Answers.LastActivityDate: 2014-03-19T10:31:01.163Z
Answers.LastEditDate: 2014-03-19T10:31:01.163Z
Answers.UserDisplayName: chaosflaws
Body: <p>In one of my previous questions I asked about <a href="https://chess.stackexchange.com/q/2246/703">comparison of the strongest chess engines</a> and got a really good answer. While there are little or no doubts that chess engines are stronger than humans, I am curious: Is there any strong javascript implementation of a chess engine that performs well (what is the ELO of the engine)?</p>
  
  <p>Knowing that a lot of high level chess engines are opensource, has anyone made an effort to port something like <a href="http://stockfishchess.org/download/" rel="nofollow noreferrer">stockfish</a> or <a href="http://www.vlasak.biz/critter/" rel="nofollow noreferrer">critter</a> to JS?</p>
  
Tags: <engines><programming>
Title: Javascript based Chess engine
ThreadText: # Javascript based Chess engine
  
  (Asked by: username_0 on 2014-03-19)
  
  In one of my previous questions I asked about [comparison of the strongest chess engines](https://chess.stackexchange.com/q/2246/703) and got a really good answer. While there are little or no doubts that chess engines are stronger than humans, I am curious: Is there any strong javascript implementation of a chess engine that performs well (what is the ELO of the engine)?
  
  Knowing that a lot of high level chess engines are opensource, has anyone made an effort to port something like [stockfish](http://stockfishchess.org/download/) or [critter](http://www.vlasak.biz/critter/) to JS?
  
  **Tags:** engines, programming
  
  
  ---
  
  ## 4 answers
  
  ### Answer by username_0 on 2014-03-19. Score: 2 | Accepted answer
  
  After a detailed look on the web, the only project I was able to find is [Garbochess](https://github.com/glinscott/Garbochess-JS). It is BSD licensed, but it looks like it is not longer under development (latest commit was a year ago). I also was not able to find anything about the strength of the engine (ELO).
  
  
  ---
  
  ### Answer by username_1 on 2015-09-28. Score: 6
  
  Stockfish has been ported to Javascript:
  
  <https://github.com/exoticorn/stockfish-js>
  
  
  ---
  
  ### Answer by username_2 on 2015-11-10. Score: 1
  
  Depends what your definition of strong is, but my basic Javascript engine is probably about 2400 now (v1.16) and is still in development.
  
  UI: <http://op12no2.me/toys/lozza>
  
  Source: <http://op12no2.me/toys/lozza/lozza.js>
  
  Typed arrays can be used for the hash table. It's client side browser based. The UI fires up a web worker which then uses UCI for comms, meaning the same code can also run offline in node.js (or jxCore), which in turn means it can be used in Arena and Winboard etc.
  
  While Lozza is hand-written, another route (licence permitting) is to use Emscripten and asm.js etc to automate trans-compilation from C/C++. Some people have done this for Stockfish. I'm unsure the resulting ELO (probably better than Lozza) but the code is of course unreadable.
  
  <https://github.com/kripken/emscripten>
  
  <http://asmjs.org/>
  
  From a coding perspective one of the biggest drawbacks of Javascript is the lack of native 64bit unsigned integers.
  
  
  ---
  
  ### Answer by username_3 on 2014-03-19. Score: 0
  
  *Edit: This answer has been written by someone who is unexperienced in JavaScript programming (me). Please note the comments shed a slightly different light on the topic.*
  
  One of the reasons there are not many JS chess engines out there is that JavaScript is quite unsuited for heavily parallelisable tasks, especially complex minimax analysis.
  
  Major drawbacks JS has (in my opinion) are:
  
  1. JavaScript is a high level language, making writing fast code
     difficult. (Of course I have to add that coding in ASM or C isn't
     going to be faster if you don't know what you are doing. But chess
     programmers know.) Additionally, performance optimisation details depend on the browser you are using.
  2. [No real multithreading support.](http://www.sitepoint.com/multi-threading-javascript/) (That's a damn hard limit on
     computation speed.)
  3. [No real memory management.](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Memory_Management) (JS does it for you, but I imagine you as
     a programmer can allocate much more efficiently.)
  4. Apparently, limits on stack size, CPU usage etc. are imposed on
     JavScript Code (although Icannot give hard evidence right now).
  5. I cannot imagine JS being very efficient with hash tables.
  6. I imagine it being difficult to load opening books or endgame
     tablebases during runtime (slow) or preloading it on startup (still
     slow and your bandwidth won't like it).
  
  Well, technically, these are reasons why it would be hard to code a *good* chess engine - but who wants an engine with 1800 Elo? (Well, still enough for one or two standard deviations of players' practical purposes.)
  
  And in the end: it's client side. If you need something client side, don't do it in a browser. If it can be done on the server, use it! E. g., using PHP, pipes and the UCI protocol, you'll get much further and you can let the server compute it for all clients (and I know it has been done before, but can't tell exactly where I've seen it).
  
  > **Comments:**
  > **username_0**: As a programmer, I can tell that there are inaccuracies in the post. JS is also run on the server (node.js) and it performs pretty good. Nevertheless the execution is definitely slower than C (it improves with every new browser version), but writing the code is much faster. Multithreading is achieved with web-workers and is pretty good. JS can also take use of gpu through WebCL. Javascript object `{a: 1, b: 2}` is actually a hash table (so it has native support). Loading opening book - yes, this is true... Although right now JS supports p2p with WebRTC, so you can paralelize your AI tasks.  
  > **username_0**: By the way - check the engine I found. It was done by one guy and I think that it is stronger than 1800.  
  > **username_3**: I'm not using JS that often, so thanks for correcting me. Would you still agree with my conclusion that outsourcing the task to a UCI engine on a server would be the better option in most cases, though?  
  > **username_0**: Sure, and it was the only option like 3 years ago. But imagine the following situation. There are 20 users. Each of them wants to analyse some position. Server will not handle even 2 of them. I have no illusions that JS engine will perform faster than C. I was curious about the current situation for JS engines.  
  > **username_4**: I agree with this comment, I use nodejs to talk to a c++ engine so it can take advantage of multithreading, popcnt, and NUMA memory optimizations  
  
  ---
  
  