Sokoban

Sokoban (warehouse keeper in japanese) is a branch of the dungeon modeled on and named after a game where a character is navigated through a series of levels. The object is to move objects to cover goal squares. The character must move only in the cardinal directions (north, south, east, and west) and push the objects from behind to move them. A player fails by getting objects stuck or boxing himself/herself in, as objects cannot be pulled, created, or destroyed.

In the case of NetHack, the objects are boulders and the goal squares are pits or holes, which block the way forward. There are four levels in each game and two versions of each, for a total of 8 different levels. Diagonal moves are not allowed. At the end of the Sokoban dungeon branch is a Treasure Zoo guarding a bag of holding or amulet of reflection, depending on which version of level 4 you are given. The levels are ascending in dungeon depth, i.e., the 2nd level is above the 1st etc.

NetHack Sokoban is complicated by the presence of monsters in the puzzles, so some concessions have been made. It is possible to create or destroy boulders, but Luck penalties are assessed for each offense.

Adventurers who die in Sokoban will not leave bones.

Levels
The entrance to Sokoban (an upstairs staircase) is located between levels 6 and 10 inclusive in the Dungeons of Doom, just below the Oracle.

Sokoban and Luck
It is possible to solve every Sokoban level just by moving boulders around in the normal fashion. However, there are some actions that are legal in Nethack but cheat the Sokoban mini-game in some way. Whenever you perform such an action, your Luck is penalized. The following actions incur penalties of -1:


 * Jumping in Sokoban.
 * Breaking a boulder.
 * Walking (as a giant) or squeezing past a boulder
 * Casting stone-to-flesh on a boulder.
 * Polymorphing a boulder.
 * Reading a scroll of earth.
 * Being pulled by a thrown iron ball.
 * Hurtling through the air due to Newton's 3rd Law. (i.e. throwing something while levitating)

Note that teleporting a boulder does not incur a luck penalty, but may move the boulder somewhere odd.

Strategy
The articles about the individual levels contain a full solution to all the levels. Some general strategy tips include
 * Think ahead, the entire level is mapped and all the levels are solvable without 'cheating', barring some unfortunate monster generation.
 * Be careful, a typo may render a boulder immobile against the wall. Try to move diagonally whenever possible, as diagonal movement will not push a boulder.
 * Check whether there are monsters in front of the pits.
 * Use a magic whistle for pets, or leave them behind one level.
 * Be aware of mimics imitating boulders. Unlike real boulders, mimics will not appear until they are in your line of sight, but a space containing a boulder may also contain a mimic mimicking a boulder, if that makes sense.
 * Upon completion, check under unmoved boulders for useful items.
 * Polymorphing into a creature with the phasing ability will not help. Instead, you get the message "The Sokoban walls resist your ability."
 * In SLASH'EM, the doppelganger can liquid leap through the bars on the Sokoban levels, although one cannot traverse them by other means (e.g., as a snake).
 * Items can sometimes be generated over holes. Pushing a boulder over the hole will bury the item.  If you wish to retrieve the item instead, you may:
 * Kick the item away; it will fall down another hole and appear somewhere on the level below. This will destroy the item if it is fragile, and on the top level will wake the monsters in the zoo.
 * Repeatedly step on the space containing the item; it will eventually fall down with you, although not necessarily onto your space. This will never break the item.
 * Turn on autopickup and step on the space containing the item; you will pick it up before you fall. Beware of loadstones, both over the hole and on the levels below.

Strategies for when a boulder got stuck:
 * Destroy a boulder with a pick axe or wand of striking (count whether there are enough!) (luck penalty!)
 * Drop everything in your inventory (including armor) and squeeze into the same square as a boulder. This will help you separate boulders stuck together, but not a boulder stuck against a wall. This way, you can also kill monsters trapped between boulders and holes which block the way. (luck penalty!)
 * Polyself into a giant and step over boulders. You still cannot lift them, however. (luck penalty!)
 * Summon more boulders with a scroll of earth, which can be found on the 1st sokoban level. Note that a non-cursed scroll will summon multiple boulders, possibly making the situation worse. (luck penalty!)
 * If the boulder is stuck because of a monster behind it, you can shoot missiles past the boulder to kill the monster. Note, however, that unicorns can be generated in Sokoban, and you risk a large luck penalty for killing a coaligned one.  If you determine by whatever means that the unicorn behind a boulder is coaligned, you can toss gems to it to somewhat compensate for the inevitable luck hit.  Sokoban is no-teleport, so the unicorn cannot leave of its own accord.  Also note that you cannot kill unicorns with rocks, an easily accessible missile weapon.  Other peaceful monsters may also be generated (but peaceful humans cannot).  Force bolts and wands of striking will destroy boulders, but other methods are safe.
 * Hit the boulder with a wand of teleport. While the new location may not be better then the old one, it often can't be much worse, and you avoid any luck penalty.

The first level of sokoban, once completed, is often used as a stash level, for several reasons:
 * It is one of the locations which the Eye of the Aethiopica can teleport you to instantly.
 * It is conveniently located, one level from the Oracle, 2-8 levels from the Gnomish Mines, and located in the top half of the Dungeons of Doom, where shops and altars are likely.
 * It is relatively free of monsters, and a spawning ground for baby monsters rather than their larger versions.
 * There are spare boulders which can be used to further block off a safe area.
 * There is a long corridor which can be used for polypiling.

The first level also contains two scrolls of earth. Remember to #name them as such as soon as you find them.

nhss
nhss is a tool that sets up a nethack-like environment (basic movement and boulder pushing only) that can be used to figure a level out before actually playing it, thus reducing the chances of rendering a level unsolvable. It can also record sessions and play them back step by step.

Unaffiliated but related to nhss, Nethack's Sokoban levels for various Sokoban implementations (XSok, Sokoban++, YSokoban, Universal Sokoban format and Games 4 Brains Sokoban format) which you can use to practice the levels in other Sokoban games.