Cache for scores values.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Tue, 02 Sep 2014 18:39:53 +0300
changeset 2 11da0a8fabf3
parent 1 8fb744f2df13
child 3 96a50cb300cc
Cache for scores values.
2048.html
--- a/2048.html	Tue Sep 02 18:19:09 2014 +0300
+++ b/2048.html	Tue Sep 02 18:39:53 2014 +0300
@@ -142,6 +142,10 @@
       }
     }
     /* http://www.reddit.com/r/2048/comments/214njx/highest_possible_score_for_2048_warning_math */
+    board.scoreTbl = {"0": 0};
+    for (var i = 1, exp = 2; i < 16; i++, exp *= 2) {
+      board.scoreTbl[exp] = (i-1)*exp;
+    }
     board.score = function(brd) {
       var score = 0;
       var max = 0;
@@ -150,6 +154,7 @@
           var val = brd[i][j];
           if (val > 2)
             score += Math.log2(val) * val;
+          /* score += board.scoreTbl[val]; */
           if (max < val)
             max = val;
         }