Merge lp:~widelands-dev/widelands/relax-ai-asserts into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 9200
Proposed branch: lp:~widelands-dev/widelands/relax-ai-asserts
Merge into: lp:widelands
Diff against target: 174 lines (+39/-24)
3 files modified
src/ai/ai_help_structs.cc (+18/-0)
src/ai/ai_help_structs.h (+7/-2)
src/ai/defaultai.cc (+14/-22)
To merge this branch: bzr merge lp:~widelands-dev/widelands/relax-ai-asserts
Reviewer Review Type Date Requested Status
TiborB Approve
Review via email: mp+372400@code.launchpad.net

Commit message

Some improvements around AI asserts

- Relax AI requirement for hunters
- Be more informative when building is missing the
  "collects_ware_from_map" AI hint

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

Continuous integration builds have changed state:

Travis build 5404. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/581765188.
Appveyor build 5174. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_relax_ai_asserts-5174.

Revision history for this message
TiborB (tiborb95) wrote :

code looks OK

review: Approve
Revision history for this message
GunChleoc (gunchleoc) wrote :

Thanks for the review :)

@bunnybot merge

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/ai/ai_help_structs.cc'
--- src/ai/ai_help_structs.cc 2019-09-05 19:57:55 +0000
+++ src/ai/ai_help_structs.cc 2019-09-06 16:24:16 +0000
@@ -370,6 +370,24 @@
370 assert(!is(attribute));370 assert(!is(attribute));
371}371}
372372
373bool BuildingObserver::has_collected_map_resource() const {
374 return collected_map_resource != INVALID_INDEX;
375}
376void BuildingObserver::set_collected_map_resource(const Widelands::TribeDescr& tribe, const std::string& ware_name) {
377 if (!ware_name.empty()) {
378 collected_map_resource = tribe.safe_ware_index(ware_name);
379 } else {
380 collected_map_resource = Widelands::INVALID_INDEX;
381 }
382}
383DescriptionIndex BuildingObserver::get_collected_map_resource() const {
384 if (has_collected_map_resource()) {
385 return collected_map_resource;
386 } else {
387 throw wexception("Building '%s' needs to define the AI hint \"collects_ware_from_map\"", desc->name().c_str());
388 }
389}
390
373Widelands::AiModeBuildings BuildingObserver::aimode_limit_status() {391Widelands::AiModeBuildings BuildingObserver::aimode_limit_status() {
374 if (total_count() > cnt_limit_by_aimode) {392 if (total_count() > cnt_limit_by_aimode) {
375 return Widelands::AiModeBuildings::kLimitExceeded;393 return Widelands::AiModeBuildings::kLimitExceeded;
376394
=== modified file 'src/ai/ai_help_structs.h'
--- src/ai/ai_help_structs.h 2019-08-21 17:57:37 +0000
+++ src/ai/ai_help_structs.h 2019-09-06 16:24:16 +0000
@@ -449,6 +449,11 @@
449 void set_is(BuildingAttribute);449 void set_is(BuildingAttribute);
450 void unset_is(BuildingAttribute);450 void unset_is(BuildingAttribute);
451451
452 // Building collects a ware from the map
453 bool has_collected_map_resource() const;
454 void set_collected_map_resource(const TribeDescr& tribe, const std::string& ware_name);
455 DescriptionIndex get_collected_map_resource() const;
456
452 char const* name;457 char const* name;
453 Widelands::DescriptionIndex id;458 Widelands::DescriptionIndex id;
454 Widelands::BuildingDescr const* desc;459 Widelands::BuildingDescr const* desc;
@@ -486,14 +491,13 @@
486 int32_t substitutes_count;491 int32_t substitutes_count;
487492
488 std::set<DescriptionIndex> production_hints;493 std::set<DescriptionIndex> production_hints;
489 DescriptionIndex collected_map_resource;494
490 bool requires_supporters;495 bool requires_supporters;
491496
492 // information needed for decision on new building construction497 // information needed for decision on new building construction
493 int16_t initial_preciousness;498 int16_t initial_preciousness;
494 int16_t max_preciousness;499 int16_t max_preciousness;
495 int16_t max_needed_preciousness;500 int16_t max_needed_preciousness;
496
497 int32_t cnt_built;501 int32_t cnt_built;
498 int32_t cnt_under_construction;502 int32_t cnt_under_construction;
499 int32_t cnt_target; // number of buildings as target503 int32_t cnt_target; // number of buildings as target
@@ -513,6 +517,7 @@
513 bool build_material_shortage;517 bool build_material_shortage;
514518
515private:519private:
520 DescriptionIndex collected_map_resource;
516 std::set<BuildingAttribute> is_what;521 std::set<BuildingAttribute> is_what;
517};522};
518523
519524
=== modified file 'src/ai/defaultai.cc'
--- src/ai/defaultai.cc 2019-09-05 19:57:55 +0000
+++ src/ai/defaultai.cc 2019-09-06 16:24:16 +0000
@@ -647,11 +647,7 @@
647 bo.fighting_type = bh.is_fighting_type();647 bo.fighting_type = bh.is_fighting_type();
648 bo.mountain_conqueror = bh.is_mountain_conqueror();648 bo.mountain_conqueror = bh.is_mountain_conqueror();
649 bo.requires_supporters = bh.requires_supporters();649 bo.requires_supporters = bh.requires_supporters();
650 if (!bh.collects_ware_from_map().empty()) {650 bo.set_collected_map_resource(*tribe_, bh.collects_ware_from_map());
651 bo.collected_map_resource = tribe_->safe_ware_index(bh.collects_ware_from_map());
652 } else {
653 bo.collected_map_resource = INVALID_INDEX;
654 }
655 if (bo.requires_supporters) {651 if (bo.requires_supporters) {
656 log(" %d: %s strictly requires supporters\n", player_number(), bo.name);652 log(" %d: %s strictly requires supporters\n", player_number(), bo.name);
657 }653 }
@@ -898,7 +894,8 @@
898 assert(count_buildings_with_attribute(BuildingAttribute::kRanger) == 1);894 assert(count_buildings_with_attribute(BuildingAttribute::kRanger) == 1);
899 assert(count_buildings_with_attribute(BuildingAttribute::kWell) == 1);895 assert(count_buildings_with_attribute(BuildingAttribute::kWell) == 1);
900 assert(count_buildings_with_attribute(BuildingAttribute::kLumberjack) == 1);896 assert(count_buildings_with_attribute(BuildingAttribute::kLumberjack) == 1);
901 assert(count_buildings_with_attribute(BuildingAttribute::kHunter) == 1);897 assert((count_buildings_with_attribute(BuildingAttribute::kHunter) == 1) ||
898 (count_buildings_with_attribute(BuildingAttribute::kHunter) == 0));
902 assert(count_buildings_with_attribute(BuildingAttribute::kIronMine) >= 1);899 assert(count_buildings_with_attribute(BuildingAttribute::kIronMine) >= 1);
903 assert(count_buildings_with_attribute(BuildingAttribute::kFisher) == 1);900 assert(count_buildings_with_attribute(BuildingAttribute::kFisher) == 1);
904 // If there will be a tribe with more than 3 mines of the same type, just increase the number901 // If there will be a tribe with more than 3 mines of the same type, just increase the number
@@ -2707,8 +2704,7 @@
2707 prio += bo.primary_priority;2704 prio += bo.primary_priority;
27082705
2709 // keep wells more distant2706 // keep wells more distant
2710 assert(bo.collected_map_resource != INVALID_INDEX);2707 if (bf->collecting_producers_nearby.at(bo.get_collected_map_resource()) > 2) {
2711 if (bf->collecting_producers_nearby.at(bo.collected_map_resource) > 2) {
2712 continue;2708 continue;
2713 }2709 }
27142710
@@ -2737,10 +2733,9 @@
2737 (bf->trees_nearby - trees_nearby_treshold_) / 10;2733 (bf->trees_nearby - trees_nearby_treshold_) / 10;
27382734
2739 // consider cutters and rangers nearby2735 // consider cutters and rangers nearby
2740 assert(bo.collected_map_resource != INVALID_INDEX);2736 prio += 2 * bf->supporters_nearby.at(bo.get_collected_map_resource()) *
2741 prio += 2 * bf->supporters_nearby.at(bo.collected_map_resource) *
2742 std::abs(management_data.get_military_number_at(25));2737 std::abs(management_data.get_military_number_at(25));
2743 prio -= bf->collecting_producers_nearby.at(bo.collected_map_resource) *2738 prio -= bf->collecting_producers_nearby.at(bo.get_collected_map_resource()) *
2744 std::abs(management_data.get_military_number_at(36)) * 3;2739 std::abs(management_data.get_military_number_at(36)) * 3;
27452740
2746 } else if (bo.is(BuildingAttribute::kNeedsRocks)) {2741 } else if (bo.is(BuildingAttribute::kNeedsRocks)) {
@@ -2772,8 +2767,7 @@
2772 }2767 }
27732768
2774 // to prevent to many quaries on one spot2769 // to prevent to many quaries on one spot
2775 assert(bo.collected_map_resource != INVALID_INDEX);2770 prio = prio - 50 * bf->collecting_producers_nearby.at(bo.get_collected_map_resource());
2776 prio = prio - 50 * bf->collecting_producers_nearby.at(bo.collected_map_resource);
27772771
2778 } else if (bo.is(BuildingAttribute::kHunter)) {2772 } else if (bo.is(BuildingAttribute::kHunter)) {
27792773
@@ -2788,11 +2782,10 @@
2788 // Overdue priority here2782 // Overdue priority here
2789 prio += bo.primary_priority;2783 prio += bo.primary_priority;
27902784
2791 prio += bf->supporters_nearby.at(bo.collected_map_resource) * 5;2785 prio += bf->supporters_nearby.at(bo.get_collected_map_resource()) * 5;
27922786
2793 assert(bo.collected_map_resource != INVALID_INDEX);
2794 prio += (bf->critters_nearby * 3) - 8 -2787 prio += (bf->critters_nearby * 3) - 8 -
2795 5 * bf->collecting_producers_nearby.at(bo.collected_map_resource);2788 5 * bf->collecting_producers_nearby.at(bo.get_collected_map_resource());
27962789
2797 } else if (bo.is(BuildingAttribute::kFisher)) { // fisher2790 } else if (bo.is(BuildingAttribute::kFisher)) { // fisher
27982791
@@ -2807,9 +2800,8 @@
2807 // Overdue priority here2800 // Overdue priority here
2808 prio += bo.primary_priority;2801 prio += bo.primary_priority;
28092802
2810 assert(bo.collected_map_resource != INVALID_INDEX);2803 prio -= bf->collecting_producers_nearby.at(bo.get_collected_map_resource()) * 20;
2811 prio -= bf->collecting_producers_nearby.at(bo.collected_map_resource) * 20;2804 prio += bf->supporters_nearby.at(bo.get_collected_map_resource()) * 20;
2812 prio += bf->supporters_nearby.at(bo.collected_map_resource) * 20;
28132805
2814 prio += -5 + bf->fish_nearby *2806 prio += -5 + bf->fish_nearby *
2815 (1 + std::abs(management_data.get_military_number_at(63) / 15));2807 (1 + std::abs(management_data.get_military_number_at(63) / 15));
@@ -3036,7 +3028,7 @@
3036 std::abs(management_data.get_military_number_at(102)) / 5;3028 std::abs(management_data.get_military_number_at(102)) / 5;
3037 } else {3029 } else {
3038 // leave some free space between them3030 // leave some free space between them
3039 prio -= bf->collecting_producers_nearby.at(bo.collected_map_resource) *3031 prio -= bf->collecting_producers_nearby.at(bo.get_collected_map_resource()) *
3040 std::abs(management_data.get_military_number_at(108)) / 5;3032 std::abs(management_data.get_military_number_at(108)) / 5;
3041 }3033 }
30423034
@@ -6067,8 +6059,8 @@
6067 for (size_t i = 0; i < bo.ware_outputs.size(); ++i) {6059 for (size_t i = 0; i < bo.ware_outputs.size(); ++i) {
6068 ++field.producers_nearby.at(bo.ware_outputs.at(i));6060 ++field.producers_nearby.at(bo.ware_outputs.at(i));
6069 }6061 }
6070 if (bo.collected_map_resource != INVALID_INDEX) {6062 if (bo.has_collected_map_resource()) {
6071 ++field.collecting_producers_nearby.at(bo.collected_map_resource);6063 ++field.collecting_producers_nearby.at(bo.get_collected_map_resource());
6072 }6064 }
60736065
6074 if (!bo.production_hints.empty()) {6066 if (!bo.production_hints.empty()) {

Subscribers

People subscribed via source and target branches

to status/vote changes: