MaGame
MaGame is a package currently involving two maze games: Mappy and Pac-man. In the game Mappy, a mouse cop is searching for the criminal cat in the maze, while in the other game Pac-man, the character is trying to eat all dots in the maze.
Once you installed the package with the pip command, you may follow steps below to run the game.
Step 1: import the game and mazes from the MaGame package
from magame import mappy # Import the Mappy game
from magame import pacman # Import the Pac-man game
from magame import mazes # Import the pre-defined mazes
The variable mazes is a tuple, containing four nested lists representing the mazes, where:
- Maze wall is indicated by "1".
- Open path is indicated by "0".
- The target in the Mappy game is indicated by "-1". It is treated as "0" in the Pac-man game.
One example is given below, and you may create your own maze following the same format.
mazes[0]
[[0, 0, 0, 1, 1, 0, 0, 0, 1, 1],
[0, 0, 1, 0, 1, 0, 0, 0, 0, 1],
[1, 0, 1, 0, 1, 0, 0, 1, 0, 0],
[1, 0, 0, 0, 1, 0, 0, 1, 0, 0],
[1, 1, 0, 1, 1, 1, 0, 1, 1, 0],
[0, 1, 0, 0, 1, 0, 0, 1, 0, 0],
[0, 1, 0, 1, 1, 0, 1, 1, 1, 0],
[0, 1, 0, 1, 0, 0, 1, 0, 0, 0],
[0, 0, 0, 1, 0, 1, 1, 0, 1, 1],
[1, 1, 0, 0, 0, 1, 0, 0, -1, 1]]
Step 2: create your own function that determines the movement in the maze
The user-defined function must follow the format below.
def maze_move(maze, position, memory):
"""
Your code here
"""
return move, memory
The input arguments of the function are:
mazeas a nested list representing the maze.positionis atuplewith two integers:v_indexandh_index. The first integerv_indexindicates the vertical index, and the second integerh_indexindicates the horizontal index, as shown by the picture below.memorycan be any data type. Users may use it to keep a track of all previous steps or previous moves. The initial value of memory is given asNone.
The outputs are:
moveis atuplewith two integers:v_moveandh_move. It is used to indicate how the character moves in the maze, as shown by the following picture.memoryis the updated memory, such as all previous steps or previous moves of the character in the maze.
The function receives the maze information, the current position in the maze, and previous step, moves, or other forms of memory; then decide the next move and update the memory.
Step 3: apply your function to play the game
The game can be played by simply calling the play() function of the mappy or pacman
mappy.play(maze, maze_move)
pacman.play(maze, maze_move)
There are two input arguments for the play() function:
mazeis the nested list as the maze information.maze_moveis the name of the function you created. It can be any valid Python function name.
If your function works correctly, you will find the character moving in the maze.
Release files for magame 0.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| magame-0.0.6.tar.gz | 78.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| magame-0.0.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 159.1 kB
Release files / magame-0.0.6.tar.gz
| Download URL | magame-0.0.6.tar.gz |
|---|---|
| Size | 78.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
98f976d2400dbf536a9ad012a298cfedd960a7c1a185823e01e846bea2c739ce
|
|
BLAKE2b-256 checksum How to use checksums |
3cd1db2c1f564431d235eba3fb34b88c64582fe3b8c21c7af96306fa151db757
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5
|
Release files / magame-0.0.6-py3-none-any.whl
| Download URL | magame-0.0.6-py3-none-any.whl |
|---|---|
| Size | 80.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0b2a1d40f4b6f3bfd091e3b160f8113771553aa6fd63d5fe482e1e6be1807a91
|
|
BLAKE2b-256 checksum How to use checksums |
061e80f49476a12e3aff6307d34da5bdc0e31937cc37cb0a5e8e203efd1d4285
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5
|