← Back to team overview

widelands-dev team mailing list archive

Re: [Merge] lp:~widelands-dev/widelands/bug-1718745-allows-seafaring into lp:widelands

 

See comment in the code

Diff comments:

> === modified file 'src/ai/defaultai.cc'
> --- src/ai/defaultai.cc	2017-11-26 17:43:25 +0000
> +++ src/ai/defaultai.cc	2017-12-02 11:42:21 +0000
> @@ -1950,11 +1950,9 @@
>  
>  	const Map& map = game().map();
>  
> -	if (gametime % 5 == 0) {
> -		// TODO(unknown): Counting port spaces is very primitive way for this
> -		// there should be better alternative f.e. like map::allows_seafaring()
> -		// function but simplier
> -		seafaring_economy = map.get_port_spaces().size() >= 2;
> +	// Checking for seafaring is a bit expensive, so we only do it once per second
> +	if (gametime % 1000 == 0) {
> +		seafaring_economy = map.allows_seafaring();

No, this is wrong. This function is called about once in 5 seconds, so adding probability 1/1000 means that it is barely called. I propose alternatives:
1. changing that to about 15
2. adding variable to AI that would keep the time when last time this was calculated and recalculate after x seconds only.
3. do something like that in "engine" - I mean cache the state and recalculate only after x seconds..

>  	}
>  
>  	for (int32_t i = 0; i < 4; ++i)


-- 
https://code.launchpad.net/~widelands-dev/widelands/bug-1718745-allows-seafaring/+merge/333233
Your team Widelands Developers is subscribed to branch lp:~widelands-dev/widelands/bug-1718745-allows-seafaring.


References