...making Linux just a little more fun!

<-- prev | next -->

Running XBoard in Irssi

By Jason Creighton

The problem

Recently, I have been playing chess on FICS, a free service that uses the ICS (Internet Chess Server) protocol. ICS is a telnet protocol, so you can "telnet freechess.org 5000", login, and play with an ASCII chess board if you want Here is what FICS output looks like: (I made up most of this output as an example, but the actual output is in the same format.)

fics% 
Example shouts: This is an example shout
fics% 
--> Example of using the "it" command...like /me in IRC.
fics% 
Example(50): This is a chat message on channel 50.
fics% 
Example (1436) seeking 15 13 rated standard f ("play 61" to respond)
fics% obs 21
You are now observing game 21.
Game 21: GMKasparov (2804) GMAdams (2741) unrated standard 120 0

Game 21 (GMKasparov vs. GMAdams)

       ---------------------------------
    8  | *K|   |   |   | *R|   |   |   |     Move # : 29 (White)
       |---+---+---+---+---+---+---+---|
    7  |   | *P|   |   |   | Q |   |   |     Black Moves : 'hxg5    (0:00)'
       |---+---+---+---+---+---+---+---|
    6  | *P|   |   |   |   |   |   |   |
       |---+---+---+---+---+---+---+---|
    5  |   | *Q|   |   |   |   | *P|   |     Black Clock : 43:48
       |---+---+---+---+---+---+---+---|
    4  |   |   |   |   |   |   |   |   |     White Clock : 1:06:43
       |---+---+---+---+---+---+---+---|
    3  | P |   |   |   |   | P |   |   |     Black Strength : 17
       |---+---+---+---+---+---+---+---|
    2  |   | P |   |   |   |   | P |   |     White Strength : 18
       |---+---+---+---+---+---+---+---|
    1  |   | K |   |   |   |   |   | R |
       ---------------------------------
         a   b   c   d   e   f   g   h
fics% 

Now, you could play chess this way, if you don't mind using an ASCII chess board and entering all your moves manually, but most people use an interface program to provide them with a graphical chess board. I use XBoard for my graphical interface, which provides a nice board, but it directly passes the ICS output to stdin, and sends its stdout to the ICS. That is to say, you start xboard in an xterm, and it's almost as if you'd used telnet to connect except you have a graphical chess board. This isn't so bad, except:

The solution

Enter Irssi.

Irssi is the IRC client I use. Well, it's mostly an IRC client. There are modules for other protocols, such as ICQ.

I thought I could run XBoard in an Irssi window, filter out the prompts, and have more fun. It's possible, you just have to tweak things a little.

Configuring FICS

One problem with playing on FICS this way is that FICS will send a bell (i. e., the ASCII BEL character) when the board is updated, letting you know it's your move. However, they are sent without a newline, and since Irssi's exec module will only print complete lines, you don't hear the bell until the next newline, which could be with, for example, a chat message, which will come an indeterminate amount of time after the BEL is sent. So it's best to turn off bells on the FICS side with this command:

set bell off

This tells FICS not to send BEL characters on every board update.

Configuring XBoard

Having turned off server-side alerts, you probably want to hear some sort of sound when the opponent moves, but since just ringing the terminal bell won't work, you'll have to use a sound file. Here are my settings for XBoard in my .Xresources file:

# xboard options
XBoard*showCoords: True
XBoard*highlightLastMove: True
XBoard*colorizeMessages: True

# Sounds
XBoard*ringBellAfterMoves: True
XBoard*soundMove:       /home/jason/sounds/fanfare.wav
XBoard*soundChallenge:  /home/jason/sounds/bridge2.wav
XBoard*soundRequest:    /home/jason/sounds/bridge2.wav

# ICS-related
XBoard*internetChessServerHost: freechess.org
XBoard*internetChessServerHelper: timeseal
XBoard*internetChessServerLogonScript: /home/jason/chess/.logon-script-freechess.org

The above configuration (among other things) sets "fanfare.wav" to be played when the opponent moves and "bridge2.wav" to be played on either a "Challenge" (When you're challenged on ICS) or a "Request" (A request for something: draw, abort, adjourn, takeback, etc.) Note that, in order for XBoard to heed "soundMove", "ringBellAfterMoves" must be on.

Your configuration will differ, of course, and XBoard has scads of options, so please refer to the 'xboard' man page for a full list of supported sound events. (Among other things.)

When giving the names of sound files, you can also specify "$" as a filename to have XBoard emit a BEL character for that event. This is, of course, totally useless for the "soundMove" event for reasons discussed earlier, but every other event that XBoard sees involves something being printed, and thus Irssi will see the BEL in a timely manner.

Note that, in order for the ICS-related sound events to work, you must have 'colorizeMessages' enabled.

If you don't have some handy sound bites laying around, google for "free sound files". Just be careful not to spend too much time searching for suitable sounds, browsing site after site, staying up all night, with your skeletal frame leaning limply against your chair, the flickering light of your monitor casting a pale glow on your bloodshot eyes, your mailbox overflowing as your quest causes you to totally withdraw from society, becoming a sad, pathetic little vegetable whose only joy in life is finding those perfect sounds for every possible event.

Well, probably not, but you can spend a lot of time on it. :-)

Configuring Irssi

Irssi doesn't really require much tweaking. If you have XBoard beeping (i. e., you've specified "$" for one or more of XBoard's sounds), you'll want to "/set bell_beeps on" in order to have Irssi not ignore any BEL characters it sees. This is the alias I use:

/alias xboard window new hide; window name xboard; exec -name xboard -window -interactive \
xboard -ics -sgf ~/chess/fics.pgn | sed --unbuffered 's/^fics% //\;T\;/^\$/d'

Note that, in the alias, we have to quote ";" and "$", because those characters have special importance to Irssi. XBoard is started in ICS mode, appending any games played to ~/chess/fics.pgn. The 'sed' command (which filters out the FICS prompt) is a little more complex, so I'll take the easy way out and not attempt to explain it in detail. The irrepressibly curious can refer to the 'sed' man page.

And that's all there is to it. You could, of course, use a different ICS interface such as eboard, but I prefer XBoard, and this configuration works for me.

I have used "FICS" to refer to the chess server throughout this article because that's what I use, but this should work with most any ICS, provided you modify the 'sed' incantation appropriately.

 


[BIO] Jason is a high school student who installed his first distribution, Slackware, in late 2002. Since then, he's joined the Answer Gang, switched to CRUX and still can't seem to see an interesting piece of technology without wondering how it works, and, in those rare cases when it actually belongs to him or someone foolish enough to lend it, tinkering endlessly with it.

Copyright © 2005, Jason Creighton. Released under the Open Publication license unless otherwise noted in the body of the article. Linux Gazette is not produced, sponsored, or endorsed by its prior host, SSC, Inc.

Published in Issue 112 of Linux Gazette, March 2005

<-- prev | next -->
Tux