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
1=== modified file 'src/ai/defaultai.cc'
2--- src/ai/defaultai.cc 2018-02-23 07:54:12 +0000
3+++ src/ai/defaultai.cc 2018-02-28 22:32:16 +0000
4@@ -1302,11 +1302,16 @@
5 std::vector<Coords> found_buildable_fields;
6
7 // first looking for unowned buildable spots
8- field.unowned_buildable_spots_nearby =
9+ field.unowned_buildable_spots_nearby =
10 map.find_fields(Area<FCoords>(field.coords, kBuildableSpotsCheckArea),
11 &found_buildable_fields, find_unowned_buildable);
12- // Now iterate over fields to get nearest one
13+ // Now iterate over fields to collect statistics
14 for (auto& coords : found_buildable_fields) {
15+ // We are not interested in blocked fields
16+ if (blocked_fields.is_blocked(coords)) {
17+ continue;
18+ }
19+ // And now looking for nearest field
20 const uint32_t cur_distance = map.calc_distance(coords, field.coords);
21 if (cur_distance < field.nearest_buildable_spot_nearby) {
22 field.nearest_buildable_spot_nearby = cur_distance;
23@@ -1695,7 +1700,7 @@
24 field.inland = true;
25 }
26
27- const uint8_t score_parts_size = 60;
28+ const uint8_t score_parts_size = 64;
29 int32_t score_parts[score_parts_size] = {0};
30 if (field.enemy_owned_land_nearby) {
31 score_parts[0] = 3 *
32@@ -1875,6 +1880,12 @@
33 score_parts[59] = (field.unowned_portspace_vicinity_nearby) ?
34 10 * std::abs(management_data.get_military_number_at(31)) :
35 0;
36+ score_parts[60] = 3 *
37+ management_data.neuron_pool[21].get_result_safe(
38+ 20 - field.nearest_buildable_spot_nearby, kAbsValue);
39+ score_parts[61] = (field.nearest_buildable_spot_nearby < 8) ? std::abs(management_data.get_military_number_at(153) * 2) : 0;
40+ score_parts[62] = (field.nearest_buildable_spot_nearby > 20) ? -std::abs(management_data.get_military_number_at(154) * 2) : 0;
41+ score_parts[63] = (field.nearest_buildable_spot_nearby < 4) ? std::abs(management_data.get_military_number_at(155) * 2) : 0;
42
43 for (uint16_t i = 0; i < score_parts_size; i++) {
44 field.military_score_ += score_parts[i];
45@@ -4890,7 +4901,10 @@
46 inputs[24] = -5;
47 inputs[25] = (basic_economy_established) ? 1 : -1;
48 inputs[26] = (basic_economy_established) ? 1 : -1;
49-
50+ inputs[27] = (bo.total_count() > 0 && spots_ < kSpotsEnough) ? -2 : 0;
51+ inputs[28] = (bo.total_count() > 0 && spots_ < kSpotsTooLittle) ? -2 : 0;
52+ inputs[29] = (spots_ < kSpotsEnough) ? -1 : 0;
53+ inputs[30] = (spots_ < kSpotsTooLittle) ? -1 : 0;
54 int16_t tmp_score = 0;
55 for (uint8_t i = 0; i < kFNeuronBitSize; ++i) {
56 if (management_data.f_neuron_pool[53].get_position(i)) {
57@@ -4911,7 +4925,7 @@
58 bo.max_needed_preciousness = 1;
59 }
60 bo.primary_priority =
61- 1 + tmp_score * std::abs(management_data.get_military_number_at(137));
62+ 1 + tmp_score * std::abs(management_data.get_military_number_at(137) / 2);
63 return BuildingNecessity::kNeeded;
64 }
65 } else if (bo.is(BuildingAttribute::kLumberjack)) {

Subscribers

People subscribed via source and target branches

to status/vote changes: