← Back to team overview

widelands-dev team mailing list archive

Re: [Merge] lp:~widelands-dev/widelands/ai_trainingsites_tweaks into lp:widelands

 

Review: Approve code

Code LGTM, just a few nits. this can go in once they have been fixed & Travis has passed.

Diff comments:

> 
> === modified file 'src/ai/defaultai.cc'
> --- src/ai/defaultai.cc	2016-02-08 17:25:17 +0000
> +++ src/ai/defaultai.cc	2016-02-09 11:02:50 +0000
> @@ -72,6 +72,7 @@
>  constexpr int kColonyScanMinArea = 10;
>  constexpr int kExpeditionMaxDuration = 90 * 60 * 1000;
>  constexpr uint32_t kNoShip = std::numeric_limits<uint32_t>::max();
> +constexpr uint32_t kNever = std::numeric_limits<uint32_t>::max();

We have a global function never() in Widelands somewhere, which you can use instead of defining your own kNever.

>  constexpr uint32_t kNoExpedition = 0;
>  
>  // this is intended for map developers, by default should be off
> @@ -4346,14 +4371,27 @@
>  				 =
>  				 (warequeues2[i]->get_max_fill() < 5) ? warequeues2[i]->get_max_fill() : 5;
>  				if (warequeues2[i]->get_filled() < required_amount) {
> -					supplied_enough = false;
> +					shortage += required_amount - warequeues2[i]->get_filled();
>  				}
>  			}
>  		}
>  
> -		if (supplied_enough) {
> +		// Has any soldier been trained up to now?
> +		if (gametime > 10 * 60 * 1000 && persistent_data->last_soldier_trained < gametime){
> +			if (persistent_data->last_soldier_trained + 10 * 60 * 1000 < gametime){

Add a space between ) and { in both lines.

> +				if (shortage <= 3) {
> +					game().send_player_change_soldier_capacity(*ts, 1);
> +				}
> +			} else {
> +				if (shortage <= 1) {
> +					game().send_player_change_soldier_capacity(*ts, 1);
> +				}
> +			}
> +		// or this can be very first soldier to be trained
> +		} else if (shortage <= 3) {
>  			game().send_player_change_soldier_capacity(*ts, 1);
>  		}
> +
>  	}
>  
>  	ts_without_trainers_ = 0;  // zeroing
> @@ -5420,6 +5460,52 @@
>  	// sites that were either conquered or destroyed
>  	std::vector<uint32_t> disappeared_sites;
>  
> +	// Willingness to attack depend on how long ago the last soldier has been trained. This is used as
> +	// indicator how busy our trainingsites are.
> +	// Moreover the stronger AI the more sensitive to it it is (a score of attack willingness is more
> +	// decreased if promotion of soldiers is stalled)
> +	int8_t training_score = 0;
> +	if (persistent_data->last_soldier_trained > gametime) {
> +		// No soldier was ever trained ...
> +		switch (type_) {
> +			case DefaultAI::Type::kNormal:
> +				training_score = -8;
> +				break;
> +			case DefaultAI::Type::kWeak:
> +				training_score = -4;
> +				break;
> +			default:
> +				training_score = -2;
> +			}
> +	} else if (persistent_data->last_soldier_trained + 10 * 60 * 1000 < gametime) {
> +		// was any soldier trained within last 10 minutes
> +		switch (type_) {
> +			case DefaultAI::Type::kNormal:
> +				training_score = -4;
> +				break;
> +			case DefaultAI::Type::kWeak:
> +				training_score = -2;
> +				break;
> +			default:
> +				training_score = -1;
> +			}
> +	}
> +	// Also we should have at least some training sites to be more willing to attack
> +	// Of course, very weak AI can have only one trainingsite so will be allways penalted by this

will be allways penalted => will always be penalized

> +	switch (ts_basic_count_ + ts_advanced_count_ - ts_without_trainers_) {
> +		case 0:
> +			training_score -= 6;
> +			break;
> +		case 1:
> +			training_score -= 3;
> +			break;
> +		case 2:
> +			training_score -= 1;
> +			break;
> +		default:
> +			;
> +	}
> +
>  	for (std::map<uint32_t, EnemySiteObserver>::iterator site = enemy_sites.begin();
>  	     site != enemy_sites.end();
>  	     ++site) {
> 
> === modified file 'src/ai/defaultai.h'
> --- src/ai/defaultai.h	2016-01-28 05:24:34 +0000
> +++ src/ai/defaultai.h	2016-02-09 11:02:50 +0000
> @@ -343,7 +343,7 @@
>  
>  	// this is a bunch of patterns that have to identify weapons and armors for input queues of trainingsites
>  	std::vector<std::string> const armors_and_weapons =
> -		{"ax", "lance", "armor", "helm", "lance", "trident", "tabard", "shield", "mask"};
> +		{"ax", "lance", "armor", "helm", "lance", "trident", "tabard", "shield", "mask", "spear"};

lance does not exist anymore, you can remove it.

>  
>  	enum {kReprioritize, kStopShipyard, kStapShipyard};
>  


-- 
https://code.launchpad.net/~widelands-dev/widelands/ai_trainingsites_tweaks/+merge/285459
Your team Widelands Developers is subscribed to branch lp:~widelands-dev/widelands/ai_trainingsites_tweaks.


References