Hello Visitor! Login or Sign Up

Elite Text Trading in Python

And now for something completely different...

This so emphatically isn't the place to put this but I'm in a spring-cleaning mood and I just have to get this off my computer and out of my mind. So I give you..

pytxtelite.py - A python port of Ian Bell's original C Text Based Elite Trading.


Memories. I still remember my BBC Model B computer with great fondness and a large part of that fondness was Elite. In it's day Elite was a revolution, a whole new genre of game. I never made it to Elite but I was at least Deadly (which frankly I thought was a lot cooler). I stumbled across Ian Bells pages one day when gripped by nostalgia and took a look at his text based elite trading program. I played with it a little doing some short trading runs. Then I took a look at the C code.

I hate C code.

I especially hate C code that is a thin port of Assembly Code. Not because I am some kind of hot-shot programmer who knows better but exactly because I am a programmer who knows his limitations. Those limitations include (but are not limited to) an inability to think in hexadecimal and to visualize the effect of bit-shifting and masking on numbers. Sure, I can work it out, but I can't THINK in it and that makes the process slow going.

So I ported it to Python (2.5, maybe earlier, your mileage will vary based on how much tinkering you want to do). I ported it to Python partly because it looked like an interesting challenge and partly because I thought it would be interesting to be able to do stuff to the Elite universe. Stuff that I would have loved to do when I was 14 like, hmm...

  • Write a program that would wander the elite universe trading and making me Rich! RICH!
  • Draw maps of the universe highlighting all the anarchic planets (you know, to plan my Elite "shoot a pirate" holidays)
  • List out all the goatsoup strings for all the planets (there's a small bug in my version of goatsoup by the way)
  • Mess with the economic model of Elite so that goods replenish more slowly or quickly at planets

What is it good for?

About as much as Ian Bells original text elite trading game. You can travel between the planets trading stuff and building your fortune but there are no graphics, missions, combat, mis-jumps or death through inept docking maneuver.

But you can also use it for all the things I mentioned before - documenting and tweaking the elite universe. It has a command line interface based on the Cmd class (thanks Doug for the excellent pyMOTW covering Cmd) but beneath that there is a TradingGame class that you should be able to drive programmatically for your own nefarious ends.

Bugs & Limitations

Ian Bells compiled version of txtelite.exe uses a random number generator that I don't have access to. When I compile his C code with LCC it uses a different random number generator. This affects only the fluctuations of commodity quantities and pricing. I was able to track down a generator for python that matches the LCC version but not for whatever his compiler uses. In Ian's latest txtelite version (1.3+) he provides an alternate platform independent random number generator which I include and activate as the default but some of the trading scripts provided on his site won't work with the commodity fluctuations that the new random number generator provides.

There is also a small bug in the goat-soup code for random names, due I think to the way C handles addressing items outside of arrays (e.g. array length is 10, you ask for the 13th item) but it's small and doesn't spoil the fun.

There may be other bugs floating in the code. Elite was built on ancient microcomputers like the 6502 in the BBC Micro. It depends on a lot of bit twiddling and the quirks of C types. Python doesn't have the same quirks so some subtle uses of over or underflow might have been missed.

What now?

There were a bunch of things I thought about doing to the game but decided against it. I wanted to build a model of the Elite universe in something more malleable (to me) than C, not create a new game from the trading engine of Elite.

If you do something interesting with it (including improving it) please post in the comments below.

Good luck Commander!


© 2006 - 2013 Automatic Romantic | Terms of Use | Privacy Policy | Developer Blog

Web Design Inspired by Andreas Viklund Some icons by Mark James