OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

I need a simple solution to check id an index is outside my 2d list

  • Thread starter Thread starter Wyatt M
  • Start date Start date
W

Wyatt M

Guest
I have recently challenged myself to make a maze generator using depth first search (with which I have zero experience) and I have a function which will be called a bunch for checking if the neighbors of a point in a 2d list are vallid and unvisited. I have my own system for notation of connections in a 2d network so just know that 0s unvisited locations.

Code:
def checkNeighbors(map,x,y):
    left = (-1,0)
    right = (1,0)
    up = (0,1)
    down = (0,-1)

    clearDirs = []

    if (map[y][x-1] == 0) and (map[y][x-1] != None):
        clearDirs.append(left)
    if (map[y][x+1] == 0) and (map[y][x+1] != None):
        clearDirs.append(right)
    if (map[y+1][x] == 0) and (map[y+1][x] != None):
        clearDirs.append(up)
    if (map[y-1][x] == 0) and (map[y-1][x] != None):
        clearDirs.append(down)

    return clearDirs

I tried playing around with the parameters but couldn't think of any property which and I used a print function on clearDirs to give me an idea as to whats happening.

I would also like to ask that you don't tell me solutions to any other parts of the depth first search as I need to try before I improve, thanks!
<p>I have recently challenged myself to make a maze generator using depth first search (with which I have zero experience) and I have a function which will be called a bunch for checking if the neighbors of a point in a 2d list are vallid and unvisited. I have my own system for notation of connections in a 2d network so just know that 0s unvisited locations.</p>
<pre><code>def checkNeighbors(map,x,y):
left = (-1,0)
right = (1,0)
up = (0,1)
down = (0,-1)

clearDirs = []

if (map[y][x-1] == 0) and (map[y][x-1] != None):
clearDirs.append(left)
if (map[y][x+1] == 0) and (map[y][x+1] != None):
clearDirs.append(right)
if (map[y+1][x] == 0) and (map[y+1][x] != None):
clearDirs.append(up)
if (map[y-1][x] == 0) and (map[y-1][x] != None):
clearDirs.append(down)

return clearDirs
</code></pre>
<p>I tried playing around with the parameters but couldn't think of any property which and I used a <code>print</code> function on clearDirs to give me an idea as to whats happening.</p>
<p>I would also like to ask that you don't tell me solutions to any other parts of the depth first search as I need to try before I improve, thanks!</p>
 

Online statistics

Members online
0
Guests online
4
Total visitors
4
Top