Sunday, June 15, 2008

Alternative Uses for Version Control: Games

I am an avid player of Simcity 4. However when trying out a new strategy for developing a city, I find it much easier to plan out the development in stages, and save the cities between stages. Making backup copies of a city is a pain because each city file is stored in a region folder. You need to manually copy the file to a different location and rename it. Obviously, if you plan on backup up a city more than a few times during its development, this becomes a pain.

One solution I have been using recently is to place the region folder under version control using Mercurial. In fact, almost any version control tool would work in this situation. Simply add the cities you want to track, and make commits whenever you reach a point you want to preserve. If a few saves later you notice that your decision to build a prison in the middle of a high wealth residential zone is not quite working out, instead of destroying it and trying to improve the land value again, you can simply revert to an earlier revision. Here is an example using Mercurial:

[Create a new city within the game]
hg commit "City - TheCity.sc4" -m "Initial Commit."
[Play the city for a while, make a few saves]
hg commit "City - TheCity.sc4" -m "Basic residential, adding more industrial."
[Play the city for while]
[Massive air and water pollution...overall reduction in health...uh oh]
hg revert "City - TheCity.sc4"

This is an oversimplified example, but you get the idea. While this obviously does not promote realism in the development of a city, when trying out new techniques it can save you a lot of time and frustration. This idea is also applicable to other games that do not have some type of "save as" feature to back up progress.