Run Length Encoded

From LifeWiki
Revision as of 04:02, 22 December 2008 by Nathaniel (talk | contribs)
Jump to navigation Jump to search

The Run Length Encoded (or RLE for short) file format is well-suited for storing large patterns. It is more cryptic than some other file formats such as plaintext and Life 1.06, but is still quite readable.

Description of format

The first line is a header line, which has the form

x = m, y = n

where m and n are the width and height of the pattern, respectively. The pattern itself begins on the next line and is encoded as a sequence if items of the form <run_count><tag>, where <run_count> is the number of occurrences of <tag> and <tag> is one of the following three characters:

<tag> description
b dead cell
o alive cell
$ end of line

<run_count> can be omitted if it is equal to 1. The last <run_count><tag> item is followed by a ! character. Dead cells at the end of a pattern line do not need to be encoded, nor does the end of the last line of the pattern. Whitespace is permitted between <run_count><tag> items (and between the last <run_count><tag> item and the following !), but except for carriage returns and line feeds this is not recommended. It is not permitted to place whitespace in the middle of a <run_count><tag> item.

Lines in the RLE file must not exceed 70 characters, although it's a good idea for RLE readers to be able to cope with longer lines. DOS, Unix and Mac newline conventions are all acceptable.

Anything after the final ! is ignored. It used to be common to put comments here (starting on a new line), but the usual method for adding comments is now by means of #C lines (see below).

Additional features

The header line may be preceded by any number of lines beginning with the # character. The # character is followed by a letter indicating the type of information that line provides. These letters generally follow the conventions for XLife files, which are described in the file xlife.man in the XLife distribution. Here is a list of letters likely to be encountered in practice:

letter description
C Indicates that a line of comment follows. This is the only really common use of # lines.
Example: #C 'Twas brillig and the slithy toves
c Same as C, but not recommended.
O Says when and by whom the file was created. RLE files produced by XLife usually have this line.
Example: #O John Smith john@gmail.com Fri Apr 30 19:38:52 1999
P Essentially the same as R, below. This line is produced by Life32, which generates coordinates which should represent the top-left corner of the Life pattern.
Example: #P 90 136
R Gives the coordinates of the top-left corner of the pattern. RLE files produced by XLife usually have this line, and the coordinates are usually negative, with the intention of placing the centre of the pattern at the origin.
Example: #R -22 -57
r Gives the rule for the pattern in the form survival_counts/birth_counts (e.g. 23/3 for Life). This line is usually present in RLE files created by XLife, but the standard method of indicating the rule is described below.
Example: #r 23/3

The rule for which the pattern is designed can be indicated in the header line, which then takes the form

x = m, y = n, rule = abc

where abc is the rule's designation, such as B3/S23 for Life or B36/S23 for HighLife. This type of extended header line is usual whenever the pattern is not intended for Conway's Life. As with ordinary header lines, RLE writers should adhere to the spacing shown, but RLE readers are best not to assume it.

Letters other than b and o may be used for the <tag>s to represent extra states. Unless the cellular automaton has more than 26 states it's a good idea to stick to lowercase letters. RLE readers that cannot handle more than two states should treat all letters other than b (and perhaps B) as equivalent to o.

Examples

The following is a glider in RLE format:

#C This is a glider. x = 3, y = 3 3o$o$bo!

External links

Cellular automata file formats