-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* maps review * wip * update lib * csv to txt * add maze generator --------- Co-authored-by: Matheus Jardim <[email protected]>
- Loading branch information
1 parent
7dc4cdd
commit 4013971
Showing
28 changed files
with
142 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.1.1 | ||
0.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from maze_runner.maze_creator import MazeGenerator | ||
|
||
maze = MazeGenerator.generate_maze_structure() | ||
MazeGenerator.save_maze_to_file(maze, "labirinto.txt") |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
####### | ||
#S F# | ||
####### |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
####### | ||
#F S# | ||
####### |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
####### | ||
# F# | ||
#S # | ||
# F# | ||
####### |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
######## | ||
# S# | ||
# # | ||
# # | ||
#F # | ||
######## |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
######## | ||
# S# | ||
# ###### | ||
# F# | ||
######## |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
######## | ||
# S# | ||
# ###### | ||
# # | ||
###### # | ||
#F # | ||
######## |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
########## | ||
#S # | ||
######## # | ||
# # | ||
# ######## | ||
# F# | ||
########## |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
########## | ||
#S# # # | ||
# # # # # | ||
# # # # # | ||
# # # # # | ||
# # F# | ||
########## |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
################## | ||
############ # | ||
# # # # | ||
# # # | ||
# # #### # # # # | ||
# # # S# # # # # | ||
# # # ## # # # # | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
########## | ||
#F #F# | ||
###### # # | ||
# S # # # | ||
# # # # | ||
#### # # # | ||
# # | ||
######## # | ||
#F # | ||
########## |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
##################### | ||
#S# # # # | ||
# # # # # ### ### # # | ||
# # # # # # # | ||
# ##### ### ####### # | ||
# # # # # | ||
##### ##### # # ##### | ||
# # # # # # # # | ||
# # # # # ### # # # # | ||
# # # # # # # # # | ||
# # ####### # # ### # | ||
# # # # # # # | ||
# # # ### # # ####### | ||
# # # # # # # | ||
# ##### # # # ##### # | ||
# # # # # # # # | ||
# # ##### # ### # # # | ||
# # # # # | ||
### # ############# # | ||
# # F# | ||
##################### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from .maze import Maze | ||
from .maze import Position | ||
from .maze_creator import MazeGenerator | ||
|
||
__all__ = [Maze, Position] | ||
__all__ = [Maze, Position, MazeGenerator] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import random | ||
|
||
|
||
class MazeGenerator: | ||
# Movimentos possíveis | ||
MOVES = [(0, 2), (2, 0), (0, -2), (-2, 0)] | ||
|
||
@staticmethod | ||
def generate_maze_structure(width: int = 21, height: int = 21): | ||
# Inicializa o labirinto com paredes | ||
maze = [["#" for _ in range(width)] for _ in range(height)] | ||
|
||
# Função recursiva para criar o labirinto | ||
def carve_passages_from(x, y): | ||
directions = MazeGenerator.MOVES[:] | ||
random.shuffle(directions) | ||
for dx, dy in directions: | ||
nx, ny = x + dx, y + dy | ||
if 0 <= nx < width and 0 <= ny < height and maze[ny][nx] == "#": | ||
if 1 <= nx < width - 1 and 1 <= ny < height - 1: | ||
maze[ny][nx] = " " | ||
maze[ny - dy // 2][nx - dx // 2] = " " | ||
carve_passages_from(nx, ny) | ||
|
||
# Define o ponto de partida | ||
start_x, start_y = (1, 1) | ||
maze[start_y][start_x] = "S" | ||
carve_passages_from(start_x, start_y) | ||
|
||
# TODO add multi exits | ||
# exits = [(width - 2, height - 2)] | ||
maze[height - 2][width - 2] = "F" | ||
|
||
return maze | ||
|
||
@staticmethod | ||
def save_maze_to_file(maze, filename): | ||
with open(filename, "w", newline="") as file: | ||
file.writelines([f"{''.join(line)}\n" for line in maze]) |