-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode.py
More file actions
96 lines (80 loc) · 7.36 KB
/
Copy pathCode.py
File metadata and controls
96 lines (80 loc) · 7.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ░░░░░░░░ ░ ░░░░
▒▒▒▒▒▒ ▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒ ▒▒▒▒▒▒ ▒▒▒▒▒ ▒
▒▒▒▒▒ ▒▒ ▒▒▒▒▒ ▒ ▒▒▒▒ ▒▒▒▒▒▒▒▒▒▒▒ ▒▒▒ ▒▒▒▒ ▒▒▒▒▒ ▒▒ ▒▒▒▒▒▒▒▒ ▒▒ ▒ ▒ ▒▒▒▒▒ ▒▒▒▒▒ ▒ ▒ ▒ ▒▒▒▒ ▒▒▒▒▒ ▒ ▒▒▒▒▒▒▒ ▒ ▒ ▒▒▒▒▒▒▒▒▒ ▒▒▒▒▒ ▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒ ▒▒▒▒▒ ▒▒▒▒▒▒
▓▓▓▓ ▓▓▓ ▓▓▓▓▓ ▓▓▓▓▓ ▓▓▓ ▓▓▓▓▓▓▓▓▓ ▓ ▓▓▓ ▓▓ ▓▓ ▓▓ ▓▓▓▓▓▓▓ ▓▓▓▓▓▓ ▓▓ ▓▓ ▓▓ ▓▓ ▓▓▓ ▓▓▓▓▓▓ ▓▓▓▓ ▓▓▓ ▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓ ▓▓▓▓▓ ▓▓ ▓▓▓ ▓▓ ▓▓▓▓▓▓▓▓▓▓ ▓▓▓ ▓▓▓▓ ▓▓▓▓▓ ▓
▓▓▓ ▓ ▓▓▓▓ ▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓ ▓▓▓▓ ▓ ▓▓ ▓▓▓▓▓▓▓▓▓ ▓▓▓ ▓▓ ▓▓ ▓ ▓▓▓ ▓▓▓ ▓▓▓▓▓▓ ▓▓▓ ▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓ ▓▓ ▓▓ ▓▓▓ ▓▓▓ ▓▓ ▓▓▓▓▓▓▓▓▓ ▓ ▓▓▓ ▓▓ ▓▓▓▓
▓▓ ▓▓▓▓▓▓▓ ▓▓▓ ▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓ ▓▓ ▓▓ ▓▓ ▓▓▓▓▓▓▓▓▓▓▓ ▓▓ ▓▓ ▓▓ ▓ ▓▓▓ ▓▓▓ ▓▓▓▓▓▓ ▓ ▓ ▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓ ▓ ▓ ▓▓▓ ▓ ▓▓▓ ▓▓▓ ▓▓ ▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓ ▓▓ ▓▓▓▓▓▓▓▓▓
█ █████████ █ ██████ █████████████ ███████ ███████ ███████ ██ ██ ██ ███ █ █ ███████ ████ ████ █████████████ ██ ███ ███ █ █ ██ ███████ █████████ █ ██ ████
████████████████████████████████████████████ █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
By Wanets.
import random
PLAYER_EMOJI = "😶"
END_EMOJI = "🧫"
WALL = "🟨"
PATH = "💠"
rend = -1
def generate_maze(width, height):
maze = [[WALL if random.random() < 0.3 else PATH for _ in range(width)] for _ in range(height)]
maze[0][0] = PATH # Start point
maze[rend][rend] = END_EMOJI # End point
return maze
def print_maze(maze, player_pos):
for y, row in enumerate(maze):
for x, tile in enumerate(row):
if (x, y) == player_pos:
print(PLAYER_EMOJI, end="")
else:
print(tile, end="")
print()
def move_player(player_pos, direction, maze):
x, y = player_pos
if direction == "W" and y > 0 and maze[y-1][x] != WALL:
y -= 1
elif direction == "S" and y < len(maze) - 1 and maze[y+1][x] != WALL:
y += 1
elif direction == "A" and x > 0 and maze[y][x-1] != WALL:
x -= 1
elif direction == "D" and x < len(maze[0]) - 1 and maze[y][x+1] != WALL:
x += 1
return x, y
def is_solvable(maze, start, end):
width, height = len(maze[0]), len(maze)
stack = [start]
visited = set()
visited.add(start)
while stack:
x, y = stack.pop()
if (x, y) == end:
return True
for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
nx, ny = x + dx, y + dy
if 0 <= nx < width and 0 <= ny < height and (nx, ny) not in visited and maze[ny][nx] != WALL:
stack.append((nx, ny))
visited.add((nx, ny))
return False
def game_loop():
global rend
width, height = 10, 10
player_pos = (0, 0)
end_pos = (rend, rend)
while True:
maze = generate_maze(width, height)
while not is_solvable(maze, (0, 0), (width - 1, height - 1)):
maze = generate_maze(width, height)
print_maze(maze, player_pos)
while player_pos != (width - 1, height - 1):
move = input("Move (WASD): ").upper()
player_pos = move_player(player_pos, move, maze)
print_maze(maze, player_pos)
print("Congratulations! You aren't an AI(ur dummer than that), but to be fully sure complete 𝘵𝘩𝘪𝘴 maze")
width += 2
height += 2
if rend == -1:
rend = 0
else:
rend = -1
# Adjust player position relative to the new maze size
player_pos = (min(player_pos[0], width - 1), min(player_pos[1], height - 1))
if __name__ == "__main__":
game_loop()