public static function set(Grid $grid, Tile $tile)
    {
        // Boundaries of the grid within which the tile would fit
        $rows = $grid->rows - $tile->height + 1;
        $columns = $grid->columns - $tile->width + 1;

        // Start at a random position
        $row = rand(0, $rows - 1);
        $column = rand(0, $columns - 1);

        // Record the initial position to prevent infinite loop
        $initialRow = $row;
        $initialColumn = $column;

        // Iterate over grid until an empty spot is found
        while (!$grid->isEmptyForTile($row, $column, $tile)) {
            $column = ($column + 1) % $columns;
            if ($column === 0) {
                $row = ($row + 1) % $rows;
            }
            if ($row === $initialRow && $column === $initialColumn) {
                throw new InvalidArgumentException("No empty slot for {$tile} tile in grid: {$grid}");
            }
        }

        $grid->set($row, $column, $tile);
        return [$row, $column];
    }