chiark / gitweb /
routesearch: allow constraining destination island
[ypp-sc-tools.db-live.git] / yarrg / rssearch.c
index 5c6cc66..fd2e66a 100644 (file)
@@ -15,6 +15,7 @@ static Neighbour **neighbours; /* neighbours[islandid]->islandid etc. */
 static sqlite3_stmt *ss_neigh;
 
 static int ports[MAX_ROUTELEN];
+static int final_isle;
 
 static Neighbour *get_neighbours(int isle) {
   Neighbour **np= &neighbours[isle];
@@ -47,6 +48,8 @@ static double process_route(int nports, int totaldist,
 
   ctr_routes_considered++;
 
+  int wrong_final= final_isle && ports[nports-1] != final_isle;
+
   debugf("========== ROUTE");
   for (i=0; i<nports; i++)
     debugf(" %d",ports[i]);
@@ -70,6 +73,12 @@ static double process_route(int nports, int totaldist,
     }
     guess_perleague= guess_absolute / leagues_divisor;
 
+    if (wrong_final) {
+      ctr_routes_wrongfinalelim++;
+      debugf(" WFELIM\n");
+      return guess_absolute;
+    }
+
     if (guess_absolute <= highscores_absolute[0].value &&
        guess_perleague <= highscores_perleague[0].value) {
       ctr_routes_quickelim++;
@@ -99,6 +108,11 @@ static double process_route(int nports, int totaldist,
   double absolute= value_route(nports, ports, 0);
   double perleague= absolute / leagues_divisor;
 
+  if (wrong_final) {
+    ctr_routes_wrongfinal++;
+    return absolute;
+  }
+
   if (absolute <= strat->absolute &&
       perleague <= strat->perleague)
     return absolute;
@@ -167,8 +181,10 @@ static void recurse(int last_isle,
   }
 }
 
-void search(int start_isle, PotentialResult ****strat_base_io) {
+void search(int start_isle, int final_isle_spec,
+           PotentialResult ****strat_base_io) {
   strat_base= ONDEMAND(*strat_base_io, narches);
+  final_isle= final_isle_spec <= 0 ? 0 : final_isle_spec;
   recurse(start_isle,0,0,1e6);
 }