Cache for scores values.
--- 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;
}