.com.unity Forums

.com.unity Forums (http://forum.shrapnelgames.com/index.php)
-   Dominions 2: The Ascension Wars (http://forum.shrapnelgames.com/forumdisplay.php?f=55)
-   -   Random map files and annotations: Python (http://forum.shrapnelgames.com/showthread.php?t=19373)

nakomus June 15th, 2004 03:23 AM

Random map files and annotations: Python
 
A while back I posted in a thread about Gandalf’s random map generator; I commented that I had tried writing a similar program in Python but failed. Soon after I reattempted the problem, and was successful in generating simple random opponents.

I was also thinking about the semi-random map idea and what one would need to be able to do to make semi-believable random maps. In order for a program to modify the map file in a believable way I concluded it really ought to have an model of the world internally, based on the information in the mapfile.

Anyway, the point is I have a I have Python code that reads in a mapfile and extracts province numbers, terrain types, and neighbors. Each province is an object with terrain and connection data associated with. Human and AI player information is in another object.

I can form provinces into lists or unordered sets pretty easily and work with them; for example, I could look at the set of provinces with the water terrain flag to see if the map has enough water provinces to allow water nations as AIs.

Currently I have two problems:
1) It doesn’t really do anything. I can pull all this information out of the map file, but I don’t have any real great idea for what to DO with it after that.

2) Its not packaged for distribution, I call use it from an interactive python session. It wouldn’t be too hard to make it into a script that could be called from the command line with arguments once I can do more than just make random opponents; although the odds of seeing a standalone executable in the near future is poor.

So what I’m wondering is, what should I do with all this map information? (I could parse more map commands if it was interesting, also). I can do things like #nostart provinces that don’t have enough (or too many) neighbors. With a bit of work I could assign the AI and/or human starting provinces (this would be nation-specific) and guarantee that no one starts right next to someone else.

Going back to the semi-random-maps discussion, is anyone making armies or army/site combinations that could be dropped into a map file?

I know Gandalf and Lief(spelling?) have there own map-randomizers. I’m not sure how what I’m doing overlaps with what you are doing;

My impression from Poke in The Eye and family at least, is that those generators are not very context-aware, putting randomly generated troops in provinces where they will drown, for example.

SO: What sort of things would you like to be able to do based on terrain and neighbors? What level of interest is there?

If Anyone is interested, I can email you a copy of code although its not terribly user friendly at this point.

Pirateiam June 15th, 2004 03:36 AM

Re: Random map files and annotations: Python
 
Actually I am trying to teach myself Python right now and would be interested in looking at your code. As long as you do not mind me possibly using some of it. I do have a few questions about Python. Do you reccomend any references for someone to help learn Python? What is the execution speed comparable to? What cross-platforms have you used with success? Sorry for the questions but I am inquisitive by nature. I will PM you my e-mail if you allow me to look at your code. Thanks

nakomus June 15th, 2004 05:32 AM

Re: Random map files and annotations: Python
 
The number-one and only real reference I can suggest is the documentation section on python.org, the tutorial is quite good and the Library Reference has a lot of information. That’s what I personally used learning the language.

Pure Python code’s execution speed is generally poor, its fully interpreted and does not compile to native code. If performance is a serious problem there are several solutions. The first is to rewrite the program’s hotspots in C; Python is implemented in C and can easily integrate modules and functions from C to improve performance. In fact there are some automated tools to make python wrappers for C libraries. I’ve never extended tried to do this so I can’t comment much.

The other solution to performance issues is to use the excellent support libraries which are generally in C. For example, the Numerical Python libraries provide matrix and array operations if you need to do serious number crunching and are generally very fast.

Most of the code I’ve written runs faster than I can notice anyway.

I have used Python under Linux (Debian, Slackware, Red Hat) and Windows (98, XP). Python has been ported to a pretty wide variety of systems, I would not expect that would be a problem.


Quote:

Originally posted by Pirateiam:
... I do have a few questions about Python. Do you reccomend any references for someone to help learn Python? What is the execution speed comparable to? What cross-platforms have you used with success? ...
<font size="2" face="sans-serif, arial, verdana">

Pirateiam June 15th, 2004 04:17 PM

Re: Random map files and annotations: Python
 
Thanks for the reply nakomus! I am currently in the middle of the tutorial. Thanks

Gandalf Parker June 15th, 2004 07:19 PM

Re: Random map files and annotations: Python
 
@Nakomus:
Well, if you take a look at some more of my stuff which is semi popular (www.dom2minions.com) you might get an idea as to how your gathering info from the map file will allow a program to do what I do, but better. http://forum.shrapnelgames.com/images/icons/icon7.gif

Such as.... I randomly scatter castles and monsters across the map. The result is land castles in water, water castles on land. Same with monsters which drown as soon as you attack the province.

If you paired your program gathering info about a map, with one which maintains the same info for castles, natives, monsters, sites, pre-made interesting provinces, province names based on terrain (woods, water, mountain, island, swamp).... then doing a BETTER random program might be very interesting.

[ June 15, 2004, 18:21: Message edited by: Gandalf Parker ]

PvK June 15th, 2004 11:23 PM

Re: Random map files and annotations: Python
 
My co-worker Jeff offers:

There appears to be a new edition of O'Reilly's "Learning Python", that is update for Python 2.3. http://www.oreilly.com/catalog/lpython2/

Overstock.com seems to have the best price
http://www.overstock.com/cgi-bin/d2....PROD_ID=625685

Gandalf Parker June 16th, 2004 02:19 AM

Re: Random map files and annotations: Python
 
I have shelves and shelves of OReilly books. I dont recommend them for learning. On any new subject I get a yellow "for Dummies" book first. Those are great books. Even if all it does is convince me that I already knew more than I thought on the subject its a good start. (never get the orange "for Idiots" books)

In-between, a SAMs book is good for learning. QUE is great. WAITE is abit heavy but good.

OReilly you get Last. In my opinion its alot of help but only if you already know the subject. Plus its impressive on the bookshelf for those who know what an OReilly book is. http://forum.shrapnelgames.com/images/icons/icon7.gif

PvK June 16th, 2004 02:41 AM

Re: Random map files and annotations: Python
 
You could use the tutorial on the web at first, and a book like the O'Reilly for a reference and to figure out more details.

PvK

Gandalf Parker June 16th, 2004 04:18 PM

Re: Random map files and annotations: Python
 
This is a FUN site. Anyone who has more than one programming language, or wants to, can have a good time here.
http://www.99-bottles-of-beer.net/

It shows the code for doing that song in 621 different programming Languages. It does alot in my opinion toward showing the difference between the efficient/good/marketable Languages and the ones that I can actually learn to produce something with now. http://forum.shrapnelgames.com/images/icons/icon7.gif

PvK June 16th, 2004 05:12 PM

Re: Random map files and annotations: Python
 
Hehe. Interesting.

By the way, another friend recommends a different Python book, although he says it is further in the serious/reference direction rather than the learning direction. There is still the good web tutorial, though:

My pal Paul wrote:
Quote:

IMO the 'Learning Python' book is not as good as the 'Programming Python' book. As the title suggests, the learning book is more of an introduction to Python whereas the programming book provides a deeper and broader coverage. I'd spend the bucks for the 'Programming Python' book. There's a second edition of it out too, although it looks like it covers only Python 2.0.
<font size="2" face="sans-serif, arial, verdana">PvK


All times are GMT -4. The time now is 12:13 PM.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©1999 - 2025, Shrapnel Games, Inc. - All Rights Reserved.