2

I was just trying an maze-mouse game, to retain the position of the mouse in array,

I created a multidimensional array in python

maze = [[0 for x in range(8)] for x in range(8)]

and I called a function using

l = move_mouse(m,maze)

function is

def move_mouse(m,maze =[i][j]):
    if m=='down':
       i = i+1
       return maze

How to pass the array with with values i and j in maze so that to retain the current position and return the same to main function?

Please tell if I'm wrong in assigning it.

2
  • What are you actually storing in maze? Is it only to record the position of the mouse in the maze, or are there other items (e.g. blocks of cheese, cats, mouse traps, etc)? Commented Mar 22, 2015 at 10:37
  • Its only to record position of the mouse. Commented Mar 22, 2015 at 12:33

1 Answer 1

5

The maze and the position are two different objects, you cannot mix them in a way you tried. Keep them separate:

def move_mouse(m, maze, pos):
    if m == 'down':
        # check the maze
        pos = pos[0], pos[1] + 1
    return pos

maze = [[0 for x in range(8)] for x in range(8)]
pos = (4,4)

pos = move_mouse('down', maze, pos)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.