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. .. raw:: html
Maze: 5 rows × 5 columns | Cells: 25 | Current tool: Hole (click to toggle)
Using the Maze Builder ---------------------- **Tools:** - **Hole**: Click on a cell to toggle it between a valid cell (light gray) and a hole (dark). Holes are not part of the maze. - **Wall**: Click on the edges between cells to add or remove walls. Walls block movement between adjacent cells. - **Mud**: Click on edges between cells to add mud. Set the mud value first (the number of turns required to cross). Click again to remove mud. - **Cheese**: Click on cells to place or remove cheese. Cheese positions will be saved with your maze. **Maze Controls:** - Use the **+** and **−** buttons around the maze to add or remove rows and columns. - Check **Show indices** to display the cell index numbers (useful for debugging). **Save/Load:** - Click **Save** to download your maze as a file. - Click **Load** to import a previously saved maze. 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: .. code-block:: python # Import the necessary modules import ast from pyrat import Game # 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. .. code-block:: python # Import the necessary modules import ast from pyrat import Game, MazeFromDict # 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_cheese`` parameter when creating the ``Game`` object. Cheese will then be placed randomly by the game.