Maze Builder¶
This interactive tool allows you to create custom mazes for PyRat. Use the controls below to build your maze, then save it as a file to use in your games.
Using the Maze Builder¶
Tip
The mouse cursor tells you what a click will do: a hand adds something, a red cross removes it, and a crossed-out circle means that this click is not allowed here.
The four tools¶
Pick a tool in the toolbar, then click on the maze. The selected tool is highlighted in blue.
Click on a cell to turn it into a hole, and click again to turn it back into a cell. Holes are not part of the maze: no player can ever stand on them.
Click on an edge between two cells to add a wall, and click again to remove it. A wall prevents players from moving between these two cells.
Set the Mud value first, which is the number of turns needed to cross. Then click on an edge between two cells to put mud there. Clicking an edge that already holds mud with the same value removes it, and clicking with a different value replaces it.
Click on a cell to place a piece of cheese, and click again to remove it. Cheese positions are saved together with your maze.
Resizing the maze¶
Use the + and − buttons around the maze to add or remove rows and columns. They are placed on the four sides, so you can grow or shrink the maze in the direction you want.
Check Show indices to display the number of each cell. This is the number that PyRat uses internally, and the one you will see in the saved file, so it is handy when you debug a program.
Saving and loading¶
Click Save to download your maze as a file.
Click Load to bring a previously saved maze back into the builder and keep working on it.
Important
The Maze Builder runs entirely in your browser, and nothing is stored between visits. Save your maze before closing the page, or your work will be lost.
Using the Maze in PyRat¶
Once you’ve saved your maze, you can load it in your PyRat game.
The saved file contains a Python tuple (maze_dict, cheese_list) with the maze structure and cheese positions:
# Import the necessary modules
import ast
from pyrat import Game
if __name__ == "__main__":
# Load the maze and cheese from saved file
with open("pyrat_maze.py", "r") as f:
maze_dict, cheese_list = ast.literal_eval(f.read())
# Create a game with the custom maze and cheese
game = Game(fixed_maze=maze_dict, fixed_cheese=cheese_list)
You can also create a MazeFromDict object if you prefer.
This has the advantages of validating the maze structure and providing additional methods.
# Import the necessary modules
import ast
from pyrat import Game, MazeFromDict
if __name__ == "__main__":
# Load the maze and cheese from saved file
with open("pyrat_maze.py", "r") as f:
maze_dict, cheese_list = ast.literal_eval(f.read())
# Create a MazeFromDict object
maze = MazeFromDict(maze_dict)
# Create a game with the maze object and cheese
game = Game(fixed_maze=maze, fixed_cheese=cheese_list)
Remarks:
When starting a game, players are added before the cheese. Therefore, make sure that fixed cheese positions do not overlap with player starting positions.
If you only want to use this tool to design a maze, just remove the
fixed_cheeseparameter when creating theGameobject. Cheese will then be placed randomly by the game.