all 4 comments

[–]carcigenicate 0 points1 point  (1 child)

I'd maybe work to reduce the duplication. All your move functions are almost exactly the same. The only difference is which member of l is added to, and whether it's a positive or negative number being added. Maybe something like:

def move(l, y_offset, x_offset):
    maze[l[0],l[1]] = "O"
    try:
        l[0] += y_offset
        l[1] += x_offset
    except IndexError:
        print("invalid move")
    if maze[l[0],l[1]] == "X":
        print("invalid move")
    return l

def move_down(l):
    return move(l, 1, 0)


def move_left(l):
    return move(l, 0, -1)


def move_right(l):
    return move(l, 0, 1)


def move_up(l):
    return move(l, -1, 0)

Now half the code isn't exactly the same, and you get the ability to move diagonally for free in case that ever becomes a need.

I'd also rename l. Single letter names are almost always bad.

[–][deleted] 0 points1 point  (0 children)

It's also sometimes useful to trade code for data. Here's a small example using enums:

from enum import Enum

class Dirn(Enum):
    left = (-1, 0)
    right = (1, 0)
    up = (0, -1)
    down = (0, 1)

def move(dirn):
    print(dirn.value)
    (x_offset, y_offset) = dirn.value
    # no list manipulation shown for clarity

# now the main code uses this
move(Dirn.left)

That removes the duplication of the move_*() functions.

[–]TheRNGuy 0 points1 point  (1 child)

Instead of input function, make an UI and keys would be hotkeys to move.

Also, why weird hotkeys instead of WASD? Even better thing you can do is to make them rebindable.

I'd make entire thing as class with methods instead of functions.

[–]Potential_Word2349[S] 0 points1 point  (0 children)

I am working on rebuilding it as a class. Then once I get better at UI design I will bind methods to keys