+ // Computer moves web worker logic:
+ this.compWorker.postMessage(["scripts",variant]);
+ const self = this;
+ this.compWorker.onmessage = function(e) {
+ const compMove = e.data;
+ // (first move) HACK: small delay to avoid selecting elements
+ // before they appear on page:
+ const delay = Math.max(500-(Date.now()-self.timeStart), 0);
+ setTimeout(() => {
+ if (self.mode == "computer") //Warning: mode could have changed!
+ self.play(compMove, "animate")
+ }, delay);
+ }