X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.db-test.git;a=blobdiff_plain;f=yarrg%2Frssearch.c;h=245070e9ad6c34740f576707dee52dca95df03b1;hp=9676640aafc9e3a28a14b2374660d777e5806c55;hb=3438eb65e4043afc6557b0e8dec38cc8027434df;hpb=8dd381ffb993692b376e48eaa4b9ab506b3568e2 diff --git a/yarrg/rssearch.c b/yarrg/rssearch.c index 9676640..245070e 100644 --- a/yarrg/rssearch.c +++ b/yarrg/rssearch.c @@ -1,4 +1,29 @@ -/**/ +/* + * Route searcher - recursive iteration over all routes + */ +/* + * This is part of the YARRG website, a tool for assisting + * players of Yohoho Puzzle Pirates. + * + * Copyright (C) 2009 Ian Jackson + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * Yohoho and Puzzle Pirates are probably trademarks of Three Rings and + * are used without permission. This program is not endorsed or + * sponsored by Three Rings. + */ #include "rscommon.h" @@ -38,12 +63,12 @@ static Neighbour *get_neighbours(int isle) { } -static PotentialResult ***buckets_base[GRANUS]; +static Bucket ***buckets_base[GRANUS]; static double process_route(int nports, int totaldist, double overestimate_excepting_tail) { - int i, ap; + int i, ap, granui; int leagues_divisor= totaldist + nports; ctr_routes_considered++; @@ -79,12 +104,15 @@ static double process_route(int nports, int totaldist, return guess[A]; } - if (guess[A] <= highscores[GRANUS-1][A][0].value && - guess[P] <= highscores[GRANUS-1][P][0].value) { - ctr_routes_quickelim++; - debugf(" QELIM %f %f\n", guess[A], guess[P]); - return guess[A]; + for (granui=0; granui highscores[granui][A][0].value || + guess[P] > highscores[granui][P][0].value) + goto not_quickelim; } + ctr_routes_quickelim++; + debugf(" QELIM %f %f\n", guess[A], guess[P]); + return guess[A]; + not_quickelim:; } int finisle= ports[nports-1]; @@ -93,10 +121,9 @@ static double process_route(int nports, int totaldist, int midisle= ports[nports/2]; int midarch= route2midarch(ports,nports); - PotentialResult *buckets[GRANUS]; - int granui; + Bucket *buckets[GRANUS]; for (granui=0; granui=2) { - if (guess[A] <= buckets[0]->value[A] && - guess[P] <= buckets[0]->value[P]) { - ctr_routes_bucketelim++; - debugf(" ELIM %f %f\n", guess[A], guess[P]); - return guess[A]; - } + for (granui=0; granui buckets[granui]->prs[ap].value[ap] && + guess[ap] > highscores[granui][ap][0].value) + goto not_bucketelim; + ctr_routes_bucketelim++; + debugf(" ELIM %f %f\n", guess[A], guess[P]); + return guess[A]; + not_bucketelim: debugf(" COMPUTE %f %f\n", guess[A], guess[P]); } @@ -130,38 +160,40 @@ static double process_route(int nports, int totaldist, } for (granui=granus-1; granui>=0; granui--) { - PotentialResult *bucket= buckets[granui]; + Bucket *bucket= buckets[granui]; - if (value[A] <= bucket->value[A] && - value[P] <= bucket->value[P]) + if (value[A] <= bucket->prs[A].value[A] && + value[P] <= bucket->prs[P].value[P]) continue; debugf(" SOMEHOW %d BEST\n",granui); - fildebugf("final %d:%3d mid %d ",finarch,finisle,midarch); + fildebugf("granu %d f%d:%3d mid%d:%3d ",granui, + finarch,finisle,midarch,midisle); for (ap=0; apvalue[ap]) { + if (value[ap] < bucket->prs[ap].value[ap]) { debugf(" "); } else { int pos; ctr_newbests_granu[granui*AP+ap]++; - bucket->value[ap]= value[ap]; - memcpy(bucket->ports[ap], ports, sizeof(*ports) * nports); - if (nports < MAX_ROUTELEN-1) bucket->ports[ap][nports]= -1; + bucket->prs[ap].length= totaldist; + memcpy(bucket->prs[ap].value, value, sizeof(value)); + memcpy(bucket->prs[ap].ports, ports, sizeof(*ports) * nports); + if (nports < MAX_ROUTELEN-1) bucket->prs[ap].ports[nports]= -1; fildebugf("** "); - for (pos=0; pos < *nscores; pos++) - if (scores[pos].pr == bucket) goto found; + for (pos=0; pos < nscores; pos++) + if (scores[pos].bucket == bucket) goto found; /* not found */ pos= -1; found: for (;;) { pos++; - if (pos >= *nscores-1) break; /* new top */ + if (pos >= nscores) break; /* new top */ if (scores[pos].value >= value[ap]) break; /* found spot */ if (pos>0) scores[pos-1]= scores[pos]; @@ -169,12 +201,20 @@ static double process_route(int nports, int totaldist, pos--; if (pos>0) { scores[pos].value= value[ap]; - scores[pos].pr= bucket; + scores[pos].bucket= bucket; + if (granui < granus-1 && + highscores[granui][A][0].bucket && + highscores[granui][P][0].bucket) { + /* both absolute and perleague are full at this granularity, + * so we don't care about anything more granular */ + fildebugf("\n STOP-GRANU "); + granus= granui+1; + } } - fildebugf("@%2d", pos); - } - } - } + fildebugf("@%2d/%2d ", pos, nscores); + } /* new best */ + } /* ap */ + } /* granui */ fildebugf(" route"); @@ -203,7 +243,7 @@ static void recurse(int last_isle, } void search(int start_isle, int final_isle_spec, - PotentialResult ****buckets_base_io[GRANUS]) { + Bucket ****buckets_base_io[GRANUS]) { int granui; for (granui=0; granui