Enable score cache.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Tue, 02 Sep 2014 18:47:33 +0300
changeset 3 96a50cb300cc
parent 2 11da0a8fabf3
child 4 732aef931a9e
Enable score cache.
2048.html
--- a/2048.html	Tue Sep 02 18:39:53 2014 +0300
+++ b/2048.html	Tue Sep 02 18:47:33 2014 +0300
@@ -142,9 +142,9 @@
       }
     }
     /* http://www.reddit.com/r/2048/comments/214njx/highest_possible_score_for_2048_warning_math */
-    board.scoreTbl = {"0": 0};
+    var boardScoreTbl = {"0": 0};
     for (var i = 1, exp = 2; i < 16; i++, exp *= 2) {
-      board.scoreTbl[exp] = (i-1)*exp;
+      boardScoreTbl[exp] = (i-1)*exp;
     }
     board.score = function(brd) {
       var score = 0;
@@ -152,9 +152,7 @@
       for (var i = 0; i < 4; i++) {
         for (var j = 0; j < 4; j++) {
           var val = brd[i][j];
-          if (val > 2)
-            score += Math.log2(val) * val;
-          /* score += board.scoreTbl[val]; */
+          score += boardScoreTbl[val];
           if (max < val)
             max = val;
         }