← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/ai_parameters_tweak into lp:widelands

 

TiborB has proposed merging lp:~widelands-dev/widelands/ai_parameters_tweak into lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/ai_parameters_tweak/+merge/284667

This is only change of few numbers in defaultai.cc, I spent some time testing and observing AI so these are my tweaks to improve behavior a bit.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/ai_parameters_tweak into lp:widelands.
=== modified file 'src/ai/defaultai.cc'
--- src/ai/defaultai.cc	2016-01-24 17:01:59 +0000
+++ src/ai/defaultai.cc	2016-02-01 19:48:24 +0000
@@ -20,6 +20,7 @@
 #include "ai/defaultai.h"
 
 #include <algorithm>
+#include <cmath>
 #include <ctime>
 #include <memory>
 #include <queue>
@@ -1434,6 +1435,9 @@
 //   Currently more military buildings are built than needed
 //   and "optimization" (dismantling not needed buildings) is done afterwards
 bool DefaultAI::construct_building(uint32_t gametime) {
+	if (buildable_fields.empty()) {
+		return false;
+	}
 	// Just used for easy checking whether a mine or something else was built.
 	bool mine = false;
 	bool field_blocked = false;
@@ -1504,19 +1508,35 @@
 	highest_nonmil_prio_ = 0;
 
 	const bool too_many_ms_constructionsites =
-		(pow(msites_in_constr(), 2) > militarysites.size());
+		(pow(msites_in_constr(), 2) > militarysites.size() + 2);
 	const bool too_many_vacant_mil =
 		(vacant_mil_positions_ * 3 > static_cast<int32_t>(militarysites.size()));
-	const int32_t kUpperLimit = 275;
+	const int32_t kUpperLimit = 325;
 	const int32_t kBottomLimit = 40; // to prevent too dense militarysites
 	// modifying least_military_score_, down if more military sites are needed and vice versa
 	if (too_many_ms_constructionsites || too_many_vacant_mil || needs_boost_economy) {
-		if (persistent_data->least_military_score < kUpperLimit) { //no sense to let it grow too hight
-			persistent_data->least_military_score += 2;
+		if (persistent_data->least_military_score < kUpperLimit) { //no sense to let it grow too high
+			persistent_data->least_military_score += 20;
 		}
 	} else {
-		persistent_data->least_military_score -= 4;
-		// do not get bellow 100 if there is at least one ms in construction
+		// least_military_score is decreased, but depending on the size of territory
+		switch (static_cast<uint32_t>(log10(buildable_fields.size()))) {
+			case 0:
+				persistent_data->least_military_score -= 10;
+				break;
+			case 1:
+				persistent_data->least_military_score -= 8;
+				break;
+			case 2:
+				persistent_data->least_military_score -= 5;
+				break;
+			case 3:
+				persistent_data->least_military_score -= 3;
+				break;
+			default:
+				persistent_data->least_military_score -= 2;
+			}
+		// do not get bellow kBottomLimit if there is at least one ms in construction
 		if ((msites_in_constr() > 0 || too_many_vacant_mil)
 			&&
 			persistent_data->least_military_score < kBottomLimit) {
@@ -1528,7 +1548,7 @@
 	}
 
 	// This is effective score, falling down very quickly
-	if (persistent_data->target_military_score > 350) {
+	if (persistent_data->target_military_score > kUpperLimit + 150) {
 		persistent_data->target_military_score = 8 * persistent_data->target_military_score / 10;
 	} else {
 		persistent_data->target_military_score = 9 * persistent_data->target_military_score / 10;
@@ -1594,7 +1614,7 @@
 	if (spots_ == 0) {
 		resource_necessity_territory_ = 100;
 	} else {
-		resource_necessity_territory_ = 100 * 5 * (productionsites.size() + 5) / spots_;
+		resource_necessity_territory_ = 100 * 3 * (productionsites.size() + 5) / spots_;
 		resource_necessity_territory_ =
 		   (resource_necessity_territory_ > 100) ? 100 : resource_necessity_territory_;
 		resource_necessity_territory_ =
@@ -2123,7 +2143,7 @@
 					continue;
 				}
 
-				if (military_last_build_ > gametime - 10 * 1000) {
+				if (military_last_build_ > gametime - 15 * 1000) {
 					continue;
 				}
 
@@ -2151,7 +2171,7 @@
 				// additional bonus is added
 				if (bf->enemy_nearby_) {
 					prio += bf->military_loneliness_ / 3;
-					prio += (20 - bf->area_military_capacity_) * 25;
+					prio += (20 - bf->area_military_capacity_) * 10;
 					prio -= bo.build_material_shortage_  * 50;
 					prio -= (bf->military_in_constr_nearby_ + bf->military_unstationed_) * 50;
 				} else {
@@ -2166,7 +2186,7 @@
 				}
 				prio += bf->unowned_land_nearby_ * resource_necessity_territory_ / 100;
 				prio += bf->unowned_mines_spots_nearby_ * resource_necessity_mines_ / 100;
-				prio += ((bf->unowned_mines_spots_nearby_ > 0) ? 20 : 0) *
+				prio += ((bf->unowned_mines_spots_nearby_ > 0) ? 35 : 0) *
 						resource_necessity_mines_ / 100;
 				prio += bf->rocks_nearby_ / 2;
 				prio += bf->water_nearby_;
@@ -2637,7 +2657,7 @@
 
 	// if this is end flag (or sole building) or just randomly
 	if (flag.nr_of_roads() <= 1 || gametime % 10 == 0) {
-		create_shortcut_road(flag, 11, 20, gametime);
+		create_shortcut_road(flag, 13, 22, gametime);
 		inhibit_road_building_ = gametime + 800;
 		// a warehouse with 3 or less roads
 	} else if (is_warehouse && flag.nr_of_roads() <= 3) {


Follow ups