Skip to content

Instantly share code, notes, and snippets.

@obukhow
Last active December 14, 2015 06:18
Show Gist options
  • Save obukhow/5041024 to your computer and use it in GitHub Desktop.
Save obukhow/5041024 to your computer and use it in GitHub Desktop.
<?php
public function getPlaceInArray(&$array, &$ri, &$rj, $di = 1, $dj = 1, $t = null)
{
$ri = 0;
$rj = 0;
while (1) {
$ri = rand(0, Mage::getStoreConfig('project/config/lines') - $di);
$rj = rand(0, Mage::getStoreConfig('project/config/columns') - $dj);
$fl = 1;
for ($ti = $ri; $ti < $ri + $di; $ti++) {
for ($tj = $rj; $tj < $rj + $dj; $tj++) {
if ($array[$ti][$tj + ($di - 1)] != 0) {
$fl = 0;
break;
}
}
}
if ($fl)
break;
}
for ($ti = $ri; $ti < $ri + $di; $ti++) {
for ($tj = $rj; $tj < $rj + $dj; $tj++) {
$array[$ti][$tj] = $t;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment