From 009ee46a6205ab051441716d7b372c50395e6bab Mon Sep 17 00:00:00 2001 From: mig Date: Tue, 4 Apr 2017 23:35:05 +0200 Subject: [PATCH] added stop ai worker method --- src/core/jocly.game.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/core/jocly.game.js b/src/core/jocly.game.js index 24ff99c..b92db42 100644 --- a/src/core/jocly.game.js +++ b/src/core/jocly.game.js @@ -414,7 +414,7 @@ JocGame.prototype.GetWho = function() { } JocGame.prototype.HumanTurn = function() { - if(this.mBoard.mMoves.length==0) { + if(!this.mBoard.mMoves || this.mBoard.mMoves.length==0) { this.mCurrentLevel=-1; this.mBoard.GenerateMoves(this); } @@ -583,6 +583,17 @@ JocGame.prototype.StartThreadedMachine = function(aOptions,algo) { }); } +JocGame.prototype.StopThreadedMachine = function() { + if(this.aiWorker) { + try { + this.aiWorker.terminate(); + delete this.aiWorker; + } catch(e) { + console.warn("Cannot terminate worker",e); + } + } +} + JocGame.prototype.ScheduleStep = function() { this.mNextSchedule = this.ExecuteStep; }