View Single Post
  #10  
Old June 6th, 2005, 12:21 PM

The_Paladin The_Paladin is offline
Private
 
Join Date: Jul 2004
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
The_Paladin is on a distinguished road
Default Re: New Map Utils For Dom2

My utils have no GUI component at the moment (and probably never will since they are quite a few options especially in the later two that would prove extremely time consuming to guify). Also since the functions I use are Windows console functions they are essentially all old DOS routine type stuff that is emulated or has equivalents under Linux / Unix (like printf, fopen). So I don't see OS compatibility as being a problem.

To Endoperez, Gandalf and anyone else who is interested I would be happy to help if I can with your projects. For anyone else who does not care about programming please feel free to skip this - you have been forewarned .

About Java - I do know Java though I don't much care for it... Its very similar to C++ though just lacks the performance I need for my RL work. I would hesitate to use an applet for the reason you have suggested - the massive download and for the operations you need they are fairly portable from machine to machine unless you are intending to provide a GUI component in which case then yeah there will be some issues with compatibility.

Its been a while now but I believe if you use regular interpreted Java you can often embed a small version of the interpreter inside the executable. Depending on how fancy the functions are you use, the required interpreter is often small enough to offer downloads with. I believe also that MS's J++ or Borland's... something or other that escapes me... they allow you to create a Intel compiled version as opposed to an interpreted version. I remember doing that once. That should allow your program to run on anything save Macs. You might not want to shell out the large dollars though for J++. Worse case scenario though most simple Windows-based Java programs can be readily converted to C++ with only changing the entrypoint function and a few function calls. Before I start rambling too much though I better move on.

The readme.txt file gives a little more info as to how I formed the blocks but in more detail essentially Gandalf is mostly right. I use arrays of two structure types, Province and Nation, which contain:

Province:
TerrainType
Available
NeighbourArray

Nation:
TerrainType
OwnedProvinces

Procedure:

1) Create an array of provinces by reading in the #terrain statements from the .MAP file. That also allows me to detect their type so the water nations can be put below the sea. I set the terrain type and available flags in the province structure appropriately.

2) Search again the .MAP file (technically this is done within step 1 but for clarity I separated them) for #neighbour statements. For each such statement, add the neighbour province to the other province's NeighbourArray. For example if the statement was #neighbour 3 12, province 3's neighbour array structure would add province 12 and province 12's structure would add province 3.

3) For each nation participating on the map, I randomly choose a province (generate a random number and choose it). I make sure the nation's terrain preference matches the selected province (water for water, land for land) and if so add that to a list (or array) of the nation's owned provinces. Within the province structure, I now set the available flag to false. If not just repeat until a match is found.

4-a) Again for each nation create a list of current neighbours to the owned provinces. This is the key to forming the blocks. That is accomplished by examining the current list of owned provinces the current nation and forming a master list of all potential neighbours. For each owned province, all members of their individual neighbour list are added to the master list. Essentially it is the union of the owned province's neighbour sets. Duplicates are fine as I will deal with them later.

4-b) Taking the master neighbour list, randomly (random number) choose a province amongst them. If that province is available (i.e. its flag indicates that it is), then add it to owned province list and mark it as unavailable. If not repeat step 4-b until a province can be assigned. Once a province is assigned return to 4-a until all additional provinces are assigned for that nation. Then repeat for all other nations.

That's it essentially. I've left out some details that would detract from the point but essentially this is it. Oh and about duplicates in the master neighbour list. I like them as they occur only if more than one owned province neighbour the same un-owned province. That encourages creating blocks of provinces as opposed to a snake like shape. And its ok to add provinces to that list that are already owned by someone, as the available flag will not be set.

I think this should answer your question but if its not clear just let me know. Sorry for the math / programming - I'm a grad student in the middle of writing my PhD thesis so I'm kind of used to writing like this these days.
__________________
-Paladin
Reply With Quote