January 11, 2008

MUD!

Back in the early 90's I ran a computer BBS -- that's where someone spends thousands of dollars to let other people play with his computer. I ran a number of games like Tradewars 2002 , Global Wars, and Murder Motel where you had X number of moves to find a weapon, victim, and hiding spot. It was multi-one-player-at-a-time, but great fun. Joe and Bill Trebing took pity on some poor kid and invited them into their Tradewars corporation. The kid thanked them by activating the laser cannons, kicking them out of the company and into space, then blasting them to sparkley dust.

I wrote a chess game where people could play each other and some utilities like a message tosser that converted from RBBS format to TriBBS.

Last weekend I started writing a MUD in Python. It will be a text based game that you Telnet into. Yes, it's extremely retro but makes for an interesting geek project and, since I use a lot of Python at work, is a good way to brush up on my programming skills. And, unlike the old BBS games, this will be real multi-player.

At first, I was going to use a library called Twisted Matrix for networking but then decided to try writing the whole thing using only those libraries that come with Python 2.5.

The trick is to design it to be non-blocking. What is blocking, you ask? Imagine a restaurant with only one employee. He's the cook, waiter, busboy, dishwasher, and cashier. In walks Mr. Ficklehead who can never make up his mind. A blocking waiter has to stand there while Ficklehead reads the menu front to back. The food burns, the customers don't get seated, people run out on the check -- a mess.

A non-blocking waiter runs to every tables and goes, "Haveyoudecidedyet? No? That'soktakeyourtime, I'llbebackinasecond" and whoosh, moves on. Everything gets a split second of attention.

Another method is call multi-threading which would be like cloning yourself. That sounds good until your run into problems like telling three clones to wash the car, change the oil, and drive to the store for groceries. Keeping any two clones from flopping on the couch to watch reruns of Scrubs is just as tricky as it sounds. Besides, some of the Python libs are not thread safe to begin with.

So I'm going with single threaded asynchronous networking.

No comments: