Move object creation out of loop.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Wed, 17 Sep 2014 19:59:12 +0300
changeset 66 c62a1051cef7
parent 65 b8028f3e30fb
child 67 328b3e5c0802
Move object creation out of loop.
2048.html
--- a/2048.html	Wed Sep 17 19:46:04 2014 +0300
+++ b/2048.html	Wed Sep 17 19:59:12 2014 +0300
@@ -527,11 +527,11 @@
       }
       ui.game.beginStep();
       var step = 0;
+      var safeBdr = board.create();
       var tsFrom = new Date().getTime();
       while (!board.gameOver(ui.board.position)) {
-        var tmpBrd = board.create();
-        board.copy(ui.board.position, tmpBrd);
-        var move = ui.ai.current.analyse(tmpBrd);
+        board.copy(ui.board.position, safeBdr);
+        var move = ui.ai.current.analyse(safeBdr);
         if (typeof move === 'undefined') {
           ui.game.setMessage("I don't know how to move!");
           return;
@@ -643,15 +643,15 @@
         tsLimit = 1000 * 10;
       else
         tsLimit = 1000 * tsLimit;
-      var tmpBrd = board.create();
+      var safeBdr = board.create();
       var tsFrom = new Date().getTime();
       for (var i = 0; i < cnt; i++) {
         var turn = 0;
         var brd = board.create();
         board.putRandom(brd);
         while (!board.gameOver(brd)) {
-          board.copy(brd, tmpBrd);
-          var move = ui.ai.current.analyse(tmpBrd);
+          board.copy(brd, safeBdr);
+          var move = ui.ai.current.analyse(safeBdr);
           if (ui.game.dirs.indexOf(move) < 0) {
             ui.game.setMessage("I don't know how to move!");
             return;