Create object outside of loop.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Thu, 25 Sep 2014 02:10:48 +0300
changeset 140 438fd8c3c3ca
parent 139 4dde63ac0bb4
child 141 c769b70e9adb
Create object outside of loop.
ai.js
--- a/ai.js	Thu Sep 25 02:05:48 2014 +0300
+++ b/ai.js	Thu Sep 25 02:10:48 2014 +0300
@@ -395,12 +395,13 @@
     if (wCached)
         return wCached;
     var wMin = +Infinity;
+    var randBoard = new this.brdEngine();
+    var nextBrd = new this.brdEngine();
     for (var i = 0; i < 3; i++) {
         for (var j = 0; j < 3; j++) {
             if (brd.get(i, j) === 0) {
-                var randBoard = brd.copy();
+                brd.copy(randBoard);
                 randBoard.set(i, j, 1);
-                var nextBrd = new this.brdEngine();
                 var wMax2 = 0;
                 for (var diri = 0; diri < ai.dirs.length; diri++) {
                     if (randBoard[ai.dirs[diri]](nextBrd))