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

Proposed by TiborB
Status: Merged
Merged at revision: 8431
Proposed branch: lp:~widelands-dev/widelands/ai_helper_sites
Merge into: lp:widelands
Diff against target: 142 lines (+60/-25)
2 files modified
src/ai/ai_help_structs.h (+2/-0)
src/ai/defaultai.cc (+58/-25)
To merge this branch: bzr merge lp:~widelands-dev/widelands/ai_helper_sites
Reviewer Review Type Date Requested Status
GunChleoc Approve
Review via email: mp+329281@code.launchpad.net

Commit message

Changes the scoring algorithm for helper sites to make them more buildable...

Description of the change

Changes the scoring code for helper sites - except for Rangers. Previous algorithm provided to low score so the sites were not properly built.

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

Continuous integration builds have changed state:

Travis build 2582. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/266367249.
Appveyor build 2404. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_ai_helper_sites-2404.

Revision history for this message
GunChleoc (gunchleoc) wrote :

LGTM :)

@bunnybot merge

review: Approve

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 2017-08-19 19:33:37 +0000
3+++ src/ai/ai_help_structs.h 2017-08-20 09:17:31 +0000
4@@ -439,6 +439,8 @@
5 uint16_t mines_percent; // % of res it can mine
6 uint32_t current_stats;
7
8+ uint32_t basic_amount; // basic amount for basic economy as defined in init.lua
9+
10 std::vector<Widelands::DescriptionIndex> inputs;
11 std::vector<Widelands::DescriptionIndex> outputs;
12 std::vector<Widelands::DescriptionIndex> positions;
13
14=== modified file 'src/ai/defaultai.cc'
15--- src/ai/defaultai.cc 2017-08-19 19:33:37 +0000
16+++ src/ai/defaultai.cc 2017-08-20 09:17:31 +0000
17@@ -634,6 +634,7 @@
18 persistent_data->remaining_basic_buildings[bo.id] = bh.basic_amount();
19 ++persistent_data->remaining_buildings_size;
20 }
21+ bo.basic_amount = bh.basic_amount();
22 if (bh.get_needs_water()) {
23 bo.set_is(BuildingAttribute::kNeedsCoast);
24 }
25@@ -2562,13 +2563,9 @@
26 } else if (bo.production_hint >= 0) {
27 if (bo.is(BuildingAttribute::kRanger)) {
28 assert(bo.cnt_target > 0);
29- } else {
30- bo.cnt_target =
31- 1 + static_cast<int32_t>(mines_.size() + productionsites.size()) / 50;
32 }
33
34- // They have no own primary priority
35- assert(bo.primary_priority == 0);
36+ prio += bo.primary_priority;
37
38 if (bo.is(BuildingAttribute::kRanger)) {
39
40@@ -2582,6 +2579,7 @@
41 prio += std::abs(management_data.get_military_number_at(66)) *
42 (bo.cnt_target - bo.total_count());
43 }
44+
45 prio -= bf->water_nearby / 5;
46
47 prio += management_data.neuron_pool[67].get_result_safe(
48@@ -2609,25 +2607,24 @@
49 prio += (-6 + bf->fish_nearby) / 3;
50 }
51
52- if ((bo.total_count() - bo.unconnected_count) > bo.cnt_target) {
53- continue;
54- }
55-
56- if (get_stocklevel(bo, gametime) > 50) {
57- continue;
58- }
59-
60- if (bo.total_count() == 0) {
61- prio += 100;
62- } else if (!bo.is(BuildingAttribute::kNeedsCoast)) {
63- prio += 10 / bo.total_count();
64+ const uint32_t current_stocklevel = (get_stocklevel(bo, gametime));
65+
66+ if (current_stocklevel > 50 &&
67+ persistent_data->remaining_basic_buildings.count(bo.id) == 0) {
68+ continue;
69+ }
70+
71+ if (current_stocklevel < 40) {
72+ prio += 5 *
73+ management_data.neuron_pool[23].get_result_safe(
74+ (40 - current_stocklevel) / 2, kAbsValue);
75 }
76
77 prio += bf->producers_nearby.at(bo.production_hint) * 10;
78 prio -= bf->supporters_nearby.at(bo.production_hint) * 20;
79
80 if (bf->enemy_nearby) {
81- prio -= 5;
82+ prio -= 20;
83 }
84 }
85
86@@ -4743,13 +4740,49 @@
87 bo.cnt_under_construction + bo.unoccupied_count == 0) {
88 bo.max_needed_preciousness = bo.max_preciousness; // even when rocks are not needed
89 return BuildingNecessity::kAllowed;
90- } else if (bo.production_hint >= 0 && bo.cnt_under_construction + bo.unoccupied_count == 0) {
91- bo.cnt_target = 1 + static_cast<int32_t>(mines_.size() + productionsites.size()) / 30;
92- if (bo.cnt_target <= bo.total_count()) {
93- return BuildingNecessity::kAllowed;
94- }
95- if (get_stocklevel(bo, gametime) == 0 &&
96- bo.last_building_built + 10 * 60 * 100 < gametime) {
97+ } else if (bo.production_hint >= 0) {
98+
99+ if (bo.cnt_under_construction + bo.unoccupied_count - bo.unconnected_count > 0) {
100+ return BuildingNecessity::kForbidden;
101+ }
102+
103+ // Rangers have been processed above
104+ assert(!bo.is(BuildingAttribute::kRanger));
105+
106+ bo.primary_priority = 0;
107+
108+ if (!basic_economy_established) {
109+ bo.cnt_target = bo.basic_amount;
110+ } else {
111+ bo.cnt_target = 1 + static_cast<int32_t>(mines_.size() + productionsites.size()) / 30;
112+ }
113+
114+ if (bo.total_count() > bo.cnt_target + 1) {
115+ return BuildingNecessity::kForbidden;
116+ }
117+
118+ // We allow another helper site if:
119+ // a) we are under target
120+ // b) if there is shortage of supported ware
121+ if (bo.total_count() < bo.cnt_target ||
122+ (get_stocklevel(bo, gametime) == 0 &&
123+ bo.last_building_built + 10 * 60 * 100 < gametime)) {
124+
125+ if (persistent_data->remaining_basic_buildings.count(bo.id)) {
126+ bo.primary_priority += std::abs(management_data.get_military_number_at(60) * 10);
127+ }
128+
129+ if (bo.total_count() < bo.cnt_target) {
130+ if (basic_economy_established) {
131+ bo.primary_priority += std::abs(management_data.get_military_number_at(51) * 6);
132+ } else if (persistent_data->remaining_basic_buildings.count(bo.id)) {
133+ bo.primary_priority += std::abs(management_data.get_military_number_at(146) * 6);
134+ } else {
135+ bo.primary_priority +=
136+ -200 + std::abs(management_data.get_military_number_at(147) * 8);
137+ }
138+ }
139+
140 return BuildingNecessity::kAllowed;
141 }
142 return BuildingNecessity::kForbidden;

Subscribers

People subscribed via source and target branches

to status/vote changes: