game.js
/* Collapse the space horizontally into column x.
 */
Collapse the space horizontally into column x.
Collapse the space horizontally into column x .
function shift(game, x) {
    let w = game.width;
    let h = game.height;
    let g = game.grid;
    let count;
    do {
        count = 0;
        for (let xx = x; xx < w - 1; xx++) {
            for (let y = 0; y < h; y++) {
                let d = y * w + xx;
                let s = y * w + xx + 1;
                g[d] = g[s];
            }
            count += !!g[(h - 1) * w + xx];
        }
        for (let y = 0; y < h; y++)
            g[y * w + w - 1] = 0;
    } while (count && !g[(h - 1) * w + x]);
}
function shift ( game , x ) { let w = game . width ; let h = game . height ; let g = game . grid ; let count ; do { count = 0 ; for ( let xx = x ; xx < w - 1 ; xx ++ ) { for ( let y = 0 ; y < h ; y ++ ) { let d = y * w + xx ; let s = y * w + xx + 1 ; g [ d ] = g [ s ] ; } count += ! ! g [ ( h - 1 ) * w + xx ] ; } for ( let y = 0 ; y < h ; y ++ ) g [ y * w + w - 1 ] = 0 ; } while ( count && ! g [ ( h - 1 ) * w + x ] ) ; }
Collapse the space horizontally into column x.
Collapse the space horizontally into column x .