class AIPlay {
	constructor(board) {
		this.worker = new Worker('./worker.js');
		this.board = board;
		board.on('switchPlayer', () => {
			if (!board.ended && !board.isActive() && board.selfNumber !== 2) {
				const data = this.board.moves.reduce((prev, curr) => prev.concat(curr), []);
				this.worker.postMessage(JSON.stringify(data));
			}
		});
		this.worker.onmessage = (evt) => {
			const directions = JSON.parse(evt.data);
			const loop = () => {
				const direction = directions.shift();
				this.board.moveTo(direction);
				if (directions.length > 0) {
					setTimeout(loop, 600);
				}
			};
			setTimeout(loop, 600);
		};
	}
}

module.exports = AIPlay;

@@ -137,211 +137,30 @@
 %0A%09%09%09
-if (!board.ended && !board.isActive() && board.selfNumber !== 2) %7B%0A%09%09%09%09const data = this.board.moves.reduce((prev, curr) =%3E prev.concat(curr), %5B%5D);%0A%09%09%09%09this.worker.postMessage(JSON.stringify(data));%0A%09%09%09%7D
+this.onSwitchPlayer();
 %0A%09%09%7D
@@ -373,12 +373,55 @@
 gth 
-%3E 0)
+=== 0) %7B%0A%09%09%09%09%09this.onSwitchPlayer();%0A%09%09%09%09%7D else
  %7B%0A%09
@@ -493,16 +493,257 @@
 %09%09%7D;%0A%09%7D%0A
+%09onSwitchPlayer() %7B%0A%09%09if (!this.board.ended && !this.board.isActive() && this.board.selfNumber !== 2) %7B%0A%09%09%09const data = this.board.moves.reduce((prev, curr) =%3E prev.concat(curr), %5B%5D);%0A%09%09%09this.worker.postMessage(JSON.stringify(data));%0A%09%09%7D%0A%09%7D%0A
 %7D%0A%0Amodul

Fix bug