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

Commit message:
Tweaking scoring of AI performance, used for training of AI. No effect on 
gameplay altogether.

Requested reviews:
  Widelands Developers (widelands-dev)

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

Tweaking scoring of AI performance, used for training of AI. No effect on 
gameplay altogether. Main changes is in review() function that just print out a 
score with some details. Out of it I added just one variable 
first_iron_mine_built used only for the review function.
-- 
Your team Widelands Developers is requested to review the proposed merge of 
lp:~widelands-dev/widelands/ai_scoring_update into lp:widelands.
=== modified file 'src/ai/ai_help_structs.cc'
--- src/ai/ai_help_structs.cc	2018-04-06 08:14:17 +0000
+++ src/ai/ai_help_structs.cc	2018-04-07 19:32:15 +0000
@@ -565,33 +565,28 @@
                             const uint32_t old_land,
                             const uint16_t attackers,
                             const int16_t trained_soldiers,
-                            const int16_t latest_attackers,
-                            const uint16_t conq_ws,
                             const uint16_t strength,
-                            const uint32_t existing_ps) {
-
-	const int16_t main_bonus =
-	   ((static_cast<int32_t>(land - old_land) > 0 && land > max_e_land * 5 / 6 && attackers > 0 &&
-	     trained_soldiers > 0 && latest_attackers > 0) ?
-	       kBonus :
-	       0);
-
-	const int16_t land_delta_bonus = static_cast<int16_t>(land - old_land) * kLandDeltaMultiplier;
-
-	const uint32_t ps_sites_bonus = kPSitesRatioMultiplier * std::pow(existing_ps, 3) / 1000 / 1000;
-
-	score = land / kCurrentLandDivider + land_delta_bonus + main_bonus +
-	        attackers * kAttackersMultiplier + ((attackers > 0) ? kAttackBonus : -kAttackBonus) +
-	        trained_soldiers * kTrainedSoldiersScore + kConqueredWhBonus * conq_ws +
-	        strength * kStrengthMultiplier + ps_sites_bonus - 500 * kPSitesRatioMultiplier;
-
-	log(" %2d %s: reviewing AI mngm. data, sc: %5d Pr.p: %d (l:%4d/%s/%4d, "
-	    "at:%4d(%3d),ts:%4d/%2d,cWH:%2d,str:%2d/%4d,ps:%4d/%4d)\n",
-	    pn, gamestring_with_leading_zeros(gametime), score, primary_parent,
-	    land / kCurrentLandDivider, (main_bonus) ? "*" : " ", land_delta_bonus,
-	    attackers * kAttackersMultiplier, latest_attackers, trained_soldiers * kTrainedSoldiersScore,
-	    trained_soldiers, conq_ws, strength, strength * kStrengthMultiplier, existing_ps,
-	    ps_sites_bonus);
+                            const uint32_t existing_ps,
+                            const uint32_t first_iron_mine_time) {
+
+    // bonuses (1000 or nothing)
+    const uint16_t territory_bonus = (land > old_land || land > max_e_land) ? 1000 : 0;
+    const uint16_t iron_mine_bonus = (first_iron_mine_time < 2 * 60 * 60 * 1000) ? 1000 : 0;
+    const uint16_t attack_bonus = (attackers > 0) ? 1000 : 0;
+    const uint16_t training_bonus = (trained_soldiers > 0) ? 1000 : 0;
+
+	// scores (numbers dependant on performance)
+    const uint16_t land_score =  land / kCurrentLandDivider;
+    const uint16_t strength_score = std::min<uint16_t>(strength, 100) * kStrengthMultiplier;
+    const uint16_t attack_score = std::min<uint16_t>(attackers, 40) * 50;
+    const uint32_t ps_sites_score = kPSitesRatioMultiplier * std::pow(existing_ps, 3) / 1000 / 1000;
+
+    score = territory_bonus + iron_mine_bonus + attack_bonus + training_bonus + land_score + strength_score + ps_sites_score + attack_score;
+
+    log(" %2d %s: reviewing AI mngm. data, sc: %5d Pr.p: %d (Bonuses:Te:%s I:%s A:%s Tr:%s, Scores:Land:%5d Str:%4d PS:%4d, Att:%4d\n",
+    pn, gamestring_with_leading_zeros(gametime), score, primary_parent,
+    (territory_bonus)?"Y":"N", (iron_mine_bonus)?"Y":"N", (attack_bonus)?"Y":"N", (training_bonus)?"Y":"N",
+    land_score, strength_score, ps_sites_score, attack_score);
 
 	if (score < -10000 || score > 30000) {
 		log("%2d %s: reviewing AI mngm. data, score too extreme: %4d\n", pn,

=== modified file 'src/ai/ai_help_structs.h'
--- src/ai/ai_help_structs.h	2018-04-03 19:27:20 +0000
+++ src/ai/ai_help_structs.h	2018-04-07 19:32:15 +0000
@@ -678,10 +678,9 @@
 	            uint32_t old_land,
 	            uint16_t attackers,
 	            int16_t trained_soldiers,
-	            int16_t latest_attackers,
-	            uint16_t conq_ws,
 	            uint16_t strength,
-	            uint32_t existing_ps);
+	            uint32_t existing_ps,
+	            uint32_t first_iron_mine_time);
 	void dump_data(PlayerNumber);
 	uint16_t new_neuron_id() {
 		++next_neuron_id;

=== modified file 'src/ai/defaultai.cc'
--- src/ai/defaultai.cc	2018-04-02 08:44:26 +0000
+++ src/ai/defaultai.cc	2018-04-07 19:32:15 +0000
@@ -108,6 +108,7 @@
      next_mine_construction_due_(0),
      fishers_count_(0),
      bakeries_count_(),
+     first_iron_mine_built(50 * 60 * 60 * 1000),
      ts_finished_count_(0),
      ts_in_const_count_(0),
      ts_without_trainers_(0),
@@ -473,9 +474,9 @@
 				   gametime, player_number(), player_statistics.get_player_land(player_number()),
 				   player_statistics.get_enemies_max_land(),
 				   player_statistics.get_old60_player_land(player_number()), attackers_count_,
-				   soldier_trained_log.count(gametime), soldier_attacks_log.count(gametime),
-				   conquered_wh, player_statistics.get_player_power(player_number()),
-				   count_productionsites_without_buildings());
+				   soldier_trained_log.count(gametime), player_statistics.get_player_power(player_number()),
+				   count_productionsites_without_buildings(),
+				   first_iron_mine_built);
 				set_taskpool_task_time(
 				   gametime + kManagementUpdateInterval, SchedulerTaskId::kManagementUpdate);
 			}
@@ -6121,6 +6122,11 @@
 
 			set_inputs_to_zero(mines_.back());
 
+			// Is this first mine?
+			if (bo.mines == iron_resource_id && gametime < first_iron_mine_built) {
+				first_iron_mine_built = gametime;
+			}
+
 		} else if (bo.type == BuildingObserver::Type::kMilitarysite) {
 			militarysites.push_back(MilitarySiteObserver());
 			militarysites.back().site = &dynamic_cast<MilitarySite&>(b);

=== modified file 'src/ai/defaultai.h'
--- src/ai/defaultai.h	2018-03-27 09:10:21 +0000
+++ src/ai/defaultai.h	2018-04-07 19:32:15 +0000
@@ -352,6 +352,8 @@
 	uint16_t fishers_count_;
 	uint16_t bakeries_count_;
 
+	uint32_t first_iron_mine_built;
+
 	// for training sites per type
 	int16_t ts_finished_count_;
 	int16_t ts_in_const_count_;

_______________________________________________
Mailing list: https://launchpad.net/~widelands-dev
Post to     : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp

Reply via email to