Introduction

A Morabaraba program is conceptually quite simple. It has four main elements:

  • A way of representing a Morabaraba position in memory (referred to as the board representation)
  • A way of determining all of the valid moves for any given position (the move generator)
  • A (primitive) way of making an assessment of which side is winning in a given position (the static evaluator)
  • A way of using these components to seek out the best move to make in a given position (the search algorithm)

None of these elements is really that hard to create. Some of them are a bit fiddly to debug, but some of the reasons why the problem is interesting are as follows:

  • There is a real sense of mystery when a collection of simple, eminently-scrutable bits of code start playing a game with initiative and determination; it's quite a rush the first time you get thrashed by your program (unless you're a Morabaraba grandmaster, you can expect this moment to arrive surprisingly quickly!).
  • Each of these bits of code gets worked really hard. This means your code has to be really efficient - this type of intelligence is a feat of engineering, and the more you can wring out of that processor, the better. This is why so many Chess and Draughts programs are written in C or Assembly (or even implemented as special-purpose FPGAs or ASICs). A program that can burn through a million nodes per second has a big advantage over a program doing 100K nodes per second; the slower program will have trouble keeping up even if it shows superior understanding of the game.
  • The bits of code interact in mysterious, difficult to track ways. Debugging is a unique challenge; a tricky bug may stay submerged through several releases, only to scupper your program in its putative finest hour - and when you've found it you'll be amazed that your program ever got through a game.
  • There is an artistic balance to be struck between raw speed and expertise - and it can be difficult to ascribe behaviour to either one. The alphabeta algorithm allows a simple program to build expertise through its speed, while a subtle program may find correct answers more rapidly than a brutal number-cruncher. Ultimately, this balance is an expression of the character, interests and aspirations of the developer, and it is a key to the individual style of each program.

Which programming language should you use? It would be easiest to suggest that you should use something which is very familiar to you, as you will be doing ground-breaking work fairly early on. On the other hand, given the amount of time you're going to invest, choosing a language with the legs to be a contender is also wise: a work of art in an interpreted language will probably lose to a mediocre effort in a compiled language with a good interpreter, just because of the vast gulf in execution speed. I've written a few of these things, for various games in languages including C, Delphi, Visual Basic, C# (.NET), Java and even PHP and Clipper (can't say I really recommend those last two as good choices). Of all of these, I'd definitely recommend C, although I had good results in Delphi and C#. I'm not convinced that Java or C# can crank out the necessary computation to make a world-class contender - but I'd certainly love to be proved wrong; there may well be optimising compilers out there which can pare away the disadvantages. And, of course, I've seen a VB6 draughts program stomp on a C draughts program in a formal tournament - because it had fewer bugs in eval and time management.

Writing a Morabaraba program can be a great way to learn a new programming language, of course. You're unlikely to be up against hard deadlines, and you get to work on interesting problems with measurable results. The interesting bits are in the algorithm; having to go back to the book for syntax won't hold you up for long. My first serious C program was a chess program.

This Guide will discuss each of the key elements of a Morabaraba program, as well as providing practical advice based on hard-won experience (which really means endless hours of frustration) on how to setabout the creation of such a program. Even if you haven't been programming for long, it's a challenge which will provide you with real personal triumphs (and not a little geek kudos). If you're interested in perhaps writing a chess program, doing Morabaraba first will be an excellent warm-up - you can get results a lot quicker, but the same engineering ideas apply: almost everything you learn writing a Morabaraba program is directly useful for chess, draughts, othello and other two-player perfect information board games.