April 19, 2004

CLI magic: let's Go!

Author: Joe Barr

I've heard the whimpering in the back. Some of you wimps think the command-line interface is just too hard. All work and no play, you say. Well, stifle that kind of talk, mister! Linux is (according to Torvalds) all about fun. And the CLI is no exception to that rule. This week we'll take a look at a console game just to prove that point. Ready? Let's Go.

According the the development history page, the first computer version of the game appeared in 1989 in a series of posts to comp.sources.games on USENET. The earliest version (1.2) of Gnu Go still available for download is from 1995. The current version (3.4) has been available since July of 2003. The game of Go itself is a little bit older, having originated in China 3 -- or possibly 4 -- thousand years ago.

Like chess, Go is about capturing territory and enemy. It's played on a matrix, usually 19 by 19. Turns are alternated between black and white, each placing a stone on an empty intersection. Enemy pieces are captured by surrounding them. When the board is filled in completely, the player with more stones left on the board wins. It's one of those devilish games which is easy to learn and impossible to master. And perfect for a programming exercise.

Installing the game

If you haven't installed Gnu software from source before, relax. It's a piece of cake. Just remember this mantra "./configure, make, and make install" and you'll be fine. Of course, your system needs to have the gcc compiler and the make program already installed before you begin.

Start by downloading the latest tarball from here. When that's finished, you'll have a file named gnugo-3.4.tar.gz sitting in your download directory. Remember our old friend tar? He'll melt that tarball for us if we ask him nicely. You can do that by entering this command:


tar xzf gnugo-3.4.tar.gz

The "xzf" arguments tell tar that we want him to extract the files - after unzipping them - from the file name immediately following the xzf. When tar is done, you'll have a new subdirectory in the directory you were in named "gnugo-3.4." Let's cd there and look around.

There are some important text files in the gnugo directory you'll want to read before going any further. The README and INSTALL files, for sure, Other file names in ALL CAPS are usually for your benefit, too.

I usually forget to take a look at configuration options before I start. That's bad practice I am trying to break myself from doing. Before running the configure script for real, enter "./configure --help" for a list of tunable parameters and options for the config. Don't be like me. Remember this important first step each time.

Once you've perused the options and noted any you might want to use, execute the configuration script for real by entering "./configure (plus any options you might need)". Normally the configuration script will uncover and alert you to any critical flaws - like missing dependencies and the like - before you go any further. As you watching all the "Checking..." lines generated by configure scroll down the screen, keep your fingers crossed that it doesn't find any.

When the configuration script has ended, it has created a custom Makefile for compiling and linking the program, based on your system and whatever options you may have requested. It's just sitting there waiting to be used. Use it now by entering "make".

When make has finished, and assuming it didn't run into any errors, you are ready to install the program. For this step, you need to superuser priveleges. After entering the "su" command and root password, enter the "make install" command. That's it. You've done it. Not bad for a noobie, noobie!

Would you like to play thermonuclear Go?

Unless the installation directory is not part of your PATH, you will now be able to start the game by typing "gnugo" at the command line. The default install directory is /usr/local/bin, by the way. If the response you get at the command line is "command not found," try entering the entire whole thing, like this:


/usr/local/bin/gnugo

Lots of lines will scroll by after gnugo starts, but the lines you are really interested in should be completely visible at the console. They look like this on my SUSE KDE Konsole:


Beginning ASCII mode game.

Board Size: 19
Handicap 0
Komi: 0.0
Move Number: 0
To Move: black
Computer player: White


    White (O) has captured 0 pieces
    Black (X) has captured 0 pieces

    A B C D E F G H J K L M N O P Q R S T
 19 . . . . . . . . . . . . . . . . . . . 19
 18 . . . . . . . . . . . . . . . . . . . 18
 17 . . . . . . . . . . . . . . . . . . . 17
 16 . . . + . . . . . + . . . . . + . . . 16
 15 . . . . . . . . . . . . . . . . . . . 15
 14 . . . . . . . . . . . . . . . . . . . 14
 13 . . . . . . . . . . . . . . . . . . . 13
 12 . . . . . . . . . . . . . . . . . . . 12
 11 . . . . . . . . . . . . . . . . . . . 11
 10 . . . + . . . . . + . . . . . + . . . 10
  9 . . . . . . . . . . . . . . . . . . .  9
  8 . . . . . . . . . . . . . . . . . . .  8
  7 . . . . . . . . . . . . . . . . . . .  7
  6 . . . . . . . . . . . . . . . . . . .  6
  5 . . . . . . . . . . . . . . . . . . .  5
  4 . . . + . . . . . + . . . . . + . . .  4
  3 . . . . . . . . . . . . . . . . . . .  3
  2 . . . . . . . . . . . . . . . . . . .  2
  1 . . . . . . . . . . . . . . . . . . .  1
    A B C D E F G H J K L M N O P Q R S T

black(1):

The blinking to the right of the black(1) above is your cue to enter a move. A move being a letter and a number representing an empty intersection on the grid. Each time you enter a move, the board is redrawn on the screen. It's also redrawn when the computer makes it play.

By the way, if the size of the board is intimidating to you, you can use the --boardsize option when you start the game to adjust it to any size you like between 5 and 21. According to man gnugo, 9 and 13 are popular sizes.

Don't feel bad if the Gnu Go beats you. It plays an excellent game. In fact it won the 19x19 tournament at the 8th Computer Olympiad last year by sweeping all ten games it played. Remember you can give yourself a handicap to level the board if Gnu Go is too rough on you.

If you are new to Go itself, there is a whole world of information about it on the web. But be careful, this is addicting. You may never go back to your GUI.

Click Here!