Civ4 Tech Tree Utility (new version)

grumbler

Prince
Joined
Oct 29, 2001
Messages
492
Location
In front of the screen
The Civ4 TTU computes possible and minimal paths for a given tech from the "CIV4TechInfos.xml" file. For the player of Civ4, this data can be useful to plan his research strategy. Also, it could be of some interest to the modder who wishes to analyze the consequences of his changes to the tech tree.

This is an improved version of a small python script I wrote prior to Civ4's release. Changes include bug fixes, improved performance, support for beaker costs and much more readable output formatting.

Also, tech data is now read directly from the game's XML file instead of a static data file; this way, TTU considers changes to the techtree and can be used to analyze modded tech trees.

You'll need to have Python installed to use the TTU. There's a readme included in the archive that explains everything you need to now about installation and use of this utility.

Download Civ4 TTU v0.5

Enjoy! :)



(Note to mods: I was unsure where to post this as it could be useful for both players and modders alike. If this was the wrong forum, please move this thread to the appropriate place.)
 
Why not just click on the tech in the tree in-game? That computes the fastest path and adds it to your queue.
 
warpstorm said:
Why not just click on the tech in the tree in-game? That computes the fastest path and adds it to your queue.
You don't necessarily want to have it added to your queue if you are just analyzing, do you?
 
warpstorm said:
Why not just click on the tech in the tree in-game? That computes the fastest path and adds it to your queue.

Sure, you could do it the easy way - but where's the fun in that? ;)

A more serious answer: For most people, the in-game functionality will probably be all they need. This displays the information in a different way and also offers some data not available in the game. For example, while it's true, that you can get the fastest path in-game by a simple mouse click, the game won't tell you about alternative research paths that are (nearly) equal in terms of beaker costs.

Also, you could use the TTU as a research tool to see how versatile the tech tree really is, something I find very difficult doing "by hand". If you're modding the tech tree, you could use TTU to monitor the results (without starting the game itself).

(Perhaps I should also add that part of the original motivation for this were a) having something to do until Civ4's release and b) familiarizing myself a bit with Python. I just thought maybe there are other people who could use something like this, so I posted it.)
 
This is a very useful util, Grumbler! :)

However, I would like you to have a look at the following possible bug...


I'm wondering if the program really calculates the shortest paths (minimum costs).

Let's take a simple example, Code of Laws, and its requirement, Writing. If you're wondering what the "{}" comes from, see my post scriptum.



civ4_techtree_util.py for 'Code of laws' said:
Minimal paths:

[0] Total cost: 800 beakers
Mysticism{50}->Meditation{80}->Priesthood{60}->Code of laws(Writing){350}.
Hunting{40}->Animal husbandry{100}->Writing{120}.

There are 20 paths to Code of laws.
Costs range from 800 to 1380 beakers. The number of minimal paths is 1.


civ4_techtree_util.py for 'Writing' said:
Minimal paths:

[2] Total cost: 260 beakers
Hunting{40}->Animal husbandry{100}->Writing{120}.


There are 6 paths to Writing.
Costs range from 260 to 330 beakers. The number of minimal paths is 1.

While that looks reasonable enough, you can actually get to Writing another way:

[0] Total cost: 310 beakers
Mysticism{50}->Meditation{80}->Priesthood{60}->Writing{120}.

Now, compare this path with that given above for reaching Code of Laws. You'll notice that at one time, you will already have researched the Mysticism{50}->Meditation{80}->Priesthood{60} part.

To me, instead of researching Hunting{40}->Animal husbandry{100} why not simply research Writing when you have researched Priesthood, which you need anyway for Code of Laws?

In other words, why not reseach the following, in order: Mysticism, Meditation, Priesthood, Writing, Code of Laws?

This would cost you 50+80+60+120+350=660 beakers, which is 140 beakers less than the minimum cost as presented by your program (and by Civ itself!). The savings of 140 beakers correspond nicely to the Hunting and Animal Husbandry techs (which you most definitely don't need for Code of Laws, I tested it in Civ myself).

It would seem the program (and the science advisor in Civ!) doesn't properly take into account subpaths which you might need for two separate goals.

In this case, the fastest way to both Writing and Code of Laws is Mysticism, Meditation, Priesthood; which you only need to research once but gain a benefit from twice.


Best regards,
Zapp


PS. To make it clearer which beaker costs the program is using I modified two lines of your program, to include the beaker cost of each tech within {}.

Here is the relevant section:
def getPathString(path):
s=''
subpaths=list()
for x in reversed(path):
if x=='#':
subpaths.append(s)
s=''
continue
elif s!='':
s='{'+str(ttree[x][0])+'}->'+s;
else:
s='{'+str(ttree[x][0])+'}.'


This is the original unmodified code as a comparison:
def getPathString(path):
s=''
subpaths=list()
for x in reversed(path):
if x=='#':
subpaths.append(s)
s=''
continue
elif s!='':
s='->'+s;
else:
s='.'
 
A more serious answer: For most people, the in-game functionality will probably be all they need. This displays the information in a different way and also offers some data not available in the game. For example, while it's true, that you can get the fastest path in-game by a simple mouse click, the game won't tell you about alternative research paths that are (nearly) equal in terms of beaker costs.
Also be aware that the in-game tool isn't better than the utility.

For example, Civilization IV itself will insist on you researching Animal Husbandry to reach Code of Laws*, which (as stated in my previous post) isn't needed at all.

*) I tried starting out as the Romans (which start with neither Hunting nor Mysticism, and clicking on Code of Laws. And sure enough, it starts reseaching Hunting for you. Which, again, you don't need, though it's still nice to have.
 
Lastly, as far as I can see, the reason for this bug is because you prune "identical subpaths".

The fastest way to CoL could be expressed as (using your program's notation, as modified by me):

Mysticism{50}->Meditation{80}->Priesthood{60}->Code of laws(Writing){350}.
Mysticism{50}->Meditation{80}->Priesthood{60}->Writing{120}.

As long as the program then realizes the real costs. Here's a suggested output:

Minimal paths:

[0] Total cost: 660 beakers
Mysticism{0*}->Meditation{0*}->Priesthood{0*}->Code of laws(Writing){350}.
Mysticism{50}->Meditation{80}->Priesthood{60}->Writing{120}.
*) zero cost, already researched.
How to go about writing Python code that does this, is a completely different matter - here I can't help you... :)
 
Back
Top Bottom