{
"info": {
"author": "Max-Philipp Schrader",
"author_email": "",
"bugtrack_url": null,
"classifiers": [
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3"
],
"description": "# gym-sokoban \n[Sokoban](https://en.wikipedia.org/wiki/Sokoban) is Japanese for warehouse keeper and a traditional video game.\nThe game is a transportation puzzle, where the player has to push all boxes in the room on the storage locations/ targets.\nThe possibility of making irreversible mistakes makes these puzzles so challenging especially for [Reinforcement Learning](https://en.wikipedia.org/wiki/Reinforcement_learning) algorithms, which mostly lack the ability to think ahead.\n
The repository implements the game Sokoban based on the rules presented [DeepMind's]() paper [Imagination Augmented Agents for Deep Reinforcement Learning](https://papers.nips.cc/paper/7152-imagination-augmented-agents-for-deep-reinforcement-learning). \nThe room generation is random and therefore, will allow to train Deep Neural Networks without overfitting on a set of predefined rooms.\n\n\n| Example Game 1 | Example Game 2 | Example Game 3 |\n| :---: | :---: | :---: \n|  |  |  |\n\n\n## 1 Installation\n\n### Via PIP\n```bash\npip install gym-sokoban\n```\n\n### From Repository\n```bash\ngit clone git@github.com:mpSchrader/gym-sokoban.git\ncd gym-sokoban\npip install -e .\n```\nCheckout the [examples](https://github.com/mpSchrader/gym-sokoban/examples) on how to use an external gym environment.\n\n## 2 Game Environment\n\n### 2.1 Room Elements\nEvery room consists of five main elements: walls, floor, boxes, box targets, and a player. They might have different states whether they overlap with a box target or not. \n\n| Type | State | Graphic | TinyWorld |\n| --- | ----- | :---: | :---: |\n| Wall | Static |  |  |\n| Floor | Empty |  |  |\n| Box Target | Empty |  |  |\n| Box | Off Target |  |  |\n| Box | On Target |  |  |\n| Player | Off Target |  |  |\n| Player | On Target |  |  |\n\n### 2.2 Actions\nThe game provides 9 actions to interact with the environment. \nPush and Move actions into the directions Up, Down, Left and Right.\nThe No Operation action is a void action, which does not change anything in the environment.\nThe mapping of the action numbers to the actual actions looks as follows\n\n | Action | ID | \n | -------- | :---: | \n | No Operation | 0 | \n | Push Up | 1 | \n | Push Down | 2 | \n | Push Left | 3 | \n | Push Right | 4 | \n | Move Up | 5 |\n | Move Down | 6 |\n | Move Left | 7 |\n | Move Right | 8 |\n\n**Move** simply moves if there is a free field in the direction, which means no blocking box or wall.\n\n**Push** push tries to move an adjacent box if the next field behind the box is free.\nThis means no chain pushing of boxes is possible.\nIn case there is no box at the adjacent field, the push action is handled the same way as the move action into the same direction.\n\n### 2.3 Rewards\nFinishing the game by pushing all on the targets gives a reward of 10 in the last step. \nAlso pushing a box on or off a target gives a reward of 1 respectively of -1. \nIn addition a reward of -0.1 is given for every step, this penalizes solutions with many steps.\n\n| Reason | Reward |\n| ------------------------- | ----: |\n| Perform Step | -0.1 |\n| Push Box on Target | 1.0 |\n| Push Box off Target | -1.0 |\n| Push all boxes on targets | 10.0 |\n\n### 2.4 Level Generation\nEvery time a Sokoban environment is loaded or reset a new room is randomly generated.\nThe generation consists of 3 phases: Topology Generation, Placement of Targets and Players, and Reverse Playing.\n#### 2.4.1 Topology Generation\nTo generate the basic topology of the room, consisting of walls and empty floor, is based on a random walk, which changes its direction at probability 0.35.\nAt every step centered at the current position, a pattern of fields is set to empty spaces.\nThe patterns used can be found in [Figure 2](#topologyMask).\n
\n
\n
\n Figure 2: Masks for creating a topology\n
\n\n \n