Currently Online

Latest Posts

Topic: suggestions for improving the economy

fk
Avatar
Topic Opener
Joined: 2013-07-30, 21:58
Posts: 151
Ranking
At home in WL-forums
Posted at: 2015-03-30, 13:00

Segmentating the map and connecting economies to regions:

An optimized way to achieve this is by scanning the map for owned fields and place this in an RLC (run length code) table. An RLC is most suitable for this, it is compact and it can be processed quickly. Now this RLC can be scanned from top to bottom for connected regions that are placed in respective RLC's. Once this has been achieved the RLC's can be merged together, if needed, as for example for every 'V' shape. This also requires parts of the top line to be connected to the bottom line, if owned by the same player, as well as the left and right border of the map. The result is that every separate region is placed in a separate RLC. It is very easy to map these resulting RLC's into field vectors. As a last step the economies have to be connected to the regions. This can be achieved by traversing the economies and map their first warehouses into one region.

If there are routines available to sort this out than the regions could be further split when they are divided by f.e. water, lava or swamps. But also without this refinement it would enable multiple start locations and make computations for the economy much easier.


Top Quote
tuggyne

Joined: 2011-07-21, 23:27
Posts: 42
Ranking
Pry about Widelands
Location: TN
Posted at: 2015-03-30, 20:37

I feel like I'm missing some context here. Can you expand on the use case for multiple start locations or whatever rather a lot more as an opening?


Top Quote
Tibor

Joined: 2009-03-23, 22:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2015-03-30, 20:42

This looks like interesting idea but probably bit hard to implement. You understand that such regions would be very fluid. Every time there is new constructionsite - not connected yet - placed, there is new economy (shortliving though) and this would need to have own region I think. Similarly an outstretched and unconnected military site - compact territory (with mother economy), but in fact a separate economy and probably separate region consequently.

But from AI standpoint it would solve another issue that is "do not build buildings on places where they cannot be connected to a road network with a warehouse (~economy)"


Top Quote
fk
Avatar
Topic Opener
Joined: 2013-07-30, 21:58
Posts: 151
Ranking
At home in WL-forums
Posted at: 2015-03-31, 08:23

tuggyne wrote:

Can you expand on the use case for multiple start locations or whatever rather a lot more as an opening?

I used multiple start location as an example. It should work for any economy that is divided over multiple regions, both from start (scenario's) and during the battle (disconnected areas). It should answer the question: economy A needs a sawery, but where is economy A?

Tibor

Thanks for calling it interesting, and I admit that it is not easy. I know this procedure from real-time digital image processing and I have already some (self written) stuff with RLC's, but it should be adapted.

there is new economy (shortliving though)

I will think this over.

But from AI standpoint it would solve another issue that is "do not build buildings on places where they cannot be connected to a road network with a warehouse (~economy)"

Yes, that is the objective.

Edited: 2015-03-31, 08:25

Top Quote
einstein13
Avatar
Joined: 2013-07-28, 23:01
Posts: 1118
Ranking
One Elder of Players
Location: Poland
Posted at: 2015-03-31, 10:57

@fk:

I was reading your first post for several times and didn't understand most of things (lots of shortcuts there).

First of all it was RLC or RLE (more common). Why do you want to use that compression mode? I understand that it can be useful, but for me it will be very CPU-consuming: making the table and compress it. You have to do it every time you are calling for economy status (or whatever you are looking for here).

fk wrote:

economy A needs a sawery, but where is economy A?

I would find easier way to answer the question face-wink.png

Simpliest way is to create common table, fill in with buildings number, take any warehouse and check connections to any other buildings. If all other buildings can't connect any more- go for another warehouse and set another economy name.

ID Building Economy
1 Headquater - 1 1
2 Woodcutter - 1 1
3 Sawmill - 1 1
4 Warehouse - 1 1
5 Port - 1 2
6 Gold Mine - 1 2
7 Tower - 1 2
8 Tower - 2 Null

On that situation you have economy "1" with Headquater, Woodcutter, Sawmill and one warehouse. Second economy is on the island with Port, Gold mine and Tower. Last "economy" is unconnected, almost conquered Tower. Making that table should be almost as CPU-consumig as your idea. And you don't use any RLE methods. Memory here is not very important. We have tones of GB now face-wink.png

If there is lots of "Null" values, you can try to make any building of that unconnected part of economy and try to link that part (conquering, just linking, whatever)


einstein13
calculations & maps packages: http://wuatek.no-ip.org/~rak/widelands/
backup website files: http://kartezjusz.ddns.net/upload/widelands/

Top Quote
Tibor

Joined: 2009-03-23, 22:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2015-03-31, 21:25

two points:

  1. economies are "connected" per definition - also ports + ships counts for "connected"
  2. logic of economies is processed well in the core of widelands. In every instant you can say where (in what economy) a building is.

So to create a map of regions per economy would need just query economy of flag/building and pass that information to nearby fields and also keep updating this information. This could be done manually in AI but would be too expensive as I would do it per field and have to update this information very frequently


Top Quote
einstein13
Avatar
Joined: 2013-07-28, 23:01
Posts: 1118
Ranking
One Elder of Players
Location: Poland
Posted at: 2015-03-31, 22:24

Tibor wrote:

to update this information

Is it possible to save any additional data to the AI? Some kind of state, maybe next step to do or something?


einstein13
calculations & maps packages: http://wuatek.no-ip.org/~rak/widelands/
backup website files: http://kartezjusz.ddns.net/upload/widelands/

Top Quote
Tibor

Joined: 2009-03-23, 22:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2015-03-31, 23:01

einstein13 wrote:

Tibor wrote:

to update this information

Is it possible to save any additional data to the AI? Some kind of state, maybe next step to do or something?

Definitelly, and it is done very intensivelly. Only problem is that these data does not survive save/load cycle... Statistics, info about buildable fields, info about enemysites...


Top Quote
einstein13
Avatar
Joined: 2013-07-28, 23:01
Posts: 1118
Ranking
One Elder of Players
Location: Poland
Posted at: 2015-03-31, 23:13

Tibor wrote:

Definitelly,

So you can make "Very smart AI" which will design his strategy? I mean at the beggining of the game it will make complex calculations about strategy, pick the best and stick to it?

I know that the idea IS complex, but you can imagine that in current AI model?

Statistics, info about buildable fields, info about enemysites...

Is this surviving or not?

I guess that general statistics are surviving- I can open them after reloading.


einstein13
calculations & maps packages: http://wuatek.no-ip.org/~rak/widelands/
backup website files: http://kartezjusz.ddns.net/upload/widelands/

Top Quote
fk
Avatar
Topic Opener
Joined: 2013-07-30, 21:58
Posts: 151
Ranking
At home in WL-forums
Posted at: 2015-04-01, 12:34

einstein13 wrote:

First of all it was RLC or RLE (more common). Why do you want to use that compression mode? I understand that it can be useful, but for me it will be very CPU-consuming

Too start with, both terms are used. About the reason for compression: Instead of parsing whole rows of the map it only needs to compare a few values. Most rows will consist of 2, 4 or perhaps 6 values. So it actually saves a lot of CPU cycles. What is more important is how many times the data will have to be constructed this way and I don't know WL well enough to make an estimation.

On that situation you have economy "1" with Headquater, Woodcutter, Sawmill and one warehouse.

My suggestion applies to a routine that decides about the next building that the AI wants to build. You don't have a woodcutter but you want to build a woodcutter. Since it is not yet there it has no location and no economy.

Tibor

So to create a map of regions per economy would need just query economy of flag/building and pass that information to nearby fields and also keep updating this information.

It should at least be updated when a field is conquered or lost. I have no idea how that is handled right now and how often, and, on the other hand, what will be the ramifications of my suggestion. I can't say in advance how the CPU-load is going to work out. If the construct building routine becomes more effective it could perhaps be called a fewer times, and perhaps also the rest of the AI analyse- and decision making.

Edited: 2015-04-01, 12:51

Top Quote