Skip to content

Commit

Permalink
Better waypoint selection and fixes
Browse files Browse the repository at this point in the history
Now just the first waypoint is chosen randomly, the following are selected by distance.
  • Loading branch information
olewehrmeyer committed Oct 11, 2014
1 parent af33e5d commit 7551176
Showing 1 changed file with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@

import org.androidannotations.annotations.EService;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import de.happycarl.geotown.app.AppConstants;
Expand Down Expand Up @@ -162,7 +165,7 @@ public void handleMessage(Message msg) {
}
break;
case MSG_QUESTION_ANSWERED:
questionAswered();
questionAnswered();
break;
default:
super.handleMessage(msg);
Expand Down Expand Up @@ -368,7 +371,7 @@ private boolean loadCurrentWaypoint() {
}

private void setLocationToWaypoint() {
currentTarget = new Location("GeoTownWaypoint");
currentTarget = new Location("GeoTown Dummy Provider");
currentTarget.setLatitude(currentWaypoint.latitude);
currentTarget.setLongitude(currentWaypoint.longitude);

Expand All @@ -383,7 +386,7 @@ private void selectNewWaypoint() {
if (random == null || currentRoute == null)
return;
if (currentWaypoint == null || currentWaypoint.done) {
//Random with seed testing area

List<GeoTownWaypoint> waypoints = new Select()
.from(GeoTownWaypoint.class)
.where("done = ?", false)
Expand All @@ -409,19 +412,33 @@ private void selectNewWaypoint() {
Log.d("GameService", "NO TRACK UPLOAD");
}
} else {
int index = Math.abs(random.nextInt() % waypoints.size());
Log.d("seed", "index: " + index + ": " + waypoints.size());
currentWaypoint = waypoints.get(index);
currentWaypoint.save();
Log.d("selectNewWaypoint", "new ID: " + currentWaypoint.id);
//Fist waypoint selection
if(currentTarget == null) {
currentWaypoint = waypoints.get(0);
currentWaypoint.save();
} else {
Location nextWPLocation = new Location("GeoTown Dummy Provider");
Map<Float, GeoTownWaypoint> waypointMap = new HashMap<>();

//Calculate the distance to each waypoint
for (GeoTownWaypoint wp : waypoints) {
nextWPLocation.setLatitude(wp.latitude);
nextWPLocation.setLongitude(wp.longitude);
waypointMap.put(currentTarget.distanceTo(nextWPLocation), wp);
}
Float minDistance = Collections.min(waypointMap.keySet());
currentWaypoint = waypointMap.get(minDistance);
currentWaypoint.save();
}

setLocationToWaypoint();

reportWaypoint();
}
}
}

private void questionAswered() {
private void questionAnswered() {
currentWaypoint.done = true;
currentWaypoint.save();
selectNewWaypoint();
Expand Down

0 comments on commit 7551176

Please sign in to comment.