27
u/DGM06 Feb 09 '20
I assume the green square in the upper left is the start or finish, but where is the other endpoint?
26
u/TheJizzWiz Feb 09 '20 edited Feb 09 '20
I havent figured out a way to implement it yet
edit: i implemented a crude way now, put it on github under maze 2
29
u/gandleforf Feb 09 '20
That's pretty neat! Did you know Git has some cool features for versioning built in; you can learn more here!
15
Feb 09 '20
[removed] — view removed comment
22
u/Panda_Mon Feb 09 '20
People who are downvoting you do not understand the concept of Reddit. Your post should be upvoted so someone will respond and teach you the answer, and then we all learn together. ❤
The point of git is that it remembers your drafts for you, amd saves each one as you submit to your project. That way you can make drastic changes that break things, and then literally go backwards in time to try again. Its called a non-destructive workflow!
0
Feb 10 '20
[deleted]
1
u/DisturbedTK Feb 10 '20
That's what branches are for. Just make a WIP branch and make your edits there.
0
Feb 09 '20
[deleted]
1
u/crankymotor Feb 10 '20
OK REDDIT WE GET IT, but not everyone knows the full functionality and utility of git, some of us just use it as a convenient online storage/sharing platform (I have done that for the longest time until I started using git (bash) to manage my repos instead of github)
u/panda_mon is right, why are y'all so critical of OP's work? He just started programming 1.5 months ago for gods sake.
1
1
u/oblivion-age Feb 09 '20
Will you at a later point create AI code to learn and solve them randomly?
4
u/ullawanka Feb 09 '20
I'm seeing green squares all over the place, but pretty sure that is an illusion.
4
u/the_blue_bottle Feb 09 '20
You can tell they are illusions because they disappear when you turn your gaze at them. That's because your fovea have a lot more receptors than the other parts of the eye
9
Feb 09 '20
very cool! If you're looking for a fun challenge to do next, can you make a little shape that navigates the maze to show the solution? This is great. Also you might like the book Mazes for Programmers.
5
u/TheJizzWiz Feb 09 '20
Thanks :) I'll try to figure out how to make this possible, it's a great idea
6
u/wiredupwrong Feb 09 '20
One of the creators of D3.js has a pretty cool website on visualizing algorithms that could spawn some ideas. https://bost.ocks.org/mike/algorithms/
241
80
8
u/Broshenniy Feb 09 '20
Where is the exit?
14
Feb 09 '20
There is no escape
3
u/Broshenniy Feb 09 '20
nooooöoooooooo
4
u/Risley Feb 09 '20
Lmfao that little man in the middle of the nooo screaming like he’s been stuck in the Jaunt for million of years....
3
36
u/Miner_ChAI Feb 09 '20
This QR has this link
8
u/ShootEly Feb 09 '20
I’m still in bed and trying not to laugh too hard as my walls are paper thin and I’d rather not wake up my roommates.
Thanks for the laugh first thing in the morning!8
3
u/ent3r_ Noob Feb 09 '20
Godammit. I knew what it was, but I still clicked. Have your goddamn updoot
3
6
Feb 09 '20
[removed] — view removed comment
8
u/Etheo Feb 09 '20
Not without the anchors.
2
u/wviana Feb 09 '20
Should be a mode that adds anchor to it.
4
u/Etheo Feb 09 '20
What for? The QR code if randomly generated will just be jibberish.
3
u/wviana Feb 09 '20
We could use for default exchange mode . Would work nice if we add a little metadata first to tell what is this data about. Maybe the first line. With an offset for completing the number if columns.
2
u/wviana Feb 09 '20
How fast a QR code could be decoded? Not counting the time for image recognition.
As it is "raw" data, wouldn't it be a really fast way to exchange data? Limited just about how good cameras and screens are.
2
u/wviana Feb 09 '20
Maybe QR code is a underused technology. Or just so ahead of it's time. ( Camera and screens quality )
3
u/ElllGeeEmm Feb 09 '20
A lot of apps can scan qr codes to exchange information. LinkedIn and Venmo both have it.
2
1
1
Feb 10 '20 edited Feb 10 '20
EDIT: formating is hard, lol
This is so cool! I forked your github repo to start playing with it myself because it looks like a lot of fun.
Here's what I've done so far:
Only import what's needed rather than using wildcards to keep things smaller and faster
Move everything into a main function
Add docstrings
Make global variable all CAPS and Renamed ms to MAZE_SIZE, I'm assuming that's what it meant.
Start linting with pylint
Auto linting with black
!/usr/bin/env python
"""Random Maze Generator"""
from tkinter import Tk, Canvas
from random import randint
CELL_SIZE = 9 # pixels
MAZE_SIZE = 100 # rows and columns
map = [["w" for _ in range(MAZE_SIZE)] for _ in range(MAZE_SIZE)]
def create(ffs):
"""Check rows and columns and draw stuff"""
for row in range(MAZE_SIZE):
for col in range(MAZE_SIZE):
if map[row][col] == "P":
color = "White"
elif map[row][col] == "w":
color = "black"
draw(ffs, row, col, color)
def draw(ffs, row, col, color):
"""Draw rectangles"""
x1 = col * CELL_SIZE
y1 = row * CELL_SIZE
x2 = x1 + CELL_SIZE
y2 = y1 + CELL_SIZE
ffs.create_rectangle(x1, y1, x2, y2, fill=color)
def check_neighbours(ccr, ccc):
"""This function checks neighbours"""
walls = []
neighbours = [
[
ccr,
ccc - 1,
ccr - 1,
ccc - 2,
ccr,
ccc - 2,
ccr + 1,
ccc - 2,
ccr - 1,
ccc - 1,
ccr + 1,
ccc - 1,
], # left
[
ccr,
ccc + 1,
ccr - 1,
ccc + 2,
ccr,
ccc + 2,
ccr + 1,
ccc + 2,
ccr - 1,
ccc + 1,
ccr + 1,
ccc + 1,
], # right
[
ccr - 1,
ccc,
ccr - 2,
ccc - 1,
ccr - 2,
ccc,
ccr - 2,
ccc + 1,
ccr - 1,
ccc - 1,
ccr - 1,
ccc + 1,
], # top
[
ccr + 1,
ccc,
ccr + 2,
ccc - 1,
ccr + 2,
ccc,
ccr + 2,
ccc + 1,
ccr + 1,
ccc - 1,
ccr + 1,
ccc + 1,
], # bottom
]
visitable_neighbours = []
for i in neighbours: # find neighbours to visit
if i[0] > 0 and i[0] < (MAZE_SIZE - 1) and i[1] > 0 and i[1] < (MAZE_SIZE - 1):
if (
map[i[2]][i[3]] == "P"
or map[i[4]][i[5]] == "P"
or map[i[6]][i[7]] == "P"
or map[i[8]][i[9]] == "P"
or map[i[10]][i[11]] == "P"
):
walls.append(i[0:2])
else:
visitable_neighbours.append(i[0:2])
return visitable_neighbours
def main():
"""Main"""
scr = randint(1, MAZE_SIZE)
scc = randint(1, MAZE_SIZE)
start_color = "Green"
ccr, ccc = scr, scc
map[ccr][ccc] = "P"
finished = False
visited_cells = []
revisited_cells = []
while not finished:
visitable_neighbours = check_neighbours(ccr, ccc)
if len(visitable_neighbours) != 0:
d = randint(1, len(visitable_neighbours)) - 1
ncr, ncc = visitable_neighbours[d]
map[ncr][ncc] = "P"
visited_cells.append([ncr, ncc])
ccr, ccc = ncr, ncc
if len(visitable_neighbours) == 0:
try:
ccr, ccc = visited_cells.pop()
revisited_cells.append([ccr, ccc])
except:
finished = True
window = Tk()
window.title("Maze")
canvas_side = MAZE_SIZE * CELL_SIZE
ffs = Canvas(window, width=canvas_side, height=canvas_side, bg="grey")
ffs.pack()
create(ffs)
draw(ffs, scr, scc, start_color)
e = randint(1, len(revisited_cells)) - 1
ecr = revisited_cells[e][0]
ecc = revisited_cells[e][1]
end_color = "red"
draw(ffs, ecr, ecc, end_color)
print(revisited_cells)
window.mainloop()
if __name__ == "__main__":
main()3
u/TheJizzWiz Feb 10 '20
Thanks! Glad you liked it! I've looked at the changes you made and have a few questions. 1) What does the if __name__ == "__main__": statement do? 2) What are docstrings? ( I hope these questions arent too stupid, im just curious)
2
Feb 10 '20
Those questions aren't stupid, at all. I've been learning python for about 5 years and still have so many questions. I can't explain the __name__=="__main__" thing any better than it has already been explained by others, here's a link to a good explanation I found on stack overflow: https://stackoverflow.com/questions/419163/what-does-if-name-main-do
As for docstrings, they make your code easier figure out for others and for yourself when you come back to it later. For example with the maze.py module, you can acces it like this and see the messages left in the docstrings:
>>> import maze >>> help(maze) Help on module maze: NAME maze - Random Maze Generator FUNCTIONS check_neighbours(ccr, ccc) This function checks neighbours create(ffs) Check rows and columns and draw stuff draw(ffs, row, col, color) Draw rectangles main() Main DATA CELL_SIZE = 9 MAZE_SIZE = 100 map = [['w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w... FILE /home/user/python/Random-Maze-Generator/maze.py2
u/TheJizzWiz Feb 10 '20
OK, thanks for the explanation! Always nice to have some help from more experienced people
2
u/Pattycakes_wcp Feb 10 '20
I mean, you could just open a pr and link the pr?
1
Feb 10 '20
Good point. Here it is. https://github.com/ChickenSlayer3000/Random-Maze-Generator/pull/1
3
u/prithvidiamond1 Feb 09 '20
Is this a unique maze, i.e, does, it have only one solution?
2
Feb 10 '20
I think so, because by just eyeing it, it appears to be just one long correct route with short branching paths that break off of it.
1
3
2
2
u/numberduck Feb 09 '20
I took a screenshot. Going to make my dnd group run through it. They're going to hate me.
Thank you for sharing.
2
2
1
1
u/Shmifful Feb 09 '20
What module did you use?
1
u/wviana Feb 09 '20
Would be nice to create a maze module. Would be very useful for game developers.
1
1
1
u/h3xag0nSun Feb 09 '20
Ideas inspired by this post: Maze generator that maps over a scannable QR code.
Maze solution finder.
I’m not sure how either of those would be done but they might be cool projects.
1
1
1
1
1
1
1
u/Sixty9lies Feb 09 '20
I just started learning Python as well. The fact that you did this in a month gives me hope and horror...as I'm not sure i'll catch on to it that fast. Super cool, though. Great work.
1
1
1
1
Feb 10 '20
Goodness, what kind of brain you got? 1 month into programming. I can't even do this and I'm years in experience.
1
1
1
u/Nateobee Feb 10 '20
My TRS-80 had one of those. Printed on my dot matrix. Solved them by highlighting dead ends.
1
Feb 10 '20
This looks like a QR Barcode LMAO. I would do the maze but I think I may go crosseyed lol.
1
u/alb1 Feb 10 '20
You might find it interesting to look at Eller's algorithm for efficiently generating perfect mazes (i.e., mazes having exactly one path between any two cells in the maze).
1
1
u/ItsMeCall911 Feb 09 '20
u/TheJizzWiz : I made a random maze generator
Me : Opening my phone to scan the QR code ¯_(ツ)_/¯
0
u/1VentiChloroform Feb 09 '20
I'm sorry to facefuck your dreams to deep, salty tears
but this is a crossword puzzle
0
106
u/TheJizzWiz Feb 09 '20
Heres the link to the code: https://github.com/ChickenSlayer3000/Random-Maze-Generator
Note: Ive only been learning python for about a month and a half now, so any recomendations on how to improve my code would be appreciated