[Widelands-dev] [Merge] lp:~widelands-dev/widelands/bug-1810062-territorial-calculations into lp:widelands

2019-02-20 Thread bunnybot
Continuous integration builds have changed state:

Travis build 4501. State: passed. Details: 
https://travis-ci.org/widelands/widelands/builds/496123226.
Appveyor build 4288. State: success. Details: 
https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1810062_territorial_calculations-4288.
-- 
https://code.launchpad.net/~widelands-dev/widelands/bug-1810062-territorial-calculations/+merge/361366
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/bug-1810062-territorial-calculations.

___
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


[Widelands-dev] [Merge] lp:~widelands-dev/widelands/robust-file-saving into lp:widelands

2019-02-20 Thread bunnybot
Continuous integration builds have changed state:

Travis build 4498. State: errored. Details: 
https://travis-ci.org/widelands/widelands/builds/495915762.
Appveyor build 4285. State: success. Details: 
https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_robust_file_saving-4285.
-- 
https://code.launchpad.net/~widelands-dev/widelands/robust-file-saving/+merge/358718
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/robust-file-saving.

___
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


Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/bug-1810062-territorial-calculations into lp:widelands

2019-02-20 Thread Toni Förster
New calculations are up:

https://fosuta.org/pics/Territorial_Times_v4.ods

We are at least 50% faster in general. The fields are almost the same. Green 
Cells have 20 or less fields difference. Yellow 50. And red more than 50 (but 
these are only two maps). 
-- 
https://code.launchpad.net/~widelands-dev/widelands/bug-1810062-territorial-calculations/+merge/361366
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/bug-1810062-territorial-calculations.

___
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


Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/bug-1810062-territorial-calculations into lp:widelands

2019-02-20 Thread hessenfarmer
I am on a business trip until Friday so I can't do much other than check this 
side.
@Toni: In principle you are right in perhaps98% of the maps but there are 
cornercases where you might miss a special building spot which is needed to 
reach a somewhat hidden valley or a big mountain. So I believe as we need to 
put it in a coroutine anyway (23 secs is still too long) we could calculate the 
exact value. In any case many thanks for the values so as trunk is the 
benchmark for time we would struggle to achieve this.
@all: I just came to an idea how we could avoid the effect that Toni described 
and which is truly consuming. I can't test it until Friday though. 
-- 
https://code.launchpad.net/~widelands-dev/widelands/bug-1810062-territorial-calculations/+merge/361366
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/bug-1810062-territorial-calculations.

___
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


Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/bug-1810062-territorial-calculations into lp:widelands

2019-02-20 Thread Toni Förster
I pushed my tweak as revision 8986. I'm currently do some testing with all the 
maps and it looks promising. Will post an updated list later on.
-- 
https://code.launchpad.net/~widelands-dev/widelands/bug-1810062-territorial-calculations/+merge/361366
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/bug-1810062-territorial-calculations.

___
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


Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/bug-1810062-territorial-calculations into lp:widelands

2019-02-20 Thread Toni Förster
I think a found a good tweak. The main problem is the second for loop:

for idx, fg in ipairs(radius) do

Here we iterate through fields too many times. On a small map some million 
times.

I got Astoria 2.R down from 58 seconds to 23seconds. On some maps the 
calculated area is a little smaller(in Elven Forest 5 fields) but it is much 
faster. The idea is that with big and medium caps we can assume that the inner 
7 or 5 fields are always accessible, so we don't need to iterate to through 
them again and again.

I made my comments in the code.

Diff comments:

