Add check to board.putRandom.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Tue, 23 Sep 2014 01:23:10 +0300
changeset 119 e5f1930f0f19
parent 118 7e93fb8136a3
child 120 653ee00d2601
Add check to board.putRandom.
rule.js
--- a/rule.js	Tue Sep 23 01:17:55 2014 +0300
+++ b/rule.js	Tue Sep 23 01:23:10 2014 +0300
@@ -50,6 +50,8 @@
 }
 board.putRandom = function(brd) {
     var cnt = board.freeCnt(brd);
+    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++) {