Cloudy background
Sokoban Logo
 
Sokoban Level Identity

Here is an algorithm that calculates an identity for a given Sokoban level. The identity is unique and only based on the playable part of the level. It is also independant of rotations and mirroring. level_id picture 1

Fill the playable area of the level. Start at the "man" position and recursively fill neighbouring squares until you hit a wall. The result is shown in red here. level_id picture 2 Encode the level, using the usual characters ( $@#.+*). Each line must be terminated with newline (hex 0A).
############
####   @####
###  *$  ###
# . .#. $###
#  $$ #. ###
### ..$    #
########## #
############
            
Fill with walls. Change every square that is not marked, to wall. This eliminates everything outside the playable area. level_id picture 3 Calculate an MD5 message digest of the string from step 5. The calculated sum is 32 characters long, but only the first 16 are used. MD5 is available in most scripting languages.The specification can be found here RFC 1321.
The result in this example is: 545CE11D547CC6D6.
Reduce walls. Make the four outer walls exactly one unit thick at its thinnest. level_id picture 4 Rotate and mirror the level in all possible combinations and repeat steps 5 and 6. This produces eight different MD5 sums.
545CE11D547CC6D6
A95C4600C6769137
F8C5D36B1F718D0F
3D984F1C449D212B
F7D213152DAA551E
28FBF9ECE43024B1
017F1D37EE023ACB
3B2D3843FEC69222
            
The finished level. level_id picture 5 Final step is to select the numerically smallest of the eight sums. In this case the level identity is: 017F1D37EE023ACB. Note that there is a (very) slight risk that two totally different levels will produce the same identity.