Merge lp:~widelands-dev/widelands/bug-1728006 into lp:widelands

Proposed by TiborB
Status: Merged
Merged at revision: 8473
Proposed branch: lp:~widelands-dev/widelands/bug-1728006
Merge into: lp:widelands
Diff against target: 84 lines (+33/-2)
2 files modified
src/ai/ai_help_structs.h (+1/-0)
src/ai/defaultai.cc (+32/-2)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-1728006
Reviewer Review Type Date Requested Status
GunChleoc Approve
Review via email: mp+333094@code.launchpad.net

Commit message

Add support for productionsites that are also supporting site to the AI.

Description of the change

This adds support for productionsites that are also supporting site. Needs testing with frisian branch. And AI training a bit, but not as a part of this merge request of course.

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

You should get rid of kPureProducer. Looks good to me otherwise. Not tested yet.

Revision history for this message
TiborB (tiborb95) wrote :

Good catch:) Removed...

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 2740. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/296462194.
Appveyor build 2552. State: failed. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1728006-2552.

Revision history for this message
GunChleoc (gunchleoc) wrote :

I have done some testing now.

@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-09-29 16:10:25 +0000
3+++ src/ai/ai_help_structs.h 2017-11-02 20:15:48 +0000
4@@ -78,6 +78,7 @@
5 kUpgradeExtends,
6 kLogRefiner,
7 kIronMine,
8+ kSupportingProducer,
9 };
10
11 enum class AiType : uint8_t { kVeryWeak, kWeak, kNormal };
12
13=== modified file 'src/ai/defaultai.cc'
14--- src/ai/defaultai.cc 2017-09-29 16:10:25 +0000
15+++ src/ai/defaultai.cc 2017-11-02 20:15:48 +0000
16@@ -698,6 +698,11 @@
17 bo.positions.push_back(temp_position.first);
18 }
19
20+ // If this is a producer, does it act also as supporter?
21+ if (!bo.outputs.empty() && !bo.production_hints.empty()) {
22+ bo.set_is(BuildingAttribute::kSupportingProducer);
23+ }
24+
25 iron_ore_id = tribe_->ironore();
26
27 if (bo.type == BuildingObserver::Type::kMine) {
28@@ -2649,7 +2654,7 @@
29 prio -= (bf->enemy_nearby) * 100;
30 prio -= (expansion_type.get_expansion_type() != ExpansionMode::kEconomy) * 100;
31 } else { // finally normal productionsites
32- assert(bo.production_hints.empty());
33+ assert(bo.production_hints.empty() || bo.is(BuildingAttribute::kSupportingProducer));
34
35 if (bo.new_building == BuildingNecessity::kForced) {
36 prio += 150;
37@@ -2709,6 +2714,21 @@
38 }
39 }
40
41+ // This is for a special case this is also supporter, it considers
42+ // producers nearby
43+ for (auto ph : bo.production_hints) {
44+ prio += management_data.neuron_pool[51].get_result_safe(
45+ bf->producers_nearby.at(ph) * 5, kAbsValue) /
46+ 2;
47+ }
48+
49+ // This considers supporters nearby
50+ for (auto ph : bo.outputs) {
51+ prio += management_data.neuron_pool[52].get_result_safe(
52+ bf->supporters_nearby.at(ph) * 5, kAbsValue) /
53+ 2;
54+ }
55+
56 if (prio <= 0) {
57 continue;
58 }
59@@ -4762,7 +4782,8 @@
60 bo.cnt_under_construction + bo.unoccupied_count == 0) {
61 bo.max_needed_preciousness = bo.max_preciousness; // even when rocks are not needed
62 return BuildingNecessity::kAllowed;
63- } else if (!bo.production_hints.empty()) {
64+ } else if (!bo.production_hints.empty() && !bo.is(BuildingAttribute::kSupportingProducer)) {
65+ // Pure supporting sites only
66
67 if (bo.cnt_under_construction + bo.unoccupied_count - bo.unconnected_count > 0) {
68 return BuildingNecessity::kForbidden;
69@@ -5126,6 +5147,15 @@
70 inputs[99] = (wood_policy_ == WoodPolicy::kAllowRangers) ? -1 : 0;
71 inputs[100] = (bo.total_count() == 0) ? 3 : 0;
72 inputs[101] = (bo.total_count() == 0) ? 6 : 0;
73+ if (bo.is(BuildingAttribute::kSupportingProducer)) {
74+ if (bo.total_count() == 0) {
75+ inputs[102] = 1;
76+ inputs[103] = 2;
77+ inputs[104] = -2;
78+ }
79+ inputs[105] = -2;
80+ inputs[106] = -2;
81+ }
82
83 int16_t tmp_score = 0;
84 for (uint8_t i = 0; i < kFNeuronBitSize; ++i) {

Subscribers

People subscribed via source and target branches

to status/vote changes: