Date: 2015-12-29 21:47:26

Gomoku BASIC ported to C

I have been thinking about game AI the last couple weeks, and since I've been working on a retro themed game for Coco 3, an old book on BASIC games came to mind; Tim Hartnell's Giant Book Of Computer Games. Tim was a self taught programmer and the author of several successful books on computer programming.

A few nights back I couldn't sleep, so I decided it would be relaxing to type in a program from Tim's book. My first choice was Reversi, but there was either an error in the printed source, or I miss-typed something and the program just wouldn't run. My second choice was Gomoku, which ran the first time I typed RUN. The game has a strong defensive AI, but not much on the offensive side. I'm thinking it would be fun to work on that part of the AI. But that's for another post.

Let me first say this isn't a competition between BASIC and C. They are very different languages. I have worked in, and love both languages. The C is a quick port. I wasn't trying to optimize it or anything. Just quick, straight port.

So I ported the BASIC version of Gomoku to C, and when I ran it, I was surprised, nay, blown away, by how much faster the game ran. I was expecting it to be faster, but I wasn't expecting the C program to be almost 23 times faster!

In the below table, I made the first move, and I timed how long the the computer took to make it's move. I was also running with the high speed poke, POKE &HFFD9,0 in BASIC (2MHz), but in C I left it in 1MHz mode.

Language Seconds
C 1.5

Have a look at this video. Makes me want to add a Semi-graphics UI to it. You are welcome to the source or just look at gomoku.bas or gomokuc.c.

Copyright © 2020, Lee Patterson