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

Proposed by TiborB
Status: Merged
Merged at revision: 8611
Proposed branch: lp:~widelands-dev/widelands/ai_blocked_cosideration
Merge into: lp:widelands
Diff against target: 65 lines (+19/-5)
1 file modified
src/ai/defaultai.cc (+19/-5)
To merge this branch: bzr merge lp:~widelands-dev/widelands/ai_blocked_cosideration
Reviewer Review Type Date Requested Status
GunChleoc Approve
Review via email: mp+339719@code.launchpad.net

Commit message

Based on my observation of AI training on McGregors Swamp, I decided to give an AI opportunity to ignore buildable fields (when scoring a buildable field) that are currently banned (on blocked_fields list). I specifically have in mind fields beyond a body of water that are mostly considered blocked, but AI still considers them a good direction to spread towards.

Description of the change

Based on my observation of AI training on McGregors Swamp I decided to give an AI opportunity to ignore buildable fields (when scoring a buildable field) that are currently banned (on blocked_fields list). I have in my mind specifically fields beyond a water, that are mostly considered blocked, but AI still consider them good direction to spread toward.
This branch itself is not enough, some training is needed afterwards, but this provides changes in C++ code... I will do train, once it is in trunk...

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

Continuous integration builds have changed state:

Travis build 3253. State: failed. Details: https://travis-ci.org/widelands/widelands/builds/346511218.
Appveyor build 3062. State: failed. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_ai_blocked_cosideration-3062.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Code LGTM. You managed to get some unprintable characters in there though:

