Speed up board.putRandom.
--- a/rule.js Tue Sep 23 01:23:10 2014 +0300
+++ b/rule.js Tue Sep 23 01:33:10 2014 +0300
@@ -53,12 +53,15 @@
if (cnt === 0)
throw Error('You forget detect game over!');
cnt = Math.floor(Math.random() * cnt)+1;
- for (var i = 0; i < 4 && cnt > 0; i++) {
- for (var j = 0; j < 4 && cnt > 0; j++) {
+exit:
+ for (var i = 0; i < 4; i++) {
+ for (var j = 0; j < 4; j++) {
if (brd[i][j] !== 0)
continue;
- if (cnt === 1)
+ if (cnt === 1) {
brd[i][j] = (Math.random() > .9) ? 2 : 1;
+ break exit;
+ }
cnt--;
}
}