Last milestone completed

Completed the project. I wanted to replace the player with a penguin, but it didn't fit the maze, so I kept it as an '>'.
It shows where you begin and where you need to go to finish, and each game is a different maze. I thought this was very difficult and i needed to learn how to make a maze, I was not prepared for that.
This commit is contained in:
ilmabura
2025-12-07 16:17:56 -05:00
parent e2273773eb
commit 2af3d6c2e7
7 changed files with 67 additions and 17 deletions

View File

@@ -3,21 +3,19 @@ import random
from retro.game import Game
from player import Player
from wall import Wall
from markers import StartMarker, FinishMarker
def generate_maze_grid(width, height):
"""
Generate a 'perfect' maze on a width x height grid.
1 = wall, 0 = passage.
Uses depth-first search on a grid of cells spaced 2 apart,
which gives a nice twisty maze like your example image.
"""
grid = [[1 for _ in range(width)] for _ in range(height)]
for y in range(1, height - 1, 2):
for x in range(1, width - 1, 2):
grid[y][x] = 0
grid[y][x] = 0
visited = set()
@@ -47,7 +45,7 @@ def create_maze_walls(board_size):
center_x = (width // 2) | 1
center_y = (height // 2) | 1
grid[center_y][center_x] = 0
grid[center_y][center_x] = 0
end_position = (center_x, center_y)
wall_positions = []
@@ -63,26 +61,35 @@ def create_maze_walls(board_size):
def main():
board_size = (100, 40)
player = Player(board_size)
walls, end_position = create_maze_walls(board_size)
print("Exit (goal) will be around:", end_position)
start_position = (1, 1)
player = Player(board_size, end_position)
start_marker = StartMarker(start_position)
finish_marker = FinishMarker(end_position)
state = {
"win": False,
"message": "",
}
game = Game(
agents=[player] + walls,
agents=[
start_marker,
finish_marker,
player,
] + walls,
state=state,
board_size=board_size,
debug=True,
debug=False,
framerate=24,
color="white_on_black",
)
game.play()
if __name__ == "__main__":
main()