bug991457.js (1779B)
1 function test() { 2 this.init(); 3 for (var i=0; i<10; i++) { 4 delete this.blocks[10][9]; 5 this.collapse_blocks(); 6 } 7 this.look_for_holes(); 8 } 9 test.prototype.init = function() { 10 this.blocks = new Array(20); 11 for (var x=0; x<this.blocks.length; x++) { 12 this.blocks[x] = new Array(10); 13 for (var y=0; y<this.blocks[x].length; y++) { 14 this.blocks[x][y] = {}; 15 } 16 } 17 } 18 test.prototype.move_block = function(x,y,x1,y1) { 19 this.blocks[x][y] = this.blocks[x1][y1]; 20 if (this.blocks[x][y]) 21 delete this.blocks[x1][y1]; 22 } 23 test.prototype.collapse_blocks = function() { 24 var didSomething=0; 25 do { 26 didSomething=0; 27 for (var x=0; x<this.blocks.length; x++) 28 for (var y=1; y<this.blocks[x].length; y++) { 29 if (!this.blocks[x][y] && this.blocks[x][y-1]) { 30 this.move_block(x,y,x,y-1); 31 didSomething=1; 32 } 33 } 34 } while (didSomething); 35 36 do { 37 didSomething = 0; 38 for (var x=0; x<this.blocks.length-1; x++) { 39 if (!this.blocks[x][9] && this.blocks[x+1][9]) { 40 for (var y=0; y<this.blocks[x].length; y++) 41 this.move_block(x,y,x+1,y); 42 didSomething = 1; 43 } 44 } 45 } while (didSomething); 46 } 47 test.prototype.look_for_holes = function() { 48 var was_empty = false; 49 var n_empty = 0; 50 for (var x=0; x<this.blocks.length; x++) { 51 var empty = true; 52 for (var y=0; y<this.blocks[x].length; y++) { 53 if (this.blocks[x][y]) { 54 empty = false; 55 n_empty++; 56 } 57 } 58 if (was_empty) 59 assertEq(empty, true); 60 was_empty = empty; 61 } 62 assertEq(n_empty, 190); 63 } 64 new test();