One of the TaviPatches, this macro generates a visual display of a chess board in your wiki. Note that the chess board patch will probably never be integrated into the main codebase, since it it's a bit frivolous for most installations. Still, it's a cool demonstration of the potential for macros.

To implement a chessboard macro for 'Tavi, you need to do the following:

  1. Download all png files from http://tavi.sourceforge.net/chess/. Alternatively, create your own according to the same naming convention. Place them in a web location of your choosing.
  2. Create the file chess.php and place it on your web server. Contents listed below.
  3. Edit the file parse/transforms.php to require('some location/chess.php') at the beginning of the file.
  4. Edit the file config.php; add a line to the $ViewMacroEngine array that looks like: "'C' => 'view_macro_chess'".
    Note: in tavi-0.22 the $ViewMacroEngine array is defined in the lib/defaults.php file. And my guess is that the require('some location/chess.php') would go in parse/macros.php.
    --(Matt Hicks)?
  5. Invoke the macro like this:
    [[C rbnqkbnr]]
    [[C pppppppp]]
    [[C ........]]
    [[C ........]]
    [[C ........]]
    [[C ....P...]]
    [[C PPPP.PPP]]
    [[C RNBQKBNR]]

Presto! You're done. Aah, the power of macros. :-) Enjoy.

Go-moku, checkers, and other games are left as an exercise for the reader.


chess.php

<?php
$ChessImageBase = 'http://someplace.org/wiki/chess_images/';

function view_macro_chess($text)
{
  static $square_color = 1;

  $rtn = '';
  for($i = 0; $i < strlen($text); $i++)
  {
    switch($text[$i])
    {
      case 'K': $rtn = $rtn . chess_square('wk', $square_color); break;
      case 'Q': $rtn = $rtn . chess_square('wq', $square_color); break;
      case 'R': $rtn = $rtn . chess_square('wr', $square_color); break;
      case 'B': $rtn = $rtn . chess_square('wb', $square_color); break;
      case 'N': $rtn = $rtn . chess_square('wn', $square_color); break;
      case 'P': $rtn = $rtn . chess_square('wp', $square_color); break;
      case 'k': $rtn = $rtn . chess_square('bk', $square_color); break;
      case 'q': $rtn = $rtn . chess_square('bq', $square_color); break;
      case 'r': $rtn = $rtn . chess_square('br', $square_color); break;
      case 'b': $rtn = $rtn . chess_square('bb', $square_color); break;
      case 'n': $rtn = $rtn . chess_square('bn', $square_color); break;
      case 'p': $rtn = $rtn . chess_square('bp', $square_color); break;
      default:  $rtn = $rtn . chess_square('',   $square_color); break;
    }
    $square_color = !$square_color;
  }

  $square_color = !$square_color;       // Start next line with same color.

  $rtn = $rtn . html_newline();
  return $rtn;
}

function chess_square($piece, $color)
{
  global $ChessImageBase;

  return '<img src="' . $ChessImageBase . $piece .
         ($color == 0 ? 'd' : 'l') . '.png" width="33" height="33" />';
}

?>