New calculations are up: https://fosuta.org/pics/Territorial_Times_v5.ods
I just added revision 8989. I tried to set the inner_radius variable to 1/1/1 just for testing but the result was, that time went up, but we didn't gain many fields. So it wasn't worth it. @kaputtnik please heave a look at the table. We are faster than trunk for the majority of the maps. 18 are less than 100ms slower. 3 less than 200. 1 is 269 and another one 1787. So we are better than before IMHO. Diff comments: > > === modified file 'src/logic/map.cc' > --- src/logic/map.cc 2019-02-12 17:27:04 +0000 > +++ src/logic/map.cc 2019-02-21 09:14:58 +0000 > @@ -255,6 +257,77 @@ > } > } > > + > +std::set<FCoords> Map::calculate_valuable_fields() const { > + std::set<FCoords> result; > + std::set<FCoords> check; > + > + ScopedTimer timer("Calculating valuable fields took %ums"); > + > + // Add all land coordinates starting from the given field for the given > radius > + const auto add_starting_coords = [this, &result, &check](const Coords& > coords, int radius) { > + MapRegion<Area<FCoords>> mr(*this, > Area<FCoords>(get_fcoords(coords), radius)); > + do { > + if (!(mr.location().field->maxcaps() & MOVECAPS_SWIM)) { > + result.insert(mr.location()); > + check.insert(mr.location()); > + } > + } while (mr.advance(*this)); > + }; > + > + // Initialize the fields table and the check area with the regions > around the starting field of each player > + for (const Coords& coords : starting_pos_) { > + add_starting_coords(coords, 9); > + } > + > + // Add port spaces to the starting check area > + if (allows_seafaring()) { > + for (const Coords& coords : get_port_spaces()) { > + add_starting_coords(coords, 5); > + } > + } > + > + // Walk the map > + while (!check.empty()) { > + std::set<FCoords> new_fields; > + // Checking the check region for buildcaps and add fields that > can be conquered > + for (const FCoords& fcoords : check) { > + int radius = 0; > + int inner_radius = 1; > + Field* field = fcoords.field; > + if ((field->maxcaps() & BUILDCAPS_BIG) == > BUILDCAPS_BIG) { Never mind. I was wrong. > + radius = 9; > + inner_radius = 7; > + } else if (field->maxcaps() & BUILDCAPS_MEDIUM) { > + radius = 7; > + inner_radius = 5; > + } else if (field->maxcaps() & BUILDCAPS_SMALL) { > + radius = 5; > + } > + if (radius > 0) { > + Widelands::HollowArea<> > hollow_area(Widelands::Area<>(fcoords, radius), inner_radius); > + Widelands::MapHollowRegion<> mr(*this, > hollow_area); > + do { > + const FCoords& candidate = > get_fcoords(mr.location()); > + if ((check.count(candidate) == 0) > + && (result.count(candidate) == > 0) > + && (candidate.field->maxcaps() > & MOVECAPS_WALK)) { > + result.insert(candidate); > + new_fields.insert(candidate); > + } > + > + } while (mr.advance(*this)); > + } > + } > + check.clear(); > + check = new_fields; > + } > + > + log("Found %" PRIuS " valuable fields\n", result.size()); > + > + return result; > +} > + > /* > =============== > remove your world, remove your data -- https://code.launchpad.net/~widelands-dev/widelands/bug-1810062-territorial-calculations/+merge/361366 Your team Widelands Developers is subscribed to branch lp:~widelands-dev/widelands/bug-1810062-territorial-calculations. _______________________________________________ Mailing list: https://launchpad.net/~widelands-dev Post to : widelands-dev@lists.launchpad.net Unsubscribe : https://launchpad.net/~widelands-dev More help : https://help.launchpad.net/ListHelp