/home/travis/build/widelands/widelands/src/ai/defaultai.cc:4905:4: error: stray ‘\302’ in program
    inputs[28] = (bo.total_count() > 0 && spots_ < kSpotsTooLittle ? -2 : 0;

etc.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 3258. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/346933690.
Appveyor build 3067. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_ai_blocked_cosideration-3067.

Revision history for this message
GunChleoc (gunchleoc) wrote :
Download full text (3.5 KiB)

I'm getting a stack-buffer-overflow when starting a new game on Fellowships with 3 normal AIs:

=================================================================
==22145==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fff62131050 at pc 0x0000015ccb20 bp 0x7fff62130950 sp 0x7fff62130940
WRITE of size 4 at 0x7fff62131050 thread T0
    #0 0x15ccb1f in DefaultAI::update_buildable_field(Widelands::BuildableField&) /home/bratzbert/sources/widelands/ai_blocked_cosideration/src/ai/defaultai.cc:1885
    #1 0x15c5d4b in DefaultAI::update_all_not_buildable_fields() /home/bratzbert/sources/widelands/ai_blocked_cosideration/src/ai/defaultai.cc:1245
    #2 0x15bd7e0 in DefaultAI::think() /home/bratzbert/sources/widelands/ai_blocked_cosideration/src/ai/defaultai.cc:341
    #3 0x1234e66 in GameHost::think() /home/bratzbert/sources/widelands/ai_blocked_cosideration/src/network/gamehost.cc:730
    #4 0xfc8741 in Widelands::Game::think() /home/bratzbert/sources/widelands/ai_blocked_cosideration/src/logic/game.cc:546
    #5 0x13d8160 in InteractiveBase::think() /home/bratzbert/sources/widelands/ai_blocked_cosideration/src/wui/interactive_base.cc:387
    #6 0x12ea477 in UI::Panel::do_think() /home/bratzbert/sources/widelands/ai_blocked_cosideration/src/ui_basic/panel.cc:455
    #7 0x12e886c in UI::Panel::do_run() /home/bratzbert/sources/widelands/ai_blocked_cosideration/src/ui_basic/panel.cc:181
    #8 0xddfdf9 in UI::Panel::Returncodes UI::Panel::run<UI::Panel::Returncodes>() /home/bratzbert/sources/widelands/ai_blocked_cosideration/src/ui_basic/panel.h:99
    #9 0xfc81d4 in Widelands::Game::run(UI::ProgressWindow*, Widelands::Game::StartGameType, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /home/bratzbert/sources/widelands/ai_blocked_cosideration/src/logic/game.cc:523
    #10 0x1233d42 in GameHost::run() /home/bratzbert/sources/widelands/ai_blocked_cosideration/src/network/gamehost.cc:672
    #11 0xdd2f60 in WLApplication::mainmenu_multiplayer() /home/bratzbert/sources/widelands/ai_blocked_cosideration/src/wlapplication.cc:1200
    #12 0xdd1fd6 in WLApplication::mainmenu() /home/bratzbert/sources/widelands/ai_blocked_cosideration/src/wlapplication.cc:1040
    #13 0xdcc902 in WLApplication::run() /home/bratzbert/sources/widelands/ai_blocked_cosideration/src/wlapplication.cc:439
    #14 0xdc9960 in main /home/bratzbert/sources/widelands/ai_blocked_cosideration/src/main.cc:49
    #15 0x7f62e043282f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
    #16 0xdc9828 in _start (/home/bratzbert/sources/widelands/ai_blocked_cosideration/widelands+0xdc9828)

Address 0x7fff62131050 is located in stack of thread T0 at offset 1264 in frame
    #0 0x15c5eef in DefaultAI::update_buildable_field(Widelands::BuildableField&) /home/bratzbert/sources/widelands/ai_blocked_cosideration/src/ai/defaultai.cc:1262

  This frame has 16 object(s):
    [32, 33) 'find_open_water'
    [96, 98) 'nearest_distance'
    [160, 162) 'actual_distance'
    [224, 228) 'unused1'
    [288, 296) 'find_water'
    [352, 368) 'find_unowned_wal...

Read more...

Revision history for this message
TiborB (tiborb95) wrote :

I apologize. I just compiled it without testing, now it works...

Revision history for this message
GunChleoc (gunchleoc) wrote :

I gave it a spin - it now only starts trying to build mines on those unreachable mountains in Fellowships once enough of it has been conquered long distance that the port space is visible.

I think the only thing helping there 100% of the time would be a test whether a road could be built to an existing flag, but that might be a bit expensive computing-wise.

@bunnybot merge

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/ai/defaultai.cc'
--- src/ai/defaultai.cc 2018-02-23 07:54:12 +0000
+++ src/ai/defaultai.cc 2018-02-28 22:32:16 +0000
@@ -1302,11 +1302,16 @@
1302 std::vector<Coords> found_buildable_fields;1302 std::vector<Coords> found_buildable_fields;
13031303
1304 // first looking for unowned buildable spots1304 // first looking for unowned buildable spots
1305 field.unowned_buildable_spots_nearby =1305 field.unowned_buildable_spots_nearby =
1306 map.find_fields(Area<FCoords>(field.coords, kBuildableSpotsCheckArea),1306 map.find_fields(Area<FCoords>(field.coords, kBuildableSpotsCheckArea),
1307 &found_buildable_fields, find_unowned_buildable);1307 &found_buildable_fields, find_unowned_buildable);
1308 // Now iterate over fields to get nearest one1308 // Now iterate over fields to collect statistics
1309 for (auto& coords : found_buildable_fields) {1309 for (auto& coords : found_buildable_fields) {
1310 // We are not interested in blocked fields
1311 if (blocked_fields.is_blocked(coords)) {
1312 continue;
1313 }
1314 // And now looking for nearest field
1310 const uint32_t cur_distance = map.calc_distance(coords, field.coords);1315 const uint32_t cur_distance = map.calc_distance(coords, field.coords);
1311 if (cur_distance < field.nearest_buildable_spot_nearby) {1316 if (cur_distance < field.nearest_buildable_spot_nearby) {
1312 field.nearest_buildable_spot_nearby = cur_distance;1317 field.nearest_buildable_spot_nearby = cur_distance;
@@ -1695,7 +1700,7 @@
1695 field.inland = true;1700 field.inland = true;
1696 }1701 }
16971702
1698 const uint8_t score_parts_size = 60;1703 const uint8_t score_parts_size = 64;
1699 int32_t score_parts[score_parts_size] = {0};1704 int32_t score_parts[score_parts_size] = {0};
1700 if (field.enemy_owned_land_nearby) {1705 if (field.enemy_owned_land_nearby) {
1701 score_parts[0] = 3 *1706 score_parts[0] = 3 *
@@ -1875,6 +1880,12 @@
1875 score_parts[59] = (field.unowned_portspace_vicinity_nearby) ?1880 score_parts[59] = (field.unowned_portspace_vicinity_nearby) ?
1876 10 * std::abs(management_data.get_military_number_at(31)) :1881 10 * std::abs(management_data.get_military_number_at(31)) :
1877 0;1882 0;
1883 score_parts[60] = 3 *
1884 management_data.neuron_pool[21].get_result_safe(
1885 20 - field.nearest_buildable_spot_nearby, kAbsValue);
1886 score_parts[61] = (field.nearest_buildable_spot_nearby < 8) ? std::abs(management_data.get_military_number_at(153) * 2) : 0;
1887 score_parts[62] = (field.nearest_buildable_spot_nearby > 20) ? -std::abs(management_data.get_military_number_at(154) * 2) : 0;
1888 score_parts[63] = (field.nearest_buildable_spot_nearby < 4) ? std::abs(management_data.get_military_number_at(155) * 2) : 0;
18781889
1879 for (uint16_t i = 0; i < score_parts_size; i++) {1890 for (uint16_t i = 0; i < score_parts_size; i++) {
1880 field.military_score_ += score_parts[i];1891 field.military_score_ += score_parts[i];
@@ -4890,7 +4901,10 @@
4890 inputs[24] = -5;4901 inputs[24] = -5;
4891 inputs[25] = (basic_economy_established) ? 1 : -1;4902 inputs[25] = (basic_economy_established) ? 1 : -1;
4892 inputs[26] = (basic_economy_established) ? 1 : -1;4903 inputs[26] = (basic_economy_established) ? 1 : -1;
48934904 inputs[27] = (bo.total_count() > 0 && spots_ < kSpotsEnough) ? -2 : 0;
4905 inputs[28] = (bo.total_count() > 0 && spots_ < kSpotsTooLittle) ? -2 : 0;
4906 inputs[29] = (spots_ < kSpotsEnough) ? -1 : 0;
4907 inputs[30] = (spots_ < kSpotsTooLittle) ? -1 : 0;
4894 int16_t tmp_score = 0;4908 int16_t tmp_score = 0;
4895 for (uint8_t i = 0; i < kFNeuronBitSize; ++i) {4909 for (uint8_t i = 0; i < kFNeuronBitSize; ++i) {
4896 if (management_data.f_neuron_pool[53].get_position(i)) {4910 if (management_data.f_neuron_pool[53].get_position(i)) {
@@ -4911,7 +4925,7 @@
4911 bo.max_needed_preciousness = 1;4925 bo.max_needed_preciousness = 1;
4912 }4926 }
4913 bo.primary_priority =4927 bo.primary_priority =
4914 1 + tmp_score * std::abs(management_data.get_military_number_at(137));4928 1 + tmp_score * std::abs(management_data.get_military_number_at(137) / 2);
4915 return BuildingNecessity::kNeeded;4929 return BuildingNecessity::kNeeded;
4916 }4930 }
4917 } else if (bo.is(BuildingAttribute::kLumberjack)) {4931 } else if (bo.is(BuildingAttribute::kLumberjack)) {

Subscribers

People subscribed via source and target branches

to status/vote changes: