Sok format

From Sokoban Wiki

(Difference between revisions)
Jump to: navigation, search
m (Implementation of the sok format)
(7 intermediate revisions not shown)
Line 1: Line 1:
 +
 +
__FORCETOC__
= Header added to the level files by the program "Sokoban YASC" =
= Header added to the level files by the program "Sokoban YASC" =
Line 5: Line 7:
::        Sokoban (c) by Falcon Co., Ltd., Japan        ::
::        Sokoban (c) by Falcon Co., Ltd., Japan        ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
::                    File Format 0.14                   ::
+
::                    File Format 0.17                   ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::                                                        ::
::                                                        ::
-
:: File Header                                            ::
+
:: File Notes                                 Optional  ::
-
::  Raw File Notes                           Optional  ::
+
:: Puzzle 1                                   Required  ::
-
::   File Notes                                Optional  ::
+
-
::  Game Type                                Optional  ::
+
-
::  Macros                                   Optional  ::
+
-
:: Level 1                                    Required  ::
+
::    Title                                    Optional*  ::
::    Title                                    Optional*  ::
::    Board                                    See legend ::
::    Board                                    See legend ::
-
::    Level Notes                             Optional  ::
+
::    Puzzle Notes                             Optional  ::
-
::    Game 1                                   Optional  ::
+
::    Saved Game or Solution 1                 Optional  ::
::      Title                                  Optional*  ::
::      Title                                  Optional*  ::
::      Moves                                  See legend ::
::      Moves                                  See legend ::
-
::      Game Notes                             Optional  ::
+
::      Notes                                 Optional  ::
-
::    Game 2                                   Optional  ::
+
::    Saved Game or Solution 2                 Optional  ::
-
::    ... (more games)                                   ::
+
::    ... (more saved games and solutions)               ::
-
:: Level 2                                     Optional  ::
+
:: Puzzle 2                                   Optional  ::
-
:: ... (more levels)                                     ::
+
:: ... (more puzzles)                                     ::
::                                                        ::
::                                                        ::
:: Remarks:                                              ::
:: Remarks:                                              ::
-
::                                                        ::
 
-
:: File Header                                            ::
 
-
::  The different types of information may be written in ::
 
-
::  any order.                                          ::
 
-
::                                                        ::
 
-
:: Raw File Notes                                        ::
 
-
::  Raw file notes are only intended for someone looking ::
 
-
::  at the raw file in a text editor. These lines begin  ::
 
-
::  with "::".                                          ::
 
::                                                        ::
::                                                        ::
:: File Notes                                            ::
:: File Notes                                            ::
-
::  File notes are the remaining lines when all other    ::
+
::  File notes consist of unstructured text and          ::
-
::  information is removed from the file header, e.g.,  ::
+
::  key/value properties, such as "Author: Name". Lines  ::
-
::  raw file notes and macros.                          ::
+
::  beginning with "::" are comments meant to be read    ::
-
::                                                        ::
+
::  only by a person examining the file in a text       ::
-
::  As an example, file notes can contain general       ::
+
::  editor, and should not be displayed by the Sokoban  ::
-
::  properties written as key/value pairs, such as      ::
+
::  program.                                             ::
-
::  "Author: Name".                                     ::
+
::                                                        ::
::                                                        ::
::  The optional but recommended property                ::
::  The optional but recommended property                ::
::  "Collection: Name" assigns a name to the puzzle      ::
::  "Collection: Name" assigns a name to the puzzle      ::
-
::  collection. When a collection is copied from a      ::
+
::  collection. When a collection is copied from the    ::
-
::  website or e-mail and pasted into a Sokoban program, ::
+
::  internet, for example, and pasted into a Sokoban     ::
-
::  this information allows the collection to be saved   ::
+
::  program, this information allows the collection to  ::
-
::  with the proper name.                               ::
+
::  be saved with the proper name.                       ::
-
::                                                        ::
+
-
:: Game Type                                              ::
+
-
::  The type applies to all levels in the file. If it is ::
+
-
::  not specified, the default value is "Sokoban".      ::
+
-
::                                                        ::
+
-
::  The type is written as "Game: X" or "Game=X".        ::
+
-
::  An example: "Game: Hexoban".                        ::
+
-
::                                                        ::
+
-
:: Macros                                                ::
+
-
::  Macros are key/value pairs separated by "=".        ::
+
-
::  An example: "Copyright=These levels are (c) by NN".  ::
+
-
::                                                        ::
+
-
::  The value of a key/value pair can be inserted in    ::
+
-
::  level notes and game notes by writing the key        ::
+
-
::  enclosed by "<#" ... "#/>". This applies to both    ::
+
-
::  types of key/value pairs, ":" and "=", but in        ::
+
-
::  contrast to ":" pairs, macros are not considered    ::
+
-
::  a part of the file notes.                            ::
+
-
::                                                        ::
+
-
::  An example of macro usage: "<#Copyright#/>".        ::
+
-
::  The use of key/value pairs is case-insensitive.      ::
+
-
::                                                        ::
+
-
::  Macro-definitions are single-lined. To insert a      ::
+
-
::  line-break in the expanded text, write "\n".        ::
+
::                                                        ::
::                                                        ::
:: Titles                                                ::
:: Titles                                                ::
::  A title line is the last non-blank text line before  ::
::  A title line is the last non-blank text line before  ::
-
::  a level or a game, provided the line is preceded    ::
+
::  a board, a saved game, or a solution, provided the   ::
-
::  by a blank line or it is the only text line at this ::
+
::  line is preceded  by a blank line or it is the only  ::
-
::  position in the file.                               ::
+
::  text line at this position in the file.             ::
::                                                        ::
::                                                        ::
::  Title lines are optional unless a single or a last  ::
::  Title lines are optional unless a single or a last  ::
-
::  text line from a preceding level, game, or file      ::
+
::  text line from a preceding puzzle, saved game,       ::
-
::  header can be mistaken for a title line.             ::
+
::  solution, or file header can be mistaken for a title ::
 +
::  line.                                               ::
::                                                        ::
::                                                        ::
-
:: Level Notes                                           ::
+
:: Puzzle Notes                                           ::
-
::  Two special key/value pairs are supported in level  ::
+
::  Two special key/value pairs are supported in puzzle  ::
::  notes: "Title" and "Author", hence, titles can      ::
::  notes: "Title" and "Author", hence, titles can      ::
::  either come from a title line or from a key/value    ::
::  either come from a title line or from a key/value    ::
Line 97: Line 62:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Wall...................: #  # :...................Wall ::
:: Wall...................: #  # :...................Wall ::
-
:: Pusher.................: p :.................Pusher ::
+
:: Pusher.................: p @ :.................Pusher ::
-
:: Pusher on goal square..: P :..Pusher on goal square ::
+
:: Pusher on goal square..: P + :..Pusher on goal square ::
-
:: Box....................: b :....................Box ::
+
:: Box....................: b $ :....................Box ::
-
:: Box on goal square.....: B :.....Box on goal square ::
+
:: Box on goal square.....: B * :.....Box on goal square ::
-
:: Goal square............: .  o :............Goal square ::
+
:: Goal square............: .  . :............Goal square ::
:: Floor..................:      :..................Floor ::
:: Floor..................:      :..................Floor ::
:: Floor..................: -  _ :..................Floor ::
:: Floor..................: -  _ :..................Floor ::
Line 108: Line 73:
::                                                        ::
::                                                        ::
::  The first and the last non-empty square in each row  ::
::  The first and the last non-empty square in each row  ::
-
::  must be a wall or a box on a goal. A board cannot    ::
+
::  must be a wall or a box on a goal. An empty interior ::
-
::  have empty rows.                                     ::
+
::  row is written with at least one "-" or "_".         ::
::                                                        ::
::                                                        ::
::  Boards may be run-length encoded (RLE), e.g.,        ::
::  Boards may be run-length encoded (RLE), e.g.,        ::
-
::  "###----@.#" may be encoded as "3#4-@.#", and        ::
+
::  "###----p.#" may be encoded as "3#4-p.#", and        ::
::  "#-#-#-##-#-#-#" may be encoded as "2(3(#-)#)".      ::
::  "#-#-#-##-#-#-#" may be encoded as "2(3(#-)#)".      ::
-
::  A row cannot be split over multiple physical lines. ::
+
::  A row cannot be split over multiple lines.           ::
::                                                        ::
::                                                        ::
-
::  Rows may be combined on a single physical line by   ::
+
::  Rows may be combined on a single line by using "|"  ::
-
::  using "|" as a row separator, e.g.,                 ::
+
::  as a row separator, e.g., "--3#|3#-#|#pb.#|5#".     ::
-
::  "--3#|3#-#|#@$.#|5#". A "|" at the end of a physical ::
+
::  A "|" at the end of a line is optional and may be   ::
-
::  line is optional and may be omitted.                 ::
+
::  omitted.                                             ::
::                                                        ::
::                                                        ::
::::::::::::::::::::::::::: Moves ::::::::::::::::::::::::::
::::::::::::::::::::::::::: Moves ::::::::::::::::::::::::::
Line 128: Line 93:
:: Move pusher left.......: l  L :.....Push/pull box left ::
:: Move pusher left.......: l  L :.....Push/pull box left ::
:: Move pusher right......: r  R :....Push/pull box right ::
:: Move pusher right......: r  R :....Push/pull box right ::
-
:: Jump start.............: [  ] :...............Jump end ::
+
:: Begin jump.............: [  ] :...............End jump ::
 +
:: Begin pusher change....: {  } :......End pusher change ::
:: Current position.......: *  * :.......Current position ::
:: Current position.......: *  * :.......Current position ::
::                                                        ::
::                                                        ::
:: Remarks:                                              ::
:: Remarks:                                              ::
::                                                        ::
::                                                        ::
-
::  Moves may be run-length encoded, e.g., "3r3U" means  ::
+
::  Moves may be run-length encoded, e.g., "3r4U" means  ::
-
::  "rrrUU", and "2(3(dr)R)" means "drdrdrRdrdrdrR".     ::
+
::  "rrrUUUU", and "2(3(dr)R)" means "drdrdrRdrdrdrR".   ::
::  Each line must, however, have at least one proper    ::
::  Each line must, however, have at least one proper    ::
::  non-digit character. Spaces between moves are        ::
::  non-digit character. Spaces between moves are        ::
::  allowed.                                            ::
::  allowed.                                            ::
::                                                        ::
::                                                        ::
-
::  Jumps and pulls: Only in reverse mode games.         ::
+
::  Jumps and pulls: Only in reverse mode saved games   ::
 +
::  and solutions.                                       ::
::                                                        ::
::                                                        ::
-
::  Reverse mode games must start with a jump, even if  ::
+
::  Reverse mode saved games and solutions must begin    ::
-
::  it is empty. An example: "[]UU[ddlll]DDllR".         ::
+
::  with a jump, even if it is empty. An example:       ::
 +
::  "[]U[rr]d".                                         ::
::                                                        ::
::                                                        ::
-
::  Current position is optional and defaults to the     ::
+
::  Pusher changes: Only in puzzles with multiple        ::
 +
::  pushers, e.g., Multiban. Moves inside the braces    ::
 +
::  depict the relative movement to get from the        ::
 +
::  currently active pusher to the next active pusher.  ::
 +
::  At game start, a "{...}" sequence activates the      ::
 +
::  pusher relative to the top-left pusher. An example:  ::
 +
::  "{rddd}Urr{uul}uLU". If the top-left pusher is the  ::
 +
::  first active pusher, then the empty "{}" can be      ::
 +
::  omitted.                                            ::
 +
::                                                        ::
 +
::  The current position is optional and defaults to the ::
::  position after the last move.                        ::
::  position after the last move.                        ::
::                                                        ::
::                                                        ::
-
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 
-
Date Created:
 
-
Date of Last Change: 2010-01-26  17:44:01
 
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
Macros
+
An example file:
-
The macro feature allows levels to share a common
+
----------------------------------------------------------------------
-
text such as a copyright notice. An example:
+
Collection: YASGen
 +
Author: YASGen & Brian Damgaard
 +
Copyright (c) 2003 by Brian Damgaard
 +
These levels may be freely distributed provided they are credited with
 +
the author's name.
-
Copyright=Copyright (c) 3642 by xyz@paris.mars
+
Chaos
 +
  #####
 +
###p .#
 +
# b #.#
 +
#  bb #
 +
#.  # #
 +
#  b.#
 +
#######
 +
 +
Solution/Moves
 +
dDuurrddLLrrddLLUlluuRDRddrruuLLrruullDlldddRRuULrrruullDldRddlUruuurr
 +
ddddLLuuRlddrruUUdlldlldRRuuulDrddlluRurrrddLLUluRRlddrruUlldlldRRRllu
 +
uulD
 +
----------------------------------------------------------------------
 +
 +
More level examples:
Demo Level 01
Demo Level 01
Line 177: Line 171:
Solution/Moves
Solution/Moves
-
(rurrdD)(uLulDD)
+
rurrdDuLulDD
The title of a snapshot does not bear any special meaning.
The title of a snapshot does not bear any special meaning.
Line 208: Line 202:
Just another trivial demo level. The number of levels in a
Just another trivial demo level. The number of levels in a
file is limited by available memory only.
file is limited by available memory only.
-
 
-
A macro example, inserting the text defined in the copyright-macro:
 
-
<#Copyright#/>
 
Solution/Moves
Solution/Moves
-
(rRRR)(drU)(dlLLulD)
+
rRRRdrUdlLLulD
Reverse Mode Snapshot 13/6
Reverse Mode Snapshot 13/6
-
[rrrd]UU(rLLL)(drD)
+
[rrrd]UUrLLLdrD
This is an example of a reverse mode snapshot.
This is an example of a reverse mode snapshot.
Line 234: Line 225:
Solution/Moves
Solution/Moves
-
(rrruul)(Lr)(Duull)(DD)
+
rrruulLrDuullDD
</pre>
</pre>
-
= Implementation of the file format =
+
= Implementation of the sok format =
 +
 
 +
The advantage of the free formatted .sok file format is that it doesn't depend on keywords or specific tags (like xml based formats do). Therefore it's rather easy to manipulate and edit the files manually.
 +
<br>
 +
From Brian Damgaard on yahoo group:<br>
 +
<div style="background-color:#F0FFF0;padding:5px;border:1px solid green;">
 +
It only requires a few extra code lines and can easily be implemented with a normal and efficient one-pass parser. The only special thing the program must do is to take into account that:
 +
* At the time the parser reads level notes, it's not known whether 1) the last text line belongs to the notes for the current level, or 2) it's the title line for the next level.
 +
* Resolving that question can first take place when the parser sees the next level (its board).
 +
* At that point, a non-fool-proof-but-in-practice-more-than-good-enough separation can be made. If the last text line in the notes from the preceding level is a single line (not part of a multi-line paragraph) then it's a title.
 +
 
 +
Some refinements can be implemented. For instance, in YASC, the line isn't considered a title if the line contains ":" because it typically signals a key-value pair. Again, it's not fool-proof, but in practice it's perfectly all right. There won't be more than, say, 1 in 50,000 true levels. where this logic fails.
 +
 
 +
The easiest way to describe a .sok file parser is with pseudo-code, concentrating on file-header, boards, titles, and notes, but omitting snapshots:
 +
  ..set state to fileHeader
 +
  ..while more lines do
 +
  .....case state of
 +
  .......fileHeader......if...next line is a board-line then
 +
  ............................change state to newLevel
 +
  ............................check whether the file-header
 +
  ............................contains a title for the first level
 +
  .......................else add next line to file-header
 +
  ............................and advance
 +
  .......................(break, for C-programmers)
 +
  .......newLevel........create new level
 +
  .......................set level-title to the stored title, if any
 +
  .......................repeat
 +
  .........................add next line to board-lines and advance
 +
  .......................until eof or the next line isn't a board-line
 +
  .......................set state to levelNotes
 +
  .......................(break, for C-programmers)
 +
  .......levelNotes......if...next line is a board-line then
 +
  ............................change state to newLevel
 +
  ............................check whether the level-notes
 +
  ............................contain a title for the next level
 +
  .......................else add next line to level-notes and advance
 +
  .....endcase
 +
  ..endwhile
 +
 
 +
  Adding snapshots/solutions to the parser is straightforward.
 +
  It involves 2 more parser states, "NewSnapshot" and "SnapshotNotes",
 +
  which work more or less like "newLevel" and "levelNotes".
 +
</div>
 +
 
 +
<br>
 +
Note: Some programs like Sokoban YASC resctrict the level titles to valid Windows file names. This means characters like these ": \ * ? [ ] ; < > | / " are ignored in the level title. This however it not part of the sok-file format.
 +
 
 +
Answer from Eric Sunshine in yahoo group:<br>
 +
<div style="background-color:snow;padding:5px;border:1px solid orange;">
 +
If you would like to support other cases, such as when much or all of
 +
the meta-data appears before the puzzle, then you likely will need to
 +
implement a more complex heuristic for determining which non-puzzle data
 +
belongs to each puzzle. SokoSave Mobile takes this approach, trying very
 +
hard to intuit which information belongs with which puzzle, since many
 +
older collections are formatted in ways not compatible with the .sok
 +
format. To do this, SokoSave Mobile implements heuristics based directly
 +
on the SokoSplit utility (with a few small bug fixes):
 +
http://www.high-speed-software.com/sokosave/sokosavedesktop/sokosplit/
 +
 
 +
Here is a brief description of the heuristic. For each puzzle, perform
 +
the following steps in order:
 +
 
 +
1. If there is a blank line immediately before the puzzle, assign it to
 +
the puzzle.
 +
 
 +
2. Assign all following unassigned non-blank lines to the puzzle.
 +
 
 +
3. Assign all preceding unassigned non-blank lines to the puzzle. These
 +
lines precede the blank line (if present) assigned to the puzzle in step 1.
 +
 
 +
4. Assign all following unassigned lines (blank or not) to the puzzle.
 +
 
 +
5. Optional: Clean up by trimming leading and trailing blank lines from
 +
the collected meta-data. (Internal blank lines are retained.)
 +
 
 +
This heuristic works correctly with all of the old puzzle collections I
 +
have sitting around which were downloaded years ago, as well as with
 +
modern collections available for download. The heuristic also is a
 +
superset of the YASC .sok parsing, so it works properly with those
 +
collections, as well.
 +
 
 +
</div>

Revision as of 02:45, 17 April 2021


Contents

Header added to the level files by the program "Sokoban YASC"

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::         Sokoban (c) by Falcon Co., Ltd., Japan         ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::                    File Format 0.17                    ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::                                                        ::
:: File Notes                                  Optional   ::
:: Puzzle 1                                    Required   ::
::    Title                                    Optional*  ::
::    Board                                    See legend ::
::    Puzzle Notes                             Optional   ::
::    Saved Game or Solution 1                 Optional   ::
::      Title                                  Optional*  ::
::      Moves                                  See legend ::
::      Notes                                  Optional   ::
::    Saved Game or Solution 2                 Optional   ::
::    ... (more saved games and solutions)                ::
:: Puzzle 2                                    Optional   ::
:: ... (more puzzles)                                     ::
::                                                        ::
:: Remarks:                                               ::
::                                                        ::
:: File Notes                                             ::
::   File notes consist of unstructured text and          ::
::   key/value properties, such as "Author: Name". Lines  ::
::   beginning with "::" are comments meant to be read    ::
::   only by a person examining the file in a text        ::
::   editor, and should not be displayed by the Sokoban   ::
::   program.                                             ::
::                                                        ::
::   The optional but recommended property                ::
::   "Collection: Name" assigns a name to the puzzle      ::
::   collection. When a collection is copied from the     ::
::   internet, for example, and pasted into a Sokoban     ::
::   program, this information allows the collection to   ::
::   be saved with the proper name.                       ::
::                                                        ::
:: Titles                                                 ::
::   A title line is the last non-blank text line before  ::
::   a board, a saved game, or a solution, provided the   ::
::   line is preceded  by a blank line or it is the only  ::
::   text line at this position in the file.              ::
::                                                        ::
::   Title lines are optional unless a single or a last   ::
::   text line from a preceding puzzle, saved game,       ::
::   solution, or file header can be mistaken for a title ::
::   line.                                                ::
::                                                        ::
:: Puzzle Notes                                           ::
::   Two special key/value pairs are supported in puzzle  ::
::   notes: "Title" and "Author", hence, titles can       ::
::   either come from a title line or from a key/value    ::
::   pair.                                                ::
::                                                        ::
::::::::::::::::::::::::::: Board ::::::::::::::::::::::::::
:: Legend.................:      :.................Legend ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Wall...................: #  # :...................Wall ::
:: Pusher.................: p  @ :.................Pusher ::
:: Pusher on goal square..: P  + :..Pusher on goal square ::
:: Box....................: b  $ :....................Box ::
:: Box on goal square.....: B  * :.....Box on goal square ::
:: Goal square............: .  . :............Goal square ::
:: Floor..................:      :..................Floor ::
:: Floor..................: -  _ :..................Floor ::
::                                                        ::
:: Remarks:                                               ::
::                                                        ::
::   The first and the last non-empty square in each row  ::
::   must be a wall or a box on a goal. An empty interior ::
::   row is written with at least one "-" or "_".         ::
::                                                        ::
::   Boards may be run-length encoded (RLE), e.g.,        ::
::   "###----p.#" may be encoded as "3#4-p.#", and        ::
::   "#-#-#-##-#-#-#" may be encoded as "2(3(#-)#)".      ::
::   A row cannot be split over multiple lines.           ::
::                                                        ::
::   Rows may be combined on a single line by using "|"   ::
::   as a row separator, e.g., "--3#|3#-#|#pb.#|5#".      ::
::   A "|" at the end of a line is optional and may be    ::
::   omitted.                                             ::
::                                                        ::
::::::::::::::::::::::::::: Moves ::::::::::::::::::::::::::
:: Legend.................:      :.................Legend ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Move pusher up.........: u  U :.......Push/pull box up ::
:: Move pusher down.......: d  D :.....Push/pull box down ::
:: Move pusher left.......: l  L :.....Push/pull box left ::
:: Move pusher right......: r  R :....Push/pull box right ::
:: Begin jump.............: [  ] :...............End jump ::
:: Begin pusher change....: {  } :......End pusher change ::
:: Current position.......: *  * :.......Current position ::
::                                                        ::
:: Remarks:                                               ::
::                                                        ::
::   Moves may be run-length encoded, e.g., "3r4U" means  ::
::   "rrrUUUU", and "2(3(dr)R)" means "drdrdrRdrdrdrR".   ::
::   Each line must, however, have at least one proper    ::
::   non-digit character. Spaces between moves are        ::
::   allowed.                                             ::
::                                                        ::
::   Jumps and pulls: Only in reverse mode saved games    ::
::   and solutions.                                       ::
::                                                        ::
::   Reverse mode saved games and solutions must begin    ::
::   with a jump, even if it is empty. An example:        ::
::   "[]U[rr]d".                                          ::
::                                                        ::
::   Pusher changes: Only in puzzles with multiple        ::
::   pushers, e.g., Multiban. Moves inside the braces     ::
::   depict the relative movement to get from the         ::
::   currently active pusher to the next active pusher.   ::
::   At game start, a "{...}" sequence activates the      ::
::   pusher relative to the top-left pusher. An example:  ::
::   "{rddd}Urr{uul}uLU". If the top-left pusher is the   ::
::   first active pusher, then the empty "{}" can be      ::
::   omitted.                                             ::
::                                                        ::
::   The current position is optional and defaults to the ::
::   position after the last move.                        ::
::                                                        ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

An example file:

----------------------------------------------------------------------
Collection: YASGen
Author: YASGen & Brian Damgaard
Copyright (c) 2003 by Brian Damgaard
These levels may be freely distributed provided they are credited with
the author's name.

Chaos

  #####
###p .#
# b #.#
#  bb #
#.  # #
#   b.#
#######

Solution/Moves
dDuurrddLLrrddLLUlluuRDRddrruuLLrruullDlldddRRuULrrruullDldRddlUruuurr
ddddLLuuRlddrruUUdlldlldRRuuulDrddlluRurrrddLLUluRRlddrruUlldlldRRRllu
uulD
----------------------------------------------------------------------

More level examples:

Demo Level 01

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

This demo level is trivial, but it suffices to demonstrate
the file-format.
A Sokoban program can add key/value pairs within the notes,
such as:
Author: nn
Website: http://www.nn.net

Solution/Moves
rurrdDuLulDD

The title of a snapshot does not bear any special meaning.
This snapshot just happens to be the best solution found
(so far). The demo-program automatically saves best solutions.

Snapshot 7/0
urrrrdd

This is an example of a snapshot saved by the user.
Later he/she can continue work on this path.

Snapshot 9/2
urrrrddLL*ruulDD

Another snapshot saved by the user. The '*' indicates
current position, i.e., the last moves were taken back,
but are still available for the "redo" function.


Demo Level 02

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

Just another trivial demo level. The number of levels in a
file is limited by available memory only.

Solution/Moves
rRRRdrUdlLLulD

Reverse Mode Snapshot 13/6
[rrrd]UUrLLLdrD

This is an example of a reverse mode snapshot.

Reverse mode snapshots always have a leading jump-sequence,
even if it is empty. An example: "[]Ulld...".


Demo Level 03

########
#      #
#  $   #
#   $  #
# + .  #
########

Solution/Moves
rrruulLrDuullDD

Implementation of the sok format

The advantage of the free formatted .sok file format is that it doesn't depend on keywords or specific tags (like xml based formats do). Therefore it's rather easy to manipulate and edit the files manually.
From Brian Damgaard on yahoo group:

It only requires a few extra code lines and can easily be implemented with a normal and efficient one-pass parser. The only special thing the program must do is to take into account that:

  • At the time the parser reads level notes, it's not known whether 1) the last text line belongs to the notes for the current level, or 2) it's the title line for the next level.
  • Resolving that question can first take place when the parser sees the next level (its board).
  • At that point, a non-fool-proof-but-in-practice-more-than-good-enough separation can be made. If the last text line in the notes from the preceding level is a single line (not part of a multi-line paragraph) then it's a title.

Some refinements can be implemented. For instance, in YASC, the line isn't considered a title if the line contains ":" because it typically signals a key-value pair. Again, it's not fool-proof, but in practice it's perfectly all right. There won't be more than, say, 1 in 50,000 true levels. where this logic fails.

The easiest way to describe a .sok file parser is with pseudo-code, concentrating on file-header, boards, titles, and notes, but omitting snapshots:

 ..set state to fileHeader
 ..while more lines do
 .....case state of
 .......fileHeader......if...next line is a board-line then
 ............................change state to newLevel
 ............................check whether the file-header
 ............................contains a title for the first level
 .......................else add next line to file-header
 ............................and advance
 .......................(break, for C-programmers)
 .......newLevel........create new level
 .......................set level-title to the stored title, if any
 .......................repeat
 .........................add next line to board-lines and advance
 .......................until eof or the next line isn't a board-line
 .......................set state to levelNotes
 .......................(break, for C-programmers)
 .......levelNotes......if...next line is a board-line then
 ............................change state to newLevel
 ............................check whether the level-notes
 ............................contain a title for the next level
 .......................else add next line to level-notes and advance
 .....endcase
 ..endwhile
 Adding snapshots/solutions to the parser is straightforward. 
 It involves 2 more parser states, "NewSnapshot" and "SnapshotNotes", 
 which work more or less like "newLevel" and "levelNotes".


Note: Some programs like Sokoban YASC resctrict the level titles to valid Windows file names. This means characters like these ": \ * ? [ ] ; < > | / " are ignored in the level title. This however it not part of the sok-file format.

Answer from Eric Sunshine in yahoo group:

If you would like to support other cases, such as when much or all of the meta-data appears before the puzzle, then you likely will need to implement a more complex heuristic for determining which non-puzzle data belongs to each puzzle. SokoSave Mobile takes this approach, trying very hard to intuit which information belongs with which puzzle, since many older collections are formatted in ways not compatible with the .sok format. To do this, SokoSave Mobile implements heuristics based directly on the SokoSplit utility (with a few small bug fixes): http://www.high-speed-software.com/sokosave/sokosavedesktop/sokosplit/

Here is a brief description of the heuristic. For each puzzle, perform the following steps in order:

1. If there is a blank line immediately before the puzzle, assign it to the puzzle.

2. Assign all following unassigned non-blank lines to the puzzle.

3. Assign all preceding unassigned non-blank lines to the puzzle. These lines precede the blank line (if present) assigned to the puzzle in step 1.

4. Assign all following unassigned lines (blank or not) to the puzzle.

5. Optional: Clean up by trimming leading and trailing blank lines from the collected meta-data. (Internal blank lines are retained.)

This heuristic works correctly with all of the old puzzle collections I have sitting around which were downloaded years ago, as well as with modern collections available for download. The heuristic also is a superset of the YASC .sok parsing, so it works properly with those collections, as well.

Personal tools