Skip to content

Instantly share code, notes, and snippets.

@connors511
Created May 22, 2013 22:39
Show Gist options
  • Save connors511/5631515 to your computer and use it in GitHub Desktop.
Save connors511/5631515 to your computer and use it in GitHub Desktop.
function createHouses() {
$tries = 0;
$max_tries = 3;
$timeout = 500;
$time_start = microtime(true);
$start =
$use = 'timeout';
while($house_count > 0) {
if ($use == 'timeout') {
if (microtime(true) - $time_start > $timeout) {
break;
}
} else {
if ($tries == $max_tries) {
break;
}
}
for ($i=0; $i < $n; $i++) {
for ($j=0; $j < $n; $j++) {
if ($house_count == 0) {
break;
}
if ($this->grid[$i][$j] == Types::$TYPE_GRASS)
{
// Higher chance near intersections?
if ($this->hasNearbyRoad($i,$j) && ($allow_nearby_house || !$this->hasNearbyHouse($i,$j))) {
// var isWall = Math.floor(Math.random()*(/wallFrequency));
$chance = (rand(0,1000) / 1000) <= $house_pct;
if ($chance) {
$this->grid[$i][$j] = Types::$TYPE_HOUSE;
$this->houses[] = array('x' => $i, 'y' => $j);
$house_count--;
}
}
}
}
}
$tries++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment