Invert GMLscripts.com

ds_grid_shuffle

NOTE: The GameMaker:Studio function of the same name produces the same results and obsoletes this script.

$$\text{Original}=\begin{bmatrix}A&B&C\\D&E&F\end{bmatrix} \qquad\text{Shuffled}=\begin{bmatrix}E&A&F\\C&B&D\end{bmatrix}$$

ds_grid_shuffle(id)
Rearranges the cell contents of a given grid in randomly.
COPY/// ds_grid_shuffle(id)
//
//  Rearranges the cell contents of a given grid in randomly.
//
//      id          grid data structure, real
//
/// GMLscripts.com/license
{
    var grid,w,h,xx,yy,temp,tx,ty;
    grid = argument0;
    w = ds_grid_width(grid);
    h = ds_grid_height(grid);
    for (xx=0; xx<w; xx+=1) {
        for (yy=0; yy<h; yy+=1) {
            tx = floor(random(w));
            ty = floor(random(h));
            temp = ds_grid_get(grid,xx,yy);
            ds_grid_set(grid,xx,yy,ds_grid_get(grid,tx,ty));
            ds_grid_set(grid,tx,ty,temp);
        }
    }
    return 0;
}

Contributors: IceMetalPunk, xot

GitHub: View · Commits · Blame · Raw