Recent Topics

1 Aug 04, 2007 02:39    

Chessboard render plugin

Description

Chessboard render is a plugin for B2evolution blogs that converts FEN notation or an alternative 8×8-layout to a chessdiagram using XHTML with 8×8 images.

About

This plugin is made by vyvy at http://www.vyvy.org/. Originally he made a plugin for B2evo 0.9, but it was soon forgotten because it was not compatible with 1.6. Vyvy made ports for [url=http://drupal.org/]Drupal[/url] (can't find it anymore on that site) and Michael Arlt for [url=http://wiki.splitbrain.org/plugin:chessdiagram]DokuWiki[/url]. The plugin is based on replacement code in chessboard_render.php, a nice piece of programming skill. I made some minor changes. This is my second attempt getting it to work on B2evo. Now I succeeded. My motivation was the underlying code. It opens possibilities for look alikes like checkers and even card games.

Explanation

The plugin uses [url=http://en.wikipedia.org/wiki/Forsyth-Edwards_Notation]FEN syntax[/url] to describe a chess position. FEN stands for Forsyth-Edwards Notation. This is an example:

[chessboard]
# Byrne - Fisher (1956) Game of the Century
(BTRL)
r3r1k1/pp3pbp/1qp1x1p1/2B5/2BP2b1/Q1n2N2/P4PPP/3R1K1R
[/chessboard]

The numbers are empty squares, the letters represent pieces in English (King, Queen, Rook, Bisshop, Night, Pawn). Upper case letters are for the white pieces. Notation starts at a8 (upper left corner). The code in brackets is optional. This tells us to render borders at the Bottom, Top, Right and Left (all four). Comments are made on a line starting #.

This board may also have been described using an easier to understand 8x8 syntax. You use whatever suits you best.

[chessboard]
# Byrne - Fisher (1956) Game of the Century
(BTLR)
r---r-k-
pp---pbp
-qp-x-p-
--B-----
--BP--b-
Q-n--N--
P----PPP
---R-K-R
[/chessboard]

This is what it looks like when rendered:

http://www.blog.hemminga.net/media/blogs/plugins/chessboard1.png

Byrne - Fisher (1956) Black plays 17. ..., Be6 (x marks the spot), while the queen is hanging on b6. Not only does Fisher win, it is also shown it is the only move that doesn't loose in this position.

By playing with the options you can make subsets of the board. (TR4l) creats a four column board with two borders, Top and Right. The starting piece Top Left is white. We now have the top right corner of the board. If we inject:

r-k-
-pbp
x-p-
----

We get:

http://www.blog.hemminga.net/media/blogs/plugins/chessboard2.png

Notice that I added four rows in the code. If I added more rows, the table would have gotten larger but not wider.

Syntax

[chessboard]

Parameters (flags)

T -> Border Top (default: no border)
B -> Border Bottom
L -> Border Left
R -> Border Right
[1..8] -> Number of colums (default = 8)
l -> Starting with a light square (default)
d -> Starting with a dark square

Pieces - use lowercase for black and uppercase for white

P / p -> Pawn
R / r -> Rook
N / n -> Knight
B / b -> Bishop
Q / q -> Queen
K / k -> King
x -> empty square with X
- or [1..8] -> empty square

Lay out

You can make a different set of images. You need to give them the same filename though. If you keep this set in a different folder, you can enable this new set by pointing to the new map (change path) in the edit section of the plugin.
If you need to layout the images, the all have the same class attribute: chessboard. In your css you can call them through:

img.chessboard{
border: 0;
}

Licence

The code for chessboard_render.php is licenced under GNU [url=http://www.gnu.org/licenses/gpl.html]GPL2[/url].

Download

[url=http://www.blog.hemminga.net/media/blogs/plugins/chessboard_render_plugin.zip]Version 2.1 beta[/url]: Stable, added image path options. Needs testing for functions and errors. Tested in B2evo 1.8.7, 1.9.3, 1.10.2 & 2.0 a.
Version 2.0 alpha: Working and stable, not completed.

Install

Download the zipfile, open it and place it in the ../blog/plugins/ folder. It should now show in the backoffice (Global settings -> Plugins) Click Install new and choose Chessboard render. Now click the edit button or the link in the name to go to the control panel of the plugin. Here you can change the path setting.

Support

If you have questions or find some unexpected behaviour, post in the Plugins & Extentions section of the B2evolution forum. I will take it on from there.
If for whatever reason I changed some code and forgot to update this reader, this is the [url=http://www.blog.hemminga.net/plugins.php/2007/08/04/title-1]entry in my blog about this plugin[/url]. You can leave a comment there if you wish.

Final remarks

I hope I get at least a few serious downloads and people actually using it and writing in there blogs about chess. If not, that's fine with me too. I enjoyed (re-)writing the plugin and learned some interesting stuff. B2evolution rules.


Form is loading...