> === modified file 'data/scripting/win_conditions/territorial_functions.lua'
> --- data/scripting/win_conditions/territorial_functions.lua   2019-02-12 
> 17:30:21 +
> +++ data/scripting/win_conditions/territorial_functions.lua   2019-02-20 
> 16:25:30 +
> @@ -14,24 +14,77 @@
>  local wc_had_territory = _"%1$s had %2$3.0f%% of the land (%3$i of %4$i)."
>  
>  -- RST
> --- .. function:: get_buildable_fields()
> ---
> ---Collects all fields that are buildable
> ---
> ---:returns: a table with the map's buildable fields
> ---
> -function get_buildable_fields()
> -   local fields = {}
> -   local map = wl.Game().map
> -   for x=0, map.width-1 do
> -  for y=0, map.height-1 do
> - local f = map:get_field(x,y)
> - if f.buildable then
> -table.insert(fields, f)
> - end
> -  end
> -   end
> -   return fields
> +-- .. function:: get_valuable_fields()
> +--
> +--Collects all fields that are valuable
> +--
> +--:returns: a table with the map's valuable fields
> +--
> +function get_valuable_fields()
> +
> +   local result = {}
> +
> +   print_loading_message("Counting valuable fields took", function()
> +
> +  local fields = {}
> +  local check = {}
> +  local starttime = ticks()
> +  local map = wl.Game().map
> +  local plrs = wl.Game().players
> +
> +  -- Initialize with starting fields and port spaces
> +  for idx, player in ipairs(plrs) do
> + local sf = map.player_slots[idx].starting_field
> +  -- initialize the fields table and the check area with the regions 
> around the starting field of each Player
> + for idx, fg in ipairs(sf:region(9)) do
> +fields[fg.__hash] = fg
> +check[fg.__hash] = fg
> + end
> +  end
> +  if map.allows_seafaring == true then
> + -- add port spaces to the starting check area
> + for idx, spaces in ipairs(map.port_spaces) do
> +local f = map:get_field(spaces["x"],spaces["y"])
> +for idx, fg in ipairs(f:region(5)) do
> +   fields[fg.__hash] = fg
> +   check[fg.__hash] = fg
> +end
> + end
> +  end
> +
> +  -- Walk the map
> +  repeat
> + local no_new_fields = true
> + local new = {}
> + -- checking the check region for buildcaps and add fields that can 
> be conquered
> + for idx, f in pairs(check) do
> +local radius ={}
> +if f:has_max_caps("big") then
> +   radius = f:region(9)

radius = f:region(9,7)

> +elseif f:has_max_caps("medium") then
> +   radius = f:region(7)

radius = f:region(7,5)

> +elseif f:has_max_caps("small") then
> +   radius = f:region(5)
> +end
> +for idx, fg in ipairs(radius) do
> +   if check[fg.__hash] == nil and fields[fg.__hash] == nil and 
> fg:has_max_caps("walkable") then
> +  no_new_fields = false
> +  new[fg.__hash] = fg
> +  fields[fg.__hash] = fg
> +   end
> +end
> + end
> + check = new
> +  until no_new_fields
> +
> +  -- as our fields table is not continuosly indexed we need to build a 
> properly indexed table
> +  for idx,f in pairs(fields) do
> + table.insert(result, f)
> +  end
> +   end)
> +
> +   print(('We found %d valuable fields'):format(#result))
> +   return result
>  end
>  
>  -- RST


-- 
https://code.launchpad.net/~widelands-dev/widelands/bug-1810062-territorial-calculations/+merge/361366
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/bug-1810062-territorial-calculations.

___
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


Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/bug-1810062-territorial-calculations into lp:widelands

2019-02-20 Thread GunChleoc
Forget my last code tweak comment, I needed to look at this with code 
highlighting.

I have done some small tweaks to the code.

We should definitely stick this in a coroutine, because my screen will go black 
for a bit on Wide World, and my machine is fast.
-- 
https://code.launchpad.net/~widelands-dev/widelands/bug-1810062-territorial-calculations/+merge/361366
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/bug-1810062-territorial-calculations.

___
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


Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/bug-1810062-territorial-calculations into lp:widelands

2019-02-20 Thread Toni Förster
I guess the difference in size for some maps between 8975 and 8978 is the way 
port spaces are evaluated. That is the main difference between the 2 revisions.
-- 
https://code.launchpad.net/~widelands-dev/widelands/bug-1810062-territorial-calculations/+merge/361366
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/bug-1810062-territorial-calculations.

___
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


Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/bug-1810062-territorial-calculations into lp:widelands

2019-02-20 Thread Toni Förster
@hessenfarmer You're welcome. :D

https://fosuta.org/pics/Territorial_Times_trunk_r8975_r8978.ods

BTW. We shouldn't let us fool by the numbers, because they say nothing about 
the "quality" of the calculated fields. The fields calculated with r8978 are 
accurate while the ones in trunk are not.

I used the Release-Build on a Late 2013 MacBook Pro with a 2,4Ghz Intel Core i5 
(I5-4258U) 
-- 
https://code.launchpad.net/~widelands-dev/widelands/bug-1810062-territorial-calculations/+merge/361366
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/bug-1810062-territorial-calculations.

___
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


Re: [Widelands-dev] [Merge] lp:~widelands-dev/widelands/bug-1810062-territorial-calculations into lp:widelands

2019-02-20 Thread hessenfarmer
Update:
I continued to playtest trident of fire and I saw a volcano eruption and saw it 
vanish again. So I assume the script still works with the new hash value
-- 
https://code.launchpad.net/~widelands-dev/widelands/bug-1810062-territorial-calculations/+merge/361366
Your team Widelands Developers is subscribed to branch 
lp:~widelands-dev/widelands/bug-1810062-territorial-calculations.

___
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