Level format

There are thousands of levels for the Sokoban game.

The most commonly used format for representing Sokoban levels is:

Level element Character ASCII code                                                                    
Wall # 0x23  
Player @ 0x40  
Player on goal + 0x2b  
Box $ 0x24  
Box on goal * 0x2a  
Goal 0x2e  
Floor (space) 0x20  

The simplest solvable level looks like this:

#####
#@$.#
#####

It's important that the whole level is surrounded by walls.

 

There are various different level formats. Many of them also offer the possibility to store save games or solutions in the level file.

 

A solution is represented by the movements of the player. The player can move up, down, left or right. Hence, the letters for these directions are: u, d, l, r.

 

In fact, the player is not moving up and down, he is moving on the floor. Hence, it would be more logical to use the system from classic text-adventures: (n)orth, (e)ast, (s)outh, (w)est. However the u, d, l, r representation has become a standard for Sokoban solutions.

 

A possible solution string may look like this: DDrdrruLruLLDllU

 

The capitals in this solution show that a box is pushed as the player moves. Usually this information is stored in a solution, too, although the solution is still correct if all letters are lowercase.

Exchange of Sokoban levels in Emails

Many e-mail servers strip empty spaces and multiple spaces. To ensure the levels can be imported to the email recipients properly here are some suggestions:

 

Replace all spaces by hyphens "-" (preferred) or underscores "_".

 

(the recipients of your mail have to replace them back to spaces in order to import the levels to their Sokoban programs. However, some of the Sokoban games do have already an automatic replacement built-in and can read the levels).

Run length encoding

The XSB format with RLE (run-length-encoding), is more compact and efficient in mobile devices (as Palm, PocketPC, Smart Phones), besides being smaller to send for SMS.

 

It can be used for both: levels and solutions.

 

In this format digits show how many elements of the same type are following.

 

####   becomes   4#

 

This level ("Claire", by Lee J Haywood):

#######
#.@ # #
#$* $ #
# $ #
# .. #
# * #
#######

runlength encoded looks like this:

 

7#|#.@-#-#|#$*-$-#|#3-$-#|#-..--#|#--*--#|7#

 

The rows of the level are separated by "|"s.

 

There has been a discussion in the Yahoo Group about what character should represent an empty square in May 2006. Finally the hyphen has been elected to be the standard character for an empty square. Nevertheless, programs are encouraged to support both, hyphens and underscores.

 

If only two level elements are grouped together they may be run length encoded, but needn't to.

 

Example:

$$  may keep  $$ or be encoded as  2$

 

It's recommended to write run-length encoded boards in a single line because currently some programs may not be able to handle RLE-boards spanning multiple lines. Most of the editor programs (for instance "notepad" in Windows) have a automatic wrapping of lines so there is no need for manually creating new lines.

 

However, when a RLE board spans multiple lines, the trailing "|" on each line may be omitted.

 

In the RLE format empty squares at the end of a row should be omitted.

 

For example, this level:

###__ 
#.###

#*$ #
# @ #
#####
The red underline characters represent spaces.

 

Should be RLE this way:

3#|#.3#|#*$-#|#--@#|5#

JSoko supported formats

JSoko supports loading files using the described format. Typically, files using this format have the file extension: .sok,.txt or .xsb.

 

Note: JSoko can't load level files stored in .lp0, .slc or other formats!