feature/avoid-repeating-places-in-game #38
@ -60,11 +60,11 @@ class PlaceRepository
|
||||
return $places;
|
||||
}
|
||||
|
||||
private function getRandomForMapWithValidPano($numberOfPlaces, $select, array &$exclude, $randomSelection = null): ?Place
|
||||
private function getRandomForMapWithValidPano($numberOfPlaces, $select, array &$exclude, $pickRandomInt = null): ?Place
|
||||
{
|
||||
do {
|
||||
$numberOfPlacesLeft = $numberOfPlaces - count($exclude);
|
||||
$place = $this->selectRandomFromDbForMap($numberOfPlacesLeft, $select, $exclude, $randomSelection);
|
||||
$place = $this->selectRandomFromDbForMap($numberOfPlacesLeft, $select, $exclude, $pickRandomInt);
|
||||
if($place === null) {
|
||||
// there is no more never visited place left
|
||||
return null;
|
||||
@ -79,15 +79,15 @@ class PlaceRepository
|
||||
return $place;
|
||||
}
|
||||
|
||||
private function selectRandomFromDbForMap($numberOfPlacesLeft, $select, array $exclude, $randomSelection): ?Place
|
||||
private function selectRandomFromDbForMap($numberOfPlacesLeft, $select, array $exclude, $pickRandomInt): ?Place
|
||||
{
|
||||
if($numberOfPlacesLeft <= 0)
|
||||
return null;
|
||||
|
||||
if(!isset($randomSelection)) {
|
||||
if(!isset($pickRandomInt)) {
|
||||
$randomOffset = random_int(0, $numberOfPlacesLeft - 1);
|
||||
} else {
|
||||
$randomOffset = $randomSelection($numberOfPlacesLeft);
|
||||
$randomOffset = $pickRandomInt($numberOfPlacesLeft);
|
||||
}
|
||||
|
||||
// $select_unvisited->orderBy('last_time');
|
||||
@ -150,7 +150,7 @@ class PlaceRepository
|
||||
$selectOldPlaces->orderBy('last_time');
|
||||
|
||||
// selection algorithm with preference (weighting) for older places
|
||||
$gaussianRandomSelection = function($numberOfPlaces) {
|
||||
$pickGaussianRandomInt = function($numberOfPlaces) {
|
||||
$stdev = 0.2;
|
||||
$avg = 0.0;
|
||||
$x = mt_rand() / mt_getrandmax();
|
||||
@ -162,7 +162,7 @@ class PlaceRepository
|
||||
// look for n - numberOfUnvisitedPlaces places
|
||||
while(count($places) < $n)
|
||||
{
|
||||
$place = $this->getRandomForMapWithValidPano($numberOfOldPlaces, $selectOldPlaces, $exclude, $gaussianRandomSelection);
|
||||
$place = $this->getRandomForMapWithValidPano($numberOfOldPlaces, $selectOldPlaces, $exclude, $pickGaussianRandomInt);
|
||||
if(isset($place))
|
||||
{
|
||||
$places[] = $place;
|
||||
@ -172,6 +172,5 @@ class PlaceRepository
|
||||
|
||||
return $places;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user