chiark / gitweb /
routesearch: middle arch is middle in list of arches, not arch of middle isle
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Fri, 9 Oct 2009 21:11:53 +0000 (22:11 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Fri, 9 Oct 2009 21:11:53 +0000 (22:11 +0100)
yarrg/rscommon.h
yarrg/rsmain.c
yarrg/rssearch.c

index bdcc157..0933e0f 100644 (file)
@@ -163,5 +163,15 @@ static inline int isle2arch(int isle) {
   return arch;
 }
 
+static inline int route2midarch(const int *ports, int nports) {
+  int archs[nports], last_arch=-1, narchs=0, i;
+  for (i=0; i<nports; i++) {
+    int arch= isle2arch(ports[i]);
+    if (arch==last_arch) continue;
+    archs[narchs++]= last_arch= arch;
+  }
+  return archs[narchs/2];
+}
+
 
 #endif /*RSCOMMON_H*/
index b3a6d73..9283fbc 100644 (file)
@@ -113,11 +113,11 @@ int main(int argc, const char **argv) {
       int nports;                                                            \
       for (nports=0; nports<MAX_ROUTELEN && ports[nports]>=0; nports++);      \
       int finisle= ports[nports-1]; int finarch= isle2arch(finisle);         \
-      int midisle= ports[nports/2]; int midarch= isle2arch(midisle);         \
+      int midarch= route2midarch(ports,nports);                                      \
       fprintf(stderr,                                                        \
-             " @%2d #%2d | start%3d mid %d:%3d f%d:%3d | %5d %5d %4d |",     \
+             " @%2d #%2d | start%3d mid%d f%d:%3d | %5d %5d %4d |",     \
              pos, nhighscores_##absperl - 1 - pos,                           \
-             ports[0], midarch,midisle, finarch,finisle,                     \
+             ports[0], midarch, finarch,finisle,                     \
              (int)hs->value, (int)pr->absolute, (int)pr->perleague);         \
       for (i=0; i<nports; i++) fprintf(stderr," %d",ports[i]);               \
       fprintf(stderr,"\n");                                                  \
index 2c530fd..5c6cc66 100644 (file)
@@ -79,7 +79,7 @@ static double process_route(int nports, int totaldist,
   }
 
   int finisle= ports[nports-1]; int finarch= isle2arch(finisle);
-  int midisle= ports[nports/2]; int midarch= isle2arch(midisle);
+  int midarch= route2midarch(ports,nports);
 
   PotentialResult **strat_fin= ONDEMAND(strat_base[finarch], narches);
   PotentialResult *strat= ONDEMAND(strat_fin[midarch], 1);
@@ -105,7 +105,7 @@ static double process_route(int nports, int totaldist,
 
   debugf(" SOMEHOW BEST\n");
 
-  fildebugf("final %d:%3d mid %d:%3d ",finarch,finisle,midarch,midisle);
+  fildebugf("final %d:%3d mid %d ",finarch,finisle,midarch);
 
 #define CHK(absperl)                                                         \
   fildebugf(#absperl " %15f", absperl);                                              \