Merge lp:~widelands-dev/widelands/ai_fisher_fix into lp:widelands

Proposed by TiborB
Status: Merged
Merged at revision: 8647
Proposed branch: lp:~widelands-dev/widelands/ai_fisher_fix
Merge into: lp:widelands
Diff against target: 62 lines (+20/-7)
2 files modified
src/ai/ai_help_structs.h (+1/-1)
src/ai/defaultai.cc (+19/-6)
To merge this branch: bzr merge lp:~widelands-dev/widelands/ai_fisher_fix
Reviewer Review Type Date Requested Status
GunChleoc Approve
hessenfarmer test and review Approve
Review via email: mp+342427@code.launchpad.net

Commit message

AI tweak - fisher now strictly requires fishes in vicinity.

Description of the change

AI tweak - fisher now strictly requires fishes in vicinity.

NOT TESTED! But what can go wrong here :)

To post a comment you must log in.
Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 3323. State: failed. Details: https://travis-ci.org/widelands/widelands/builds/360061692.
Appveyor build 3130. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_ai_fisher_fix-3130.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Famous last words *lol* - I have done some minimal testing.

@bunnybot merge

review: Approve
Revision history for this message
bunnybot (widelandsofficial) wrote :

Refusing to merge, since Travis is not green. Use @bunnybot merge force for merging anyways.

Travis build 3323. State: failed. Details: https://travis-ci.org/widelands/widelands/builds/360061692.

Revision history for this message
hessenfarmer (stephan-lutz) wrote :

fix is not working. Reason is that the algorithm counts all fish in the working radius, but fishermen only are able to extract the fish from the coast so even if there is no catchable fish at all. AI will (and is doing so in my tests) continue to build fishermen huts. Only thing is they now will be build in a region of 6 around the coast instead of 7 around the coast, cause the first water field had been emptied. So as the current game adds default fish to the maps where no fish is defined, we can't solve it in the editors. best thing would be to check whether there is a walkable and reachable field near the ressource befor considering it to be nearby

review: Needs Fixing
Revision history for this message
TiborB (tiborb95) wrote :

Indeed, this fix does not cover situation when fish are there but not reachable from coast.

But eliminates possibility of building a fishers hut in vicinity of water without fish at all.

I will modify the code once more...

Revision history for this message
TiborB (tiborb95) wrote :

OK, so I did it hard way, please test now

(some cleanup needed before merging)

Revision history for this message
hessenfarmer (stephan-lutz) wrote :

still not working properly
see replay

Revision history for this message
hessenfarmer (stephan-lutz) wrote :

didn't know how to add somethign to the branh so I created a bug reprot and added my replay there it shows both the fisher problem not being fixed and the problem with the non conquered mountain area

Revision history for this message
hessenfarmer (stephan-lutz) wrote :

Did a playtest of the algorithm.
Code cleanup looks good.
Thanks to Tibor for his patience and support

review: Approve (test and review)
Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 3351. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/363043830.
Appveyor build 3157. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_ai_fisher_fix-3157.

Revision history for this message
GunChleoc (gunchleoc) wrote :

LGTM - just 1 nit for a comment. Please merge once it's fixed :)

review: Approve
Revision history for this message
TiborB (tiborb95) wrote :

OK, fixed, merging now
@bunnybot merge

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/ai/ai_help_structs.h'
2--- src/ai/ai_help_structs.h 2018-04-03 19:27:20 +0000
3+++ src/ai/ai_help_structs.h 2018-04-07 19:33:55 +0000
4@@ -346,7 +346,7 @@
5 int16_t water_nearby;
6 int16_t open_water_nearby;
7 int16_t distant_water;
8- int8_t fish_nearby;
9+ int16_t fish_nearby;
10 int8_t critters_nearby;
11 ResourceAmount ground_water; // used by wells
12 uint8_t space_consumers_nearby;
13
14=== modified file 'src/ai/defaultai.cc'
15--- src/ai/defaultai.cc 2018-04-02 08:44:26 +0000
16+++ src/ai/defaultai.cc 2018-04-07 19:33:55 +0000
17@@ -1471,10 +1471,23 @@
18 }
19 }
20
21- // counting fields with fish
22- if (field.water_nearby > 0 && (field.fish_nearby == kUncalculated || resource_count_now)) {
23- field.fish_nearby = map.find_fields(Area<FCoords>(field.coords, kProductionArea), nullptr,
24- FindNodeResource(world.get_resource("fish")));
25+ // counting fields with fish, doing it roughly every 10-th minute is enough
26+ if (field.water_nearby > 0 && (field.fish_nearby == kUncalculated || (resource_count_now && gametime % 10 == 0))) {
27+ CheckStepWalkOn fisher_cstep(MOVECAPS_WALK, true);
28+ static std::vector<Coords> fish_fields_list; // pity this contains duplicates
29+ fish_fields_list.clear();
30+ map.find_reachable_fields(Area<FCoords>(field.coords, kProductionArea),
31+ &fish_fields_list, fisher_cstep, FindNodeResource(world.get_resource("fish")));
32+
33+ // This is "list" of unique fields in fish_fields_list we got above
34+ static std::set<Coords> counted_fields;
35+ counted_fields.clear();
36+ field.fish_nearby = 0;
37+ for (auto fish_coords : fish_fields_list) {
38+ if (counted_fields.insert(fish_coords).second) {
39+ field.fish_nearby += map.get_fcoords(fish_coords).field->get_resources_amount();
40+ }
41+ }
42 }
43
44 // Counting resources that do not change fast
45@@ -2724,7 +2737,7 @@
46
47 } else if (bo.is(BuildingAttribute::kFisher)) { // fisher
48
49- if (bf->water_nearby < 2 || bf->fish_nearby < 2) {
50+ if (bf->fish_nearby <= 15) {
51 continue;
52 }
53
54@@ -4359,7 +4372,7 @@
55 // hunters)
56 if (site.bo->inputs.empty() && site.bo->production_hints.empty() &&
57 site.site->can_start_working() && !site.bo->is(BuildingAttribute::kSpaceConsumer) &&
58- site.site->get_statistics_percent() < 10 &&
59+ site.site->get_statistics_percent() < 5 &&
60 ((game().get_gametime() - site.built_time) > 10 * 60 * 1000)) {
61
62 site.bo->last_dismantle_time = game().get_gametime();

Subscribers

People subscribed via source and target branches

to status/vote changes: