Janis
2003-12-05 01:11:32 UTC
An algorithm to create Sokoban levels seems not to be too hard :-]
NP hard problem to generate Sokoban levels.
An idea to solve the task is to treat the problem backwards...
1.) Create a bounded random dungeon with standard NH routines.
1a.) The dungeon *may* have some fixed part(s) connected, e.g. hallway(s)
that must be passed and which are leading to the room with the stairs
to the next level.
"N holes":
2.) Select a point on the map as close as possible to the room with
the stairs up. Search from a valid "unvisited" path to that point
starting from the entry stairs.(+)
2a.) Alternatively select a random point. (Path search as in 2.)
3.) Determine the position of a virtual Reyalp(*) adjacent to the
selected point on the opposite side of the room with the stairs.
4.) Create a hole at the selected point. Mark point as visited.
5.) Let the Reyalp drag a virtual boulder from the selected point.
Reyalp may not enter points already marked.
"One boulder":
6.) Select an adjacent point for Reyalp, that is not already marked.
7.) Move Reyalp, move virtual boulder, mark boulder position visited.
8.) Iterate "One boulder" for a (random) number Z of turns, while
moves are possible and a path to the entry stairs is existing.
8a.) Undo last move if no path to the entry stairs is existing.
9.) Make the virtual boulder a real one.
10.) Iterate "N holes" for a (random) number N of holes to be filled.
11.) Remove (virtual) Reyalp.
Finish.
(+) Step 2a) needs a bit more work: a valid path to Reyalp(*) must
also be existing, otherwise select a new point or stop interation.
(*) Reyalp: player backwards.
Though the resulting levels may not have an appealing design, I think
the above algorithm will work. The levels of course can not have the
finesse of the constructed elaborated levels, they are random. But
depending on whether you chose to allow fixed dungeon parts (1a.) and
whether you allow random holes (2a.) there may be quite interesting
new topologies generated. And the level difficulty may be tuned by
selecting appropriate values for N and Z.
hacked it onto the paper ;-) - you might want to try that algorithm.
Feedback and hints to errors made are welcome.
Janis, the Reyalp, smashed by a boulder
This topic comes up every so often. Sokoban is NP hard, so, unless
somebody proves P=NP, you'll have your machine try every possibility.
There are some generators around, but they are of course limited by your
Though they are NP hard to solve I think you don't need to solve ansomebody proves P=NP, you'll have your machine try every possibility.
There are some generators around, but they are of course limited by your
NP hard problem to generate Sokoban levels.
But to my YANI: Sokoban maps are far easier to generate than to solve.
I think so, too.An idea to solve the task is to treat the problem backwards...
1.) Create a bounded random dungeon with standard NH routines.
1a.) The dungeon *may* have some fixed part(s) connected, e.g. hallway(s)
that must be passed and which are leading to the room with the stairs
to the next level.
"N holes":
2.) Select a point on the map as close as possible to the room with
the stairs up. Search from a valid "unvisited" path to that point
starting from the entry stairs.(+)
2a.) Alternatively select a random point. (Path search as in 2.)
3.) Determine the position of a virtual Reyalp(*) adjacent to the
selected point on the opposite side of the room with the stairs.
4.) Create a hole at the selected point. Mark point as visited.
5.) Let the Reyalp drag a virtual boulder from the selected point.
Reyalp may not enter points already marked.
"One boulder":
6.) Select an adjacent point for Reyalp, that is not already marked.
7.) Move Reyalp, move virtual boulder, mark boulder position visited.
8.) Iterate "One boulder" for a (random) number Z of turns, while
moves are possible and a path to the entry stairs is existing.
8a.) Undo last move if no path to the entry stairs is existing.
9.) Make the virtual boulder a real one.
10.) Iterate "N holes" for a (random) number N of holes to be filled.
11.) Remove (virtual) Reyalp.
Finish.
(+) Step 2a) needs a bit more work: a valid path to Reyalp(*) must
also be existing, otherwise select a new point or stop interation.
(*) Reyalp: player backwards.
Though the resulting levels may not have an appealing design, I think
the above algorithm will work. The levels of course can not have the
finesse of the constructed elaborated levels, they are random. But
depending on whether you chose to allow fixed dungeon parts (1a.) and
whether you allow random holes (2a.) there may be quite interesting
new topologies generated. And the level difficulty may be tuned by
selecting appropriate values for N and Z.
(I'm currently working on a lot of sokoban related stuff, so who
knows? maybe I can do it one day)
If I have not made any mistakes - that's of course unlikely, I justknows? maybe I can do it one day)
hacked it onto the paper ;-) - you might want to try that algorithm.
Feedback and hints to errors made are welcome.
Janis, the Reyalp, smashed by a boulder