Dyego Maas - Blog

Generative AI Consultant and Software Architect

Updating the most influential book of the BASIC era

Updating the most influential book of the BASIC era

In this post, I introduce the project to update the BASIC Computer Games book to new programming languages, explain how to take part, and share some of my experience porting the game Life to C#.

5 min read

BASIC Computer Games is considered one of the most influential books of its time. It was the first programming book to sell more than 1 million copies, and there was a time when more copies of the book sat in libraries than there were computers able to run BASIC.

In the 1970s and 1980s, programming magazines printed a whole series of programs that you then had to type into a computer to run. It was a pretty cool concept: DIY gaming.

Page 101, scanned from BASIC Computer Games, containing the LIFE program
Page from the book BASIC Computer Games, with the game Life

The Project

The book’s games are now being updated to modern programming languages, to preserve a piece of computing history and make them more accessible. This is happening through an open source project organized by Jeff Atwood, co-founder of StackOverflow, and described in detail in the post Updating The Single Most Influential Book of the BASIC Era.

The article is super interesting and gives the project a lot of rich historical context. And since it’s an open source project, you can contribute too.

How to contribute

The games are being updated to the languages at the top of the TIOBE February 2021 index that are considered memory safe and general-purpose scripting languages:

  • Java
  • Python
  • C#
  • VB.NET
  • JavaScript
  • Ruby
  • Delphi / Object Pascal
  • Perl

If you know any of these languages, you can contribute too. I imagine a few other languages might be accepted, but you’d have to ask (it’s an open source project, after all).

Picking a game to port

The first thing to do (after reading the article, of course) is to go to the repository and find a game that hasn’t been ported yet to a language you know well.

In my case, I chose to port game 55 on the list, Life, to C#.

Luckily, you won’t need to transcribe the BASIC code from the magazine, since that’s already been done. By the way, the book’s content is available on the Atari Archives site, and you can download the full book here.

The next step is to set up your local environment.

Setting up the BASIC environment

Around 2009, Lyle Kopnicky normalized all the code for Vintage BASIC. That makes our lives easier, since the tool is easy to install and run on Windows, Linux, and MacOS.

Vintage BASIC is a BASIC interpreter written in Haskell, and it behaves much like the Commodore 64’s BASIC.

The project site has a very thorough User’s Guide that you can read in about an hour.

Once it’s installed, you can run a BASIC program from your terminal like this: vintbas myprogram.bas.

Forking the project

To contribute, you’ll first need to fork the project repository on GitHub.

If you’re new to the world of open source projects, the GitHub docs show in detail how to fork a repository.

Converting to another language

This is the fun part, and it’s up to you. Keep in mind, though, that this is a port and not simply a new version. So it’s important to reproduce the original’s behavior as faithfully as possible.

Dica

To test your port, you can open two terminals: in the first, run the original game with Vintage BASIC; in the second, run yours. If everything is right, the output should be the same.

Pull Request

Once you’re happy with your port, just open a Pull Request against the original repository. I ended up opening two, because I found a few bugs in my first implementation.

My contribution: Life in C#

I picked game 55 in the book, called LIFE, and decided to port it to C#. I spent about a day and a half of my vacation on the port. That included studying BASIC, understanding the original program, writing my port, and fixing a ton of bugs.

Why I chose Life

I chose Life specifically because I already admired it. Known as Conway’s Game of Life, it’s a cellular automaton simulation created by John Conway in 1970. From a set of simple rules, complex behaviors emerge. Later, Stephen Wolfram studied cellular automata in more depth, publishing a series of papers that culminated in his book A New Kind of Science, published in 2002.

More recently, Stephen Wolfram has been working on a unified model of physics rooted in these same concepts. The theory proposes a computational model of the universe, and you can learn more about it here.

Visual summary of the Wolfram Physics Project, presenting the concept of Ruliads
Visual summary of the Wolfram Physics Project

If your curiosity is piqued, you can learn more about the project on Lex Fridman’s podcast:

Porting the game to C#

Porting Life to C# was more fun than I expected. The hardest part of the project was making the port’s simulation faithful to the original.

Since BASIC arrays are indexed from 1 instead of 0, as in Java or C#, the original program had several hard-coded values that complicated the conversion. A few mistakes while adjusting the indexes led to subtle differences in the simulation after a few dozen iterations.

Because of the changes I had to make to the indexing, the first implementation worked, but only until some cell reached the edges of the simulation. From that point on, the port’s simulation evolved completely differently from the original.

After a few hours of testing, I finally managed to fix it and reach a satisfying result:

You can find the code here.