GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2020-08-16 07:02:08

redeyesmaster
Member
Registered: 2020-08-09
Posts: 43

ds_grid_shuffle_adv

Expand///ds_grid_shuffle_adv(DSGridIndex, x, y)
// This script will not "randomize()" you must set that your self,
// that way you can use a seed if you want.

/**
 * Shuffles around the grid based on row or column
 *
 * @param   DSMapIndex  The input DS map, DSMap
 * @param   x           true = shuffles by columns
 * @param   y           true = shuffles by rows
 *
 * @return  nothing
 */

/// GMLscripts.com/license


var _grid, _width, widthmax, _height, heightmax;


_grid     = argument[0];
_width    = ds_grid_width(_grid);
widthmax  = _width
_height   = ds_grid_height(_grid);
heightmax = _height
_gridTemp = ds_grid_create(_width,_height)

if (argument[1] = 1) && (argument[2] = 0)
{
    for (var _i=0; _i < widthmax; _i++)
    {
        _width = ds_grid_width(_grid)
        var xrandom = irandom(_width-1)
        ds_grid_set_grid_region(_gridTemp, _grid, xrandom, 0, xrandom, _height-1, _i, 0)
        ds_grid_set_grid_region(_grid, _grid, xrandom+1, 0, _width-1, _height-1, xrandom, 0);
        ds_grid_resize(_grid,_width-1,_height);
        if (_width = 1) break;
    }
    ds_grid_resize(_grid, widthmax, heightmax)
    ds_grid_copy(_grid, _gridTemp)
}


if (argument[1] = 0) && (argument[2] = 1)
{
    for (var _i=0; _i < heightmax; _i++)
    {
        _height = ds_grid_height(_grid)
        var yrandom = irandom(_height-1)
        ds_grid_set_grid_region(_gridTemp, _grid, 0, yrandom, _width-1, yrandom, 0, _i)
        ds_grid_set_grid_region(_grid, _grid, 0, yrandom+1, _width-1, _height-1, 0, yrandom);
        ds_grid_resize(_grid,_width,_height-1);
        if (_height = 1) break;
    }
    ds_grid_resize(_grid, widthmax, heightmax)
    ds_grid_copy(_grid, _gridTemp)
}

if  (argument[1] = 1) && (argument[2] = 1)
{
    ds_grid_shuffle(_grid)
}
ds_grid_destroy(_grid)
ds_grid_destroy(_gridTemp)
return _grid;

This adds more options for shuffling your ds grids then the vanilla function.

Last edited by redeyesmaster (2020-08-16 07:03:07)

Offline

#2 2020-08-17 16:13:11

xot
Administrator
Registered: 2007-08-18
Posts: 1,239

Re: ds_grid_shuffle_adv

This is good idea for a script. I might split these into ds_grid_shuffle_rows() and ds_grid_shuffle_columns() variants.


Abusing forum power since 1986.

Offline

#3 2020-08-18 02:01:39

redeyesmaster
Member
Registered: 2020-08-09
Posts: 43

Re: ds_grid_shuffle_adv

xot wrote:

I might split these into ds_grid_shuffle_rows() and ds_grid_shuffle_columns() variants.

I thought there was already a shuffle function for rows, but looking into it I guess not. Maybe i'm thinking another data structure. I actually found a bug with it before I posted it where i was returning (ending the script) before I was destroying the temporary structures. I would highly suggest looking into this before pushing it any further forward. My debug has been broken for years so I'm not able to see if it's creating extra grids with out an unreasonable amount of effort.

Edit: Oh yeah I remember why I didn't make it two separate scripts, it's because the GMS documentation pages refer to the two words as if they are interchangeable for some reason. The X of a grid is not the same thing as the X of a graph, it's more like the Y, then when you get into grid heights and lengths this makes even less sense because they work as you suspect they would, then when you're handling specifically rows and columns they are reversed again. Which is why the X argument shuffles the columns and the Y shuffles the rows. Those arguments should probably be changed to sufffleX, shuffleY.

Last edited by redeyesmaster (2020-08-18 02:14:09)

Offline

Board footer

Powered by FluxBB