src/RandomFiller.php
public static function tryToFill(Grid $grid, Distribution $distribution)
    {
        $smallTiles = $distribution->small;
        $tallTiles = $distribution->tall;
        $wideTiles = $distribution->wide;

        for ($i = 0; $i < $distribution->getTiles(); $i++) {
            // Fill small tiles at the end
            if ($wideTiles === 0 && $tallTiles === 0) {
                static::set($grid, Tile::SMALL());
                $smallTiles -= 1;
            // Fill tall tiles if more or equal than wide ones
            } elseif ($tallTiles >= $wideTiles) {
                static::set($grid, Tile::TALL());
                $tallTiles -= 1;
            // Fill wide tiles if more than tall ones
            } else {
                static::set($grid, Tile::WIDE());
                $wideTiles -= 1;
            }
        }
    }
public static function tryToFill(Grid $grid, Distribution $distribution)
    {
        $smallTiles = $distribution->small;
        $tallTiles = $distribution->tall;
        $wideTiles = $distribution->wide;

        for ($i = 0; $i < $distribution->getTiles(); $i++) {
            // Fill small tiles at the end
            if ($wideTiles === 0 && $tallTiles === 0) {
                static::set($grid, Tile::SMALL());
                $smallTiles -= 1;
            // Fill tall tiles if more or equal than wide ones
            } elseif ($tallTiles >= $wideTiles) {
                static::set($grid, Tile::TALL());
                $tallTiles -= 1;
            // Fill wide tiles if more than tall ones
            } else {
                static::set($grid, Tile::WIDE());
                $wideTiles -= 1;
            }
        }
    }
public static function tryToFill ( Grid $ grid , Distribution $ distribution ) { $ smallTiles = $ distribution -> small ; $ tallTiles = $ distribution -> tall ; $ wideTiles = $ distribution -> wide ; for ( $ i = 0 ; $ i < $ distribution -> getTiles ( ) ; $ i ++ ) { // Fill small tiles at the end if ( $ wideTiles === 0 && $ tallTiles === 0 ) { static :: set ( $ grid , Tile :: SMALL ( ) ) ; $ smallTiles -= 1 ; // Fill tall tiles if more or equal than wide ones } elseif ( $ tallTiles >= $ wideTiles ) { static :: set ( $ grid , Tile :: TALL ( ) ) ; $ tallTiles -= 1 ; // Fill wide tiles if more than tall ones } else { static :: set ( $ grid , Tile :: WIDE ( ) ) ; $ wideTiles -= 1 ; } } }
Fill a tiles distribution randomly within a grid.

@param Grid $grid Grid to fill.
@param Distribution $distribution Distribution to set.
@return void
@throws InvalidArgumentException If there is no spot available for the given tile in the grid.
Fill a tiles distribution randomly within a grid .