RSG-Group/Chess

Support web-workers

Closed this issue · 3 comments

The algorithm in the new AI is powerful, but if you run it with depth bigger than 3, the UI will freeze for seconds and the mobile version will even crash.
At the moment we're using WebViews from PhoneGap and Electron to make RSG Chess multi-platform, so the problem can be fixed on all platforms using Web Workers. Docs and tutorials can be find on MDN and some really helpful blog posts.

What about asynchronous and generator functions?

So I researched this topic and found it will be a lot easier to implement this to the Chess mobile and Chess desktop which are using our API. Also it's more important to fix the performance issues created by the AI loops on these platforms because the Android app can crash multiple times which will be critical.

There are two main issues with the web worker in RSG Chess mobile.

  1. The workers doesn't support es6 imports, so we need to use the CDN. but we already use the same resources from the npm module. This can be fixed by webpack.
  2. The workers cannot post functions, like game.allMoves, which the AI requires. That can be fixed by importing the game methods from the game.js in RSG Chess API.

There is a working example now, how the web workers can work with RSG Chess AI API:
https://github.com/radi-cho/rsg-chess-web-worker